mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-17 15:47:14 +00:00
fix(tgbot): suppress 'message not modified' warnings in Telegram edit calls (#6340)
When users click Refresh buttons in the Telegram bot (usage_refresh, client_refresh, ips_refresh, onlines_refresh), editMessageText and editMessageReplyMarkup are always called even when the content has not changed. Telegram returns a 400 "message is not modified" error which was logged as Warning, cluttering the logs on every refresh click. Add isTelegramNotModifiedError helper that detects this specific Telegram API error and logs it at Debug level instead of Warning.
This commit is contained in:
@@ -210,6 +210,10 @@ func (t *Tgbot) editMessageCallbackTgBot(chatId int64, messageID int, inlineKeyb
|
||||
ReplyMarkup: inlineKeyboard,
|
||||
}
|
||||
if _, err := bot.EditMessageReplyMarkup(context.Background(), ¶ms); err != nil {
|
||||
if isTelegramNotModifiedError(err) {
|
||||
logger.Debug("Telegram reply markup unchanged, skipping edit")
|
||||
return
|
||||
}
|
||||
logger.Warning(err)
|
||||
}
|
||||
}
|
||||
@@ -226,10 +230,25 @@ func (t *Tgbot) editMessageTgBot(chatId int64, messageID int, text string, inlin
|
||||
params.ReplyMarkup = inlineKeyboard[0]
|
||||
}
|
||||
if _, err := bot.EditMessageText(context.Background(), ¶ms); err != nil {
|
||||
if isTelegramNotModifiedError(err) {
|
||||
logger.Debug("Telegram message text unchanged, skipping edit")
|
||||
return
|
||||
}
|
||||
logger.Warning(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Telegram answers a no-op edit with a 400 whose description carries this text;
|
||||
// a refresh tap that changed nothing is not an operator-visible failure.
|
||||
func isTelegramNotModifiedError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
errStr := err.Error()
|
||||
return strings.Contains(errStr, "not modified") ||
|
||||
strings.Contains(errStr, "No fields to modify")
|
||||
}
|
||||
|
||||
// SendMsgToTgbotDeleteAfter sends a message and deletes it after a specified delay.
|
||||
func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup) {
|
||||
// Determine if replyMarkup was passed; otherwise, set it to nil
|
||||
|
||||
Reference in New Issue
Block a user