From b73e378de719123d51c80eacdde3ff404d2ae0d3 Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Mon, 21 Nov 2022 23:50:39 +0800 Subject: [PATCH] feat: minor changes to text responces --- bot.go | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/bot.go b/bot.go index 89aba70..b9f424a 100644 --- a/bot.go +++ b/bot.go @@ -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}) }