feat: minor changes to text responces

This commit is contained in:
Yiyang Kang 2022-11-21 23:50:39 +08:00
parent f9ae020243
commit b73e378de7
Signed by: kkyy
GPG Key ID: 80FD317ECAF06CC3
1 changed files with 11 additions and 21 deletions

32
bot.go
View File

@ -73,38 +73,25 @@ func handleTrafficCmd(c tele.Context) error {
if len(dailyTraffic) > 1 {
row := dailyTraffic[len(dailyTraffic)-2]
day := fmt.Sprintf("%d-%02d-%02d", row.Date.Year, row.Date.Month, row.Date.Day)
responseParts = append(
responseParts,
fmt.Sprintf("Yesterday (%s):` %s`", day, fmtTraffic(row)),
)
responseParts = append(responseParts, fmt.Sprintf("Yesterday (%s):` %s`", day, fmtTraffic(row)))
}
// Today's traffic if present
if len(dailyTraffic) > 0 {
row := dailyTraffic[len(dailyTraffic)-1]
responseParts = append(
responseParts,
fmt.Sprintf("Today so far:` %s`\n", fmtTraffic(row)),
)
responseParts = append(responseParts, fmt.Sprintf("Today so far:` %s`\n", fmtTraffic(row)))
}
// Last month's traffic, if present
if len(monthlyTraffic) > 1 {
row := monthlyTraffic[len(monthlyTraffic)-2]
month := fmt.Sprintf("%d-%02d", row.Date.Year, row.Date.Month)
responseParts = append(
responseParts,
fmt.Sprintf("Last month (%s):` %s`", month, fmtTraffic(row)),
)
responseParts = append(responseParts, fmt.Sprintf("Last month (%s):` %s`", month, fmtTraffic(row)))
}
// This month's traffic, if present
if len(monthlyTraffic) > 0 {
row := monthlyTraffic[len(monthlyTraffic)-1]
responseParts = append(
responseParts,
fmt.Sprintf("This month so far:` %s`", fmtTraffic(row)),
)
bar := fmt.Sprintf("\n```\n%s\n```", drawBarForTrafficRecord(row))
responseParts = append(responseParts, bar)
responseParts = append(responseParts, fmt.Sprintf("This month so far:` %s`", fmtTraffic(row)))
responseParts = append(responseParts, drawBarForTrafficRecord(row))
}
var respText string
@ -196,7 +183,7 @@ func drawBarForTrafficRecord(r stats.VnstatTrafficRecord) string {
effective := lo.Max([]uint64{r.Rx, r.Tx})
max := config.MonthlyTrafficLimitGiB
ratio := float64(effective) / 1024 / 1024 / 1024 / float64(max)
return fmt.Sprintf("%s %2.0f%%", drawBar(ratio, 16), ratio*100)
return fmt.Sprintf("%s `%2.0f%%`", drawBar(ratio, 16), ratio*100)
}
func handleYearProgressCmd(c tele.Context) error {
@ -206,6 +193,9 @@ func handleYearProgressCmd(c tele.Context) error {
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})
replyText := []string{
fmt.Sprintf("`%d is %2.0f%% complete.`", time.Now().Year(), ratio*100),
drawBar(ratio, 20),
}
return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown})
}