Skip to content

Commit

Permalink
feat(tgbot): Add refresh button to server usage (#2253)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
najahiiii committed May 14, 2024
1 parent 0fb4094 commit 73a19a4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions web/service/tgbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -916,7 +919,7 @@ func (t *Tgbot) SendReport() {
t.SendMsgToTgbotAdmins(msg)
}

info := t.getServerUsage()
info := t.sendServerUsage()
t.SendMsgToTgbotAdmins(info)

t.sendExhaustedToAdmins()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73a19a4

Please sign in to comment.