Skip to content

Commit

Permalink
Fix a bug in the usage report of the bot that resulted in a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
mjef committed Apr 24, 2023
1 parent 87aa43e commit 23a5524
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
27 changes: 14 additions & 13 deletions web/job/stats_notify_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,22 @@ func (j *StatsNotifyJob) OnReceive() *StatsNotifyJob {

resp, del, upd := j.telegramService.HandleCallback(update.CallbackQuery)

if upd {
updateMsg := tgbotapi.NewEditMessageText(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID, resp.Text)
keyboard := resp.ReplyMarkup.(tgbotapi.InlineKeyboardMarkup)
updateMsg.ReplyMarkup = &keyboard

if _, err := bot.Request(updateMsg); err != nil {
logger.Warning(err)
}
} else if resp != nil {
_, err := bot.Send(resp)
if err != nil {
logger.Warning(err)
if resp != nil {
if upd {
updateMsg := tgbotapi.NewEditMessageText(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID, resp.Text)
keyboard := resp.ReplyMarkup.(tgbotapi.InlineKeyboardMarkup)
updateMsg.ReplyMarkup = &keyboard

if _, err := bot.Request(updateMsg); err != nil {
logger.Warning(err)
}
} else {
_, err := bot.Send(resp)
if err != nil {
logger.Warning(err)
}
}
}

if del {
deleteMsg := tgbotapi.NewDeleteMessage(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID)
if _, err := bot.Request(deleteMsg); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions web/service/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,13 @@ func (t *TelegramService) HandleCallback(callback *tgbotapi.CallbackQuery) (resp
lang = client.Language
}

resp, _ = t.GetClientUsage(chatId, strings.TrimPrefix(callback.Data, updateCommandPrefix), t.settingService.GetTgCrmEnabled(), lang)
resp, err = t.GetClientUsage(chatId, strings.TrimPrefix(callback.Data, updateCommandPrefix), t.settingService.GetTgCrmEnabled(), lang)
delete = false
update = true
if err == nil {
update = true
} else {
update = false
}
return
} else if strings.HasPrefix(callback.Data, renewCommandPrefix) {
if _, exists := TgSessions[callback.Message.Chat.ID]; !exists {
Expand Down

0 comments on commit 23a5524

Please sign in to comment.