chore: code adjustment (#512)

This commit is contained in:
Khanh Ngo 2023-12-29 10:56:37 +01:00 committed by GitHub
parent 8cfe9a3d5b
commit 45849a2aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 69 deletions

View file

@ -26,8 +26,8 @@ var (
Bot *echotron.API
BotMutex sync.RWMutex
floodWait = make(map[int64]int64, 0)
floodMessageSent = make(map[int64]struct{}, 0)
floodWait = make(map[int64]int64)
floodMessageSent = make(map[int64]struct{})
)
func Start(initDeps TgBotInitDependencies) (err error) {
@ -84,12 +84,15 @@ func Start(initDeps TgBotInitDependencies) (err error) {
continue
}
floodMessageSent[userid] = struct{}{}
bot.SendMessage(
_, err := bot.SendMessage(
fmt.Sprintf("You can only request your configs once per %d minutes", FloodWait),
userid,
&echotron.MessageOptions{
ReplyToMessageID: update.Message.ID,
})
if err != nil {
log.Errorf("Failed to send telegram message. Error %v", err)
}
continue
}
floodWait[userid] = time.Now().Unix()
@ -100,12 +103,15 @@ func Start(initDeps TgBotInitDependencies) (err error) {
for _, f := range failed {
messageText += f + "\n"
}
bot.SendMessage(
_, err := bot.SendMessage(
messageText,
userid,
&echotron.MessageOptions{
ReplyToMessageID: update.Message.ID,
})
if err != nil {
log.Errorf("Failed to send telegram message. Error %v", err)
}
}
}
}