parent
d037f57560
commit
f9ae020243
12
bot.go
12
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})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue