mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
New - TGbot, "All clients" button (#2493)
This commit is contained in:
parent
9dcc55ea1b
commit
de8c80597f
3 changed files with 108 additions and 0 deletions
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -769,8 +770,40 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
} else {
|
} else {
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.errorOperation"))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.errorOperation"))
|
||||||
}
|
}
|
||||||
|
case "get_clients":
|
||||||
|
inboundId := dataArray[1]
|
||||||
|
inboundIdInt, err := strconv.Atoi(inboundId)
|
||||||
|
if err != nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
inbound, err := t.inboundService.GetInbound(inboundIdInt)
|
||||||
|
if err != nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clients, err := t.getInboundClients(inboundIdInt)
|
||||||
|
if err != nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.chooseClient", "Inbound=="+inbound.Remark), clients)
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
switch callbackQuery.Data {
|
||||||
|
case "get_inbounds":
|
||||||
|
inbounds, err := t.getInbounds()
|
||||||
|
if err != nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, err.Error())
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.buttons.allClients"))
|
||||||
|
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.chooseInbound"), inbounds)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,6 +870,7 @@ func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool) {
|
||||||
tu.InlineKeyboardRow(
|
tu.InlineKeyboardRow(
|
||||||
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.commands")).WithCallbackData(t.encodeQuery("commands")),
|
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.commands")).WithCallbackData(t.encodeQuery("commands")),
|
||||||
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.onlines")).WithCallbackData(t.encodeQuery("onlines")),
|
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.onlines")).WithCallbackData(t.encodeQuery("onlines")),
|
||||||
|
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.allClients")).WithCallbackData(t.encodeQuery("get_inbounds")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
numericKeyboardClient := tu.InlineKeyboard(
|
numericKeyboardClient := tu.InlineKeyboard(
|
||||||
|
@ -1082,6 +1116,72 @@ func (t *Tgbot) getInboundUsages() string {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tgbot) getInbounds() (*telego.InlineKeyboardMarkup, error) {
|
||||||
|
inbounds, err := t.inboundService.GetAllInbounds()
|
||||||
|
var buttons []telego.InlineKeyboardButton
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("GetAllInbounds run failed:", err)
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
|
} else {
|
||||||
|
if len(inbounds) > 0 {
|
||||||
|
for _, inbound := range inbounds {
|
||||||
|
status := "❌"
|
||||||
|
if inbound.Enable {
|
||||||
|
status = "✅"
|
||||||
|
}
|
||||||
|
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(t.encodeQuery("get_clients "+strconv.Itoa(inbound.Id))))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Warning("GetAllInbounds run failed:", err)
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
cols := 0
|
||||||
|
if len(buttons) < 6 {
|
||||||
|
cols = 3
|
||||||
|
} else {
|
||||||
|
cols = 2
|
||||||
|
}
|
||||||
|
keyboard := tu.InlineKeyboardGrid(tu.InlineKeyboardCols(cols, buttons...))
|
||||||
|
return keyboard, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tgbot) getInboundClients(id int) (*telego.InlineKeyboardMarkup, error) {
|
||||||
|
inbound, err := t.inboundService.GetInbound(id)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("getIboundClients run failed:", err)
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
|
}
|
||||||
|
clients, err := t.inboundService.GetClients(inbound)
|
||||||
|
var buttons []telego.InlineKeyboardButton
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("GetInboundClients run failed:", err)
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
|
} else {
|
||||||
|
if len(clients) > 0 {
|
||||||
|
for _, client := range clients {
|
||||||
|
buttons = append(buttons, tu.InlineKeyboardButton(client.Email).WithCallbackData(t.encodeQuery("client_get_usage "+client.Email)))
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getClientsFailed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
cols := 0
|
||||||
|
if len(buttons) < 6 {
|
||||||
|
cols = 3
|
||||||
|
} else {
|
||||||
|
cols = 2
|
||||||
|
}
|
||||||
|
keyboard := tu.InlineKeyboardGrid(tu.InlineKeyboardCols(cols, buttons...))
|
||||||
|
|
||||||
|
return keyboard, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tgbot) clientInfoMsg(
|
func (t *Tgbot) clientInfoMsg(
|
||||||
traffic *xray.ClientTraffic,
|
traffic *xray.ClientTraffic,
|
||||||
printEnabled bool,
|
printEnabled bool,
|
||||||
|
|
|
@ -618,11 +618,13 @@
|
||||||
"confirmNumberAdd" = "✅ Confirm adding: {{ .Num }}"
|
"confirmNumberAdd" = "✅ Confirm adding: {{ .Num }}"
|
||||||
"limitTraffic" = "🚧 Traffic Limit"
|
"limitTraffic" = "🚧 Traffic Limit"
|
||||||
"getBanLogs" = "Get Ban Logs"
|
"getBanLogs" = "Get Ban Logs"
|
||||||
|
"allClients" = "All Clients"
|
||||||
|
|
||||||
[tgbot.answers]
|
[tgbot.answers]
|
||||||
"successfulOperation" = "✅ Operation successful!"
|
"successfulOperation" = "✅ Operation successful!"
|
||||||
"errorOperation" = "❗ Error in operation."
|
"errorOperation" = "❗ Error in operation."
|
||||||
"getInboundsFailed" = "❌ Failed to get inbounds."
|
"getInboundsFailed" = "❌ Failed to get inbounds."
|
||||||
|
"getClientsFailed" = "❌ Failed to get clients."
|
||||||
"canceled" = "❌ {{ .Email }}: Operation canceled."
|
"canceled" = "❌ {{ .Email }}: Operation canceled."
|
||||||
"clientRefreshSuccess" = "✅ {{ .Email }}: Client refreshed successfully."
|
"clientRefreshSuccess" = "✅ {{ .Email }}: Client refreshed successfully."
|
||||||
"IpRefreshSuccess" = "✅ {{ .Email }}: IPs refreshed successfully."
|
"IpRefreshSuccess" = "✅ {{ .Email }}: IPs refreshed successfully."
|
||||||
|
@ -638,3 +640,5 @@
|
||||||
"enableSuccess" = "✅ {{ .Email }}: Enabled successfully."
|
"enableSuccess" = "✅ {{ .Email }}: Enabled successfully."
|
||||||
"disableSuccess" = "✅ {{ .Email }}: Disabled successfully."
|
"disableSuccess" = "✅ {{ .Email }}: Disabled successfully."
|
||||||
"askToAddUserId" = "Your configuration is not found!\r\nPlease ask your admin to use your Telegram ID in your configuration(s).\r\n\r\nYour User ID: <code>{{ .TgUserID }}</code>"
|
"askToAddUserId" = "Your configuration is not found!\r\nPlease ask your admin to use your Telegram ID in your configuration(s).\r\n\r\nYour User ID: <code>{{ .TgUserID }}</code>"
|
||||||
|
"chooseClient" = "Choose a Client for Inbound {{ .Inbound }}"
|
||||||
|
"chooseInbound" = "Choose an Inbound"
|
||||||
|
|
|
@ -618,11 +618,13 @@
|
||||||
"confirmNumberAdd" = "✅ Подтвердить добавление: {{ .Num }}"
|
"confirmNumberAdd" = "✅ Подтвердить добавление: {{ .Num }}"
|
||||||
"limitTraffic" = "🚧 Лимит трафика"
|
"limitTraffic" = "🚧 Лимит трафика"
|
||||||
"getBanLogs" = "Логи блокировок"
|
"getBanLogs" = "Логи блокировок"
|
||||||
|
"allClients" = "Все клиенты"
|
||||||
|
|
||||||
[tgbot.answers]
|
[tgbot.answers]
|
||||||
"successfulOperation" = "✅ Успешный!"
|
"successfulOperation" = "✅ Успешный!"
|
||||||
"errorOperation" = "❗ Ошибка в операции."
|
"errorOperation" = "❗ Ошибка в операции."
|
||||||
"getInboundsFailed" = "❌ Не удалось получить входящие потоки."
|
"getInboundsFailed" = "❌ Не удалось получить входящие потоки."
|
||||||
|
"getClientsFailed" = "❌ Не удалось получить клиентов."
|
||||||
"canceled" = "❌ {{ .Email }}: Операция отменена."
|
"canceled" = "❌ {{ .Email }}: Операция отменена."
|
||||||
"clientRefreshSuccess" = "✅ {{ .Email }}: Клиент успешно обновлен."
|
"clientRefreshSuccess" = "✅ {{ .Email }}: Клиент успешно обновлен."
|
||||||
"IpRefreshSuccess" = "✅ {{ .Email }}: IP-адреса успешно обновлены."
|
"IpRefreshSuccess" = "✅ {{ .Email }}: IP-адреса успешно обновлены."
|
||||||
|
@ -638,3 +640,5 @@
|
||||||
"enableSuccess" = "✅ {{ .Email }}: Включено успешно."
|
"enableSuccess" = "✅ {{ .Email }}: Включено успешно."
|
||||||
"disableSuccess" = "✅ {{ .Email }}: Отключено успешно."
|
"disableSuccess" = "✅ {{ .Email }}: Отключено успешно."
|
||||||
"askToAddUserId" = "Ваша конфигурация не найдена!\r\nПожалуйста, попросите администратора использовать ваш идентификатор пользователя Telegram в ваших конфигурациях.\r\n\r\nВаш идентификатор пользователя: <code>{{ .TgUserID }}</code>"
|
"askToAddUserId" = "Ваша конфигурация не найдена!\r\nПожалуйста, попросите администратора использовать ваш идентификатор пользователя Telegram в ваших конфигурациях.\r\n\r\nВаш идентификатор пользователя: <code>{{ .TgUserID }}</code>"
|
||||||
|
"chooseClient" = "Выберите пользователя для подключения {{ .Inbound }}"
|
||||||
|
"chooseInbound" = "Выберите подключение"
|
||||||
|
|
Loading…
Reference in a new issue