feat: minor changes to text responces
This commit is contained in:
		
							parent
							
								
									f9ae020243
								
							
						
					
					
						commit
						b73e378de7
					
				
							
								
								
									
										32
									
								
								bot.go
								
								
								
								
							
							
						
						
									
										32
									
								
								bot.go
								
								
								
								
							| 
						 | 
					@ -73,38 +73,25 @@ func handleTrafficCmd(c tele.Context) error {
 | 
				
			||||||
	if len(dailyTraffic) > 1 {
 | 
						if len(dailyTraffic) > 1 {
 | 
				
			||||||
		row := dailyTraffic[len(dailyTraffic)-2]
 | 
							row := dailyTraffic[len(dailyTraffic)-2]
 | 
				
			||||||
		day := fmt.Sprintf("%d-%02d-%02d", row.Date.Year, row.Date.Month, row.Date.Day)
 | 
							day := fmt.Sprintf("%d-%02d-%02d", row.Date.Year, row.Date.Month, row.Date.Day)
 | 
				
			||||||
		responseParts = append(
 | 
							responseParts = append(responseParts, fmt.Sprintf("Yesterday (%s):` %s`", day, fmtTraffic(row)))
 | 
				
			||||||
			responseParts,
 | 
					 | 
				
			||||||
			fmt.Sprintf("Yesterday (%s):` %s`", day, fmtTraffic(row)),
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Today's traffic if present
 | 
						// Today's traffic if present
 | 
				
			||||||
	if len(dailyTraffic) > 0 {
 | 
						if len(dailyTraffic) > 0 {
 | 
				
			||||||
		row := dailyTraffic[len(dailyTraffic)-1]
 | 
							row := dailyTraffic[len(dailyTraffic)-1]
 | 
				
			||||||
		responseParts = append(
 | 
							responseParts = append(responseParts, fmt.Sprintf("Today so far:` %s`\n", fmtTraffic(row)))
 | 
				
			||||||
			responseParts,
 | 
					 | 
				
			||||||
			fmt.Sprintf("Today so far:` %s`\n", fmtTraffic(row)),
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Last month's traffic, if present
 | 
						// Last month's traffic, if present
 | 
				
			||||||
	if len(monthlyTraffic) > 1 {
 | 
						if len(monthlyTraffic) > 1 {
 | 
				
			||||||
		row := monthlyTraffic[len(monthlyTraffic)-2]
 | 
							row := monthlyTraffic[len(monthlyTraffic)-2]
 | 
				
			||||||
		month := fmt.Sprintf("%d-%02d", row.Date.Year, row.Date.Month)
 | 
							month := fmt.Sprintf("%d-%02d", row.Date.Year, row.Date.Month)
 | 
				
			||||||
		responseParts = append(
 | 
							responseParts = append(responseParts, fmt.Sprintf("Last month (%s):` %s`", month, fmtTraffic(row)))
 | 
				
			||||||
			responseParts,
 | 
					 | 
				
			||||||
			fmt.Sprintf("Last month (%s):` %s`", month, fmtTraffic(row)),
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// This month's traffic, if present
 | 
						// This month's traffic, if present
 | 
				
			||||||
	if len(monthlyTraffic) > 0 {
 | 
						if len(monthlyTraffic) > 0 {
 | 
				
			||||||
		row := monthlyTraffic[len(monthlyTraffic)-1]
 | 
							row := monthlyTraffic[len(monthlyTraffic)-1]
 | 
				
			||||||
		responseParts = append(
 | 
							responseParts = append(responseParts, fmt.Sprintf("This month so far:` %s`", fmtTraffic(row)))
 | 
				
			||||||
			responseParts,
 | 
							responseParts = append(responseParts, drawBarForTrafficRecord(row))
 | 
				
			||||||
			fmt.Sprintf("This month so far:` %s`", fmtTraffic(row)),
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
		bar := fmt.Sprintf("\n```\n%s\n```", drawBarForTrafficRecord(row))
 | 
					 | 
				
			||||||
		responseParts = append(responseParts, bar)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var respText string
 | 
						var respText string
 | 
				
			||||||
| 
						 | 
					@ -196,7 +183,7 @@ func drawBarForTrafficRecord(r stats.VnstatTrafficRecord) string {
 | 
				
			||||||
	effective := lo.Max([]uint64{r.Rx, r.Tx})
 | 
						effective := lo.Max([]uint64{r.Rx, r.Tx})
 | 
				
			||||||
	max := config.MonthlyTrafficLimitGiB
 | 
						max := config.MonthlyTrafficLimitGiB
 | 
				
			||||||
	ratio := float64(effective) / 1024 / 1024 / 1024 / float64(max)
 | 
						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 {
 | 
					func handleYearProgressCmd(c tele.Context) error {
 | 
				
			||||||
| 
						 | 
					@ -206,6 +193,9 @@ func handleYearProgressCmd(c tele.Context) error {
 | 
				
			||||||
	elapsed := time.Since(yearStart)
 | 
						elapsed := time.Since(yearStart)
 | 
				
			||||||
	ratio := float64(elapsed) / float64(yearDur)
 | 
						ratio := float64(elapsed) / float64(yearDur)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bar := fmt.Sprintf("```\n%s %2.0f%%\n```", drawBar(ratio, 16), ratio*100)
 | 
						replyText := []string{
 | 
				
			||||||
	return c.Reply(bar, &tele.SendOptions{ParseMode: tele.ModeMarkdown})
 | 
							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})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue