diff options
| author | Ahmad Thoriq Najahi <najahi@zephyrus.id> | 2024-05-14 15:00:10 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-14 15:00:10 +0300 |
| commit | 73a19a45d76a53579ccd9cf306258f57b59a2836 (patch) | |
| tree | 0d06f316589d149196a4f4b70e8d957f656c5dea /web | |
| parent | 0fb4094fe6032606b7cd99d89f16f3f1ad403629 (diff) | |
feat(tgbot): Add refresh button to server usage (#2253)
- Added a refresh button to the server usage interface to allow users to refresh the displayed information.
- Updated the sendReport function to use the sendServerUsage function instead of getServerUsage to ensure consistency in functionality.
Signed-off-by: Ahmad Thoriq Najahi <najahi@zephyrus.id>
Diffstat (limited to 'web')
| -rw-r--r-- | web/service/tgbot.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/web/service/tgbot.go b/web/service/tgbot.go index b8b04f05..0880faaa 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -770,7 +770,10 @@ func (t *Tgbot) asnwerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool switch callbackQuery.Data { case "get_usage": t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.buttons.serverUsage")) - t.SendMsgToTgbot(chatId, t.getServerUsage()) + t.getServerUsage(chatId) + case "usage_refresh": + t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation")) + t.getServerUsage(chatId, callbackQuery.Message.GetMessageID()) case "inbounds": t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.buttons.getInbounds")) t.SendMsgToTgbot(chatId, t.getInboundUsages()) @@ -916,7 +919,7 @@ func (t *Tgbot) SendReport() { t.SendMsgToTgbotAdmins(msg) } - info := t.getServerUsage() + info := t.sendServerUsage() t.SendMsgToTgbotAdmins(info) t.sendExhaustedToAdmins() @@ -946,7 +949,28 @@ func (t *Tgbot) sendExhaustedToAdmins() { } } -func (t *Tgbot) getServerUsage() string { +func (t *Tgbot) getServerUsage(chatId int64, messageID ...int) string { + info := t.prepareServerUsageInfo() + + keyboard := tu.InlineKeyboard(tu.InlineKeyboardRow( + tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.refresh")).WithCallbackData(t.encodeQuery("usage_refresh")))) + + if len(messageID) > 0 { + t.editMessageTgBot(chatId, messageID[0], info, keyboard) + } else { + t.SendMsgToTgbot(chatId, info, keyboard) + } + + return info +} + +// Send server usage without an inline keyborad +func (t *Tgbot) sendServerUsage() string { + info := t.prepareServerUsageInfo() + return info +} + +func (t *Tgbot) prepareServerUsageInfo() string { info, ipv4, ipv6 := "", "", "" // get latest status of server |
