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}) +}