mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
[tgbot] Ability to remove telegram user from the client in the bot
This commit is contained in:
parent
bcdac5aad6
commit
4cf7f75749
1 changed files with 60 additions and 14 deletions
|
@ -183,17 +183,23 @@ func (t *Tgbot) asnwerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
email := dataArray[1]
|
email := dataArray[1]
|
||||||
switch dataArray[0] {
|
switch dataArray[0] {
|
||||||
case "client_refresh":
|
case "client_refresh":
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Client Refreshed successfully.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Client refreshed successfully.", email))
|
||||||
t.searchClient(chatId, email, callbackQuery.Message.MessageID)
|
t.searchClient(chatId, email, callbackQuery.Message.MessageID)
|
||||||
case "client_cancel":
|
case "client_cancel":
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email))
|
||||||
t.searchClient(chatId, email, callbackQuery.Message.MessageID)
|
t.searchClient(chatId, email, callbackQuery.Message.MessageID)
|
||||||
case "ips_refresh":
|
case "ips_refresh":
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : IPs Refreshed successfully.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : IPs refreshed successfully.", email))
|
||||||
t.searchClientIps(chatId, email, callbackQuery.Message.MessageID)
|
t.searchClientIps(chatId, email, callbackQuery.Message.MessageID)
|
||||||
case "ips_cancel":
|
case "ips_cancel":
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email))
|
||||||
t.searchClientIps(chatId, email, callbackQuery.Message.MessageID)
|
t.searchClientIps(chatId, email, callbackQuery.Message.MessageID)
|
||||||
|
case "tgid_refresh":
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Client's Telegram User refreshed successfully.", email))
|
||||||
|
t.clientTelegramUserInfo(chatId, email, callbackQuery.Message.MessageID)
|
||||||
|
case "tgid_cancel":
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email))
|
||||||
|
t.clientTelegramUserInfo(chatId, email, callbackQuery.Message.MessageID)
|
||||||
case "reset_traffic":
|
case "reset_traffic":
|
||||||
inlineKeyboard := tu.InlineKeyboard(
|
inlineKeyboard := tu.InlineKeyboard(
|
||||||
tu.InlineKeyboardRow(
|
tu.InlineKeyboardRow(
|
||||||
|
@ -325,6 +331,29 @@ func (t *Tgbot) asnwerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
case "tg_user":
|
case "tg_user":
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Get Telegram User Info.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Get Telegram User Info.", email))
|
||||||
t.clientTelegramUserInfo(chatId, email)
|
t.clientTelegramUserInfo(chatId, email)
|
||||||
|
case "tgid_remove":
|
||||||
|
inlineKeyboard := tu.InlineKeyboard(
|
||||||
|
tu.InlineKeyboardRow(
|
||||||
|
tu.InlineKeyboardButton("❌ Cancel").WithCallbackData("tgid_cancel "+email),
|
||||||
|
),
|
||||||
|
tu.InlineKeyboardRow(
|
||||||
|
tu.InlineKeyboardButton("✅ Confirm Remove Telegram User?").WithCallbackData("tgid_remove_c "+email),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
t.editMessageCallbackTgBot(chatId, callbackQuery.Message.MessageID, inlineKeyboard)
|
||||||
|
case "tgid_remove_c":
|
||||||
|
traffic, err := t.inboundService.GetClientTrafficByEmail(email)
|
||||||
|
if err != nil || traffic == nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = t.inboundService.SetClientTelegramUserID(traffic.Id, "")
|
||||||
|
if err == nil {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Telegram User removed successfully.", email))
|
||||||
|
t.clientTelegramUserInfo(chatId, email, callbackQuery.Message.MessageID)
|
||||||
|
} else {
|
||||||
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
|
||||||
|
}
|
||||||
case "toggle_enable":
|
case "toggle_enable":
|
||||||
enabled, err := t.inboundService.ToggleClientEnableByEmail(email)
|
enabled, err := t.inboundService.ToggleClientEnableByEmail(email)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -637,7 +666,7 @@ func (t *Tgbot) searchClientIps(chatId int64, email string, messageID ...int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) clientTelegramUserInfo(chatId int64, email string) {
|
func (t *Tgbot) clientTelegramUserInfo(chatId int64, email string, messageID ...int) {
|
||||||
traffic, client, err := t.inboundService.GetClientByEmail(email)
|
traffic, client, err := t.inboundService.GetClientByEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning(err)
|
logger.Warning(err)
|
||||||
|
@ -650,20 +679,37 @@ func (t *Tgbot) clientTelegramUserInfo(chatId int64, email string) {
|
||||||
t.SendMsgToTgbot(chatId, msg)
|
t.SendMsgToTgbot(chatId, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
output := fmt.Sprintf("📧 Email: %s\r\n👤 Telegram User: %s\r\n", email, client.TgID)
|
tdId := "None"
|
||||||
requestUser := telego.KeyboardButtonRequestUser{
|
if len(client.TgID) > 0 {
|
||||||
RequestID: int32(traffic.Id),
|
tdId = client.TgID
|
||||||
UserIsBot: false,
|
|
||||||
}
|
}
|
||||||
keyboard := tu.Keyboard(
|
output := fmt.Sprintf("📧 Email: %s\r\n👤 Telegram User: %s\r\n", email, tdId)
|
||||||
tu.KeyboardRow(
|
inlineKeyboard := tu.InlineKeyboard(
|
||||||
tu.KeyboardButton("👤 Select Telegram User").WithRequestUser(&requestUser),
|
tu.InlineKeyboardRow(
|
||||||
|
tu.InlineKeyboardButton("🔄 Refresh").WithCallbackData("tgid_refresh "+email),
|
||||||
),
|
),
|
||||||
tu.KeyboardRow(
|
tu.InlineKeyboardRow(
|
||||||
tu.KeyboardButton("❌ Close Keyboard"),
|
tu.InlineKeyboardButton("❌ Remove Telegram User").WithCallbackData("tgid_remove "+email),
|
||||||
),
|
),
|
||||||
).WithIsPersistent()
|
)
|
||||||
t.SendMsgToTgbot(chatId, output, keyboard)
|
if len(messageID) > 0 {
|
||||||
|
t.editMessageTgBot(chatId, messageID[0], output, inlineKeyboard)
|
||||||
|
} else {
|
||||||
|
t.SendMsgToTgbot(chatId, output, inlineKeyboard)
|
||||||
|
requestUser := telego.KeyboardButtonRequestUser{
|
||||||
|
RequestID: int32(traffic.Id),
|
||||||
|
UserIsBot: false,
|
||||||
|
}
|
||||||
|
keyboard := tu.Keyboard(
|
||||||
|
tu.KeyboardRow(
|
||||||
|
tu.KeyboardButton("👤 Select Telegram User").WithRequestUser(&requestUser),
|
||||||
|
),
|
||||||
|
tu.KeyboardRow(
|
||||||
|
tu.KeyboardButton("❌ Close Keyboard"),
|
||||||
|
),
|
||||||
|
).WithIsPersistent()
|
||||||
|
t.SendMsgToTgbot(chatId, "👤 Select a telegram user:", keyboard)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
|
func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
|
||||||
|
|
Loading…
Reference in a new issue