change: reply quietly

This commit is contained in:
Yiyang Kang 2022-11-26 21:03:48 +08:00
parent 0c70dc976a
commit ce171109c8
1 changed files with 15 additions and 11 deletions

26
bot.go
View File

@ -95,12 +95,12 @@ func handleStartCmd(c tele.Context) error {
func handleTrafficCmd(c tele.Context) error { func handleTrafficCmd(c tele.Context) error {
dailyTraffic, err := stats.VnstatDailyTraffic(config.WatchedInterface) dailyTraffic, err := stats.VnstatDailyTraffic(config.WatchedInterface)
if err != nil { if err != nil {
_ = c.Reply(stickerFromID(stickerPanic)) _ = c.Reply(stickerFromID(stickerPanic), tele.Silent)
return err return err
} }
monthlyTraffic, err := stats.VnstatMonthlyTraffic(config.WatchedInterface) monthlyTraffic, err := stats.VnstatMonthlyTraffic(config.WatchedInterface)
if err != nil { if err != nil {
_ = c.Reply(stickerFromID(stickerPanic)) _ = c.Reply(stickerFromID(stickerPanic), tele.Silent)
return err return err
} }
@ -137,7 +137,7 @@ func handleTrafficCmd(c tele.Context) error {
respText = strings.Join(responseParts, "\n") respText = strings.Join(responseParts, "\n")
} }
return c.Reply(respText, &tele.SendOptions{ParseMode: tele.ModeMarkdown}) return c.Reply(respText, &tele.SendOptions{ParseMode: tele.ModeMarkdown}, tele.Silent)
} }
func fmtTraffic(r stats.VnstatTrafficRecord) string { func fmtTraffic(r stats.VnstatTrafficRecord) string {
@ -148,7 +148,7 @@ func fmtTraffic(r stats.VnstatTrafficRecord) string {
func handleUserInfoCmd(c tele.Context) error { func handleUserInfoCmd(c tele.Context) error {
u := c.Sender() u := c.Sender()
if u == nil { if u == nil {
return c.Reply("Unknown.") return c.Reply("Unknown.", tele.Silent)
} }
replyText := []string{ replyText := []string{
@ -163,13 +163,13 @@ func handleUserInfoCmd(c tele.Context) error {
fmt.Sprintf(`IsPremium: %t`, u.IsPremium), fmt.Sprintf(`IsPremium: %t`, u.IsPremium),
"```", "```",
} }
return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown}) return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown}, tele.Silent)
} }
func handleChatInfoCmd(c tele.Context) error { func handleChatInfoCmd(c tele.Context) error {
chat := c.Chat() chat := c.Chat()
if chat == nil { if chat == nil {
return c.Reply("Unknown.") return c.Reply("Unknown.", tele.Silent)
} }
loc := "" loc := ""
if chat.ChatLocation != nil { if chat.ChatLocation != nil {
@ -195,7 +195,7 @@ func handleChatInfoCmd(c tele.Context) error {
fmt.Sprintf(`NoVoiceAndVideo: %t`, chat.NoVoiceAndVideo), fmt.Sprintf(`NoVoiceAndVideo: %t`, chat.NoVoiceAndVideo),
"```", "```",
} }
return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown}) return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown}, tele.Silent)
} }
func drawBar(progress float64, length int) string { func drawBar(progress float64, length int) string {
@ -234,7 +234,7 @@ func handleYearProgressCmd(c tele.Context) error {
"\n%d is <b>%2.0f%%</b> complete.\n<pre>%s</pre>", "\n%d is <b>%2.0f%%</b> complete.\n<pre>%s</pre>",
time.Now().Year(), ratio*100, drawBar(ratio, 25), time.Now().Year(), ratio*100, drawBar(ratio, 25),
) )
return c.Reply(replyText, &tele.SendOptions{ParseMode: tele.ModeHTML}) return c.Reply(replyText, &tele.SendOptions{ParseMode: tele.ModeHTML}, tele.Silent)
} }
func handleGeneralMessage(_ tele.Context) error { func handleGeneralMessage(_ tele.Context) error {
@ -258,12 +258,16 @@ func handleDigCmd(c tele.Context) error {
req, err := cmds.NewDigRequest(msg.Payload) req, err := cmds.NewDigRequest(msg.Payload)
if err != nil { if err != nil {
return c.Reply("Invalid arguments.\nUsage: `/dig <name> [type]`", &tele.SendOptions{ParseMode: tele.ModeMarkdown}) return c.Reply(
"Invalid arguments.\nUsage: `/dig <name> [type]`",
&tele.SendOptions{ParseMode: tele.ModeMarkdown},
tele.Silent,
)
} }
resp, err := cmds.Dig(req) resp, err := cmds.Dig(req)
if err != nil { if err != nil {
_ = c.Reply(stickerFromID(stickerPanic)) _ = c.Reply(stickerFromID(stickerPanic), tele.Silent)
return err return err
} }
@ -286,5 +290,5 @@ func handleDigCmd(c tele.Context) error {
html.EscapeString(replyBuf.String()), html.EscapeString(replyBuf.String()),
"</pre>", "</pre>",
} }
return c.Reply(strings.Join(replyText, ""), &tele.SendOptions{ParseMode: tele.ModeHTML}) return c.Reply(strings.Join(replyText, ""), &tele.SendOptions{ParseMode: tele.ModeHTML}, tele.Silent)
} }