From f9ae020243d9babaf4de993141ab2df097cbc999 Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Mon, 21 Nov 2022 15:42:43 +0800 Subject: [PATCH] feat: add /year_progress command yeah i'm bored --- bot.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bot.go b/bot.go index 1ca3862..89aba70 100644 --- a/bot.go +++ b/bot.go @@ -39,6 +39,7 @@ func initBot() (*tele.Bot, error) { b.Handle("/me", handleUserInfoCmd) b.Handle("/chat", handleChatInfoCmd) + b.Handle("/year_progress", handleYearProgressCmd) return b, nil } @@ -197,3 +198,14 @@ func drawBarForTrafficRecord(r stats.VnstatTrafficRecord) string { ratio := float64(effective) / 1024 / 1024 / 1024 / float64(max) return fmt.Sprintf("%s %2.0f%%", drawBar(ratio, 16), ratio*100) } + +func handleYearProgressCmd(c tele.Context) error { + yearStart := time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local) + yearEnd := yearStart.AddDate(1, 0, 0) + yearDur := yearEnd.Sub(yearStart) + elapsed := time.Since(yearStart) + ratio := float64(elapsed) / float64(yearDur) + + bar := fmt.Sprintf("```\n%s %2.0f%%\n```", drawBar(ratio, 16), ratio*100) + return c.Reply(bar, &tele.SendOptions{ParseMode: tele.ModeMarkdown}) +}