Skip to content

Commit 554981d

Browse files
feat(tgbot): send connection links and qrs on client creation (closes #3320)\n\n- Refactored inline keyboards into getCommonClientButtons to respect DRY\n- Extended SubmitAddClient callback handlers to dispatch individual links and QR codes to the bot chat on success. (#3888)
1 parent a08f1c6 commit 554981d

File tree

1 file changed

+38
-64
lines changed

1 file changed

+38
-64
lines changed

web/service/tgbot.go

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,8 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
19261926
} else {
19271927
t.deleteMessageTgBot(chatId, callbackQuery.Message.GetMessageID())
19281928
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.successfulOperation"), tu.ReplyKeyboardRemove())
1929+
t.sendClientIndividualLinks(chatId, client_Email)
1930+
t.sendClientQRLinks(chatId, client_Email)
19291931
}
19301932
case "add_client_submit_enable":
19311933
client_Enable = true
@@ -1936,6 +1938,8 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
19361938
} else {
19371939
t.deleteMessageTgBot(chatId, callbackQuery.Message.GetMessageID())
19381940
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.successfulOperation"), tu.ReplyKeyboardRemove())
1941+
t.sendClientIndividualLinks(chatId, client_Email)
1942+
t.sendClientQRLinks(chatId, client_Email)
19391943
}
19401944
case "reset_all_traffics_cancel":
19411945
t.deleteMessageTgBot(chatId, callbackQuery.Message.GetMessageID())
@@ -3302,6 +3306,27 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
33023306
}
33033307
}
33043308

3309+
// getCommonClientButtons returns the shared inline keyboard rows for client configuration
3310+
func (t *Tgbot) getCommonClientButtons() [][]telego.InlineKeyboardButton {
3311+
return [][]telego.InlineKeyboardButton{
3312+
tu.InlineKeyboardRow(
3313+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.limitTraffic")).WithCallbackData("add_client_ch_default_traffic"),
3314+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.resetExpire")).WithCallbackData("add_client_ch_default_exp"),
3315+
),
3316+
tu.InlineKeyboardRow(
3317+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_comment")).WithCallbackData("add_client_ch_default_comment"),
3318+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.ipLimit")).WithCallbackData("add_client_ch_default_ip_limit"),
3319+
),
3320+
tu.InlineKeyboardRow(
3321+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitDisable")).WithCallbackData("add_client_submit_disable"),
3322+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitEnable")).WithCallbackData("add_client_submit_enable"),
3323+
),
3324+
tu.InlineKeyboardRow(
3325+
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.cancel")).WithCallbackData("add_client_cancel"),
3326+
),
3327+
}
3328+
}
3329+
33053330
// addClient handles the process of adding a new client to an inbound.
33063331
func (t *Tgbot) addClient(chatId int64, msg string, messageID ...int) {
33073332
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
@@ -3312,91 +3337,40 @@ func (t *Tgbot) addClient(chatId int64, msg string, messageID ...int) {
33123337

33133338
protocol := inbound.Protocol
33143339

3340+
var protocolRows [][]telego.InlineKeyboardButton
33153341
switch protocol {
33163342
case model.VMESS, model.VLESS:
3317-
inlineKeyboard := tu.InlineKeyboard(
3343+
protocolRows = [][]telego.InlineKeyboardButton{
33183344
tu.InlineKeyboardRow(
33193345
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_email")).WithCallbackData("add_client_ch_default_email"),
33203346
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_id")).WithCallbackData("add_client_ch_default_id"),
33213347
),
3322-
tu.InlineKeyboardRow(
3323-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.limitTraffic")).WithCallbackData("add_client_ch_default_traffic"),
3324-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.resetExpire")).WithCallbackData("add_client_ch_default_exp"),
3325-
),
3326-
tu.InlineKeyboardRow(
3327-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_comment")).WithCallbackData("add_client_ch_default_comment"),
3328-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.ipLimit")).WithCallbackData("add_client_ch_default_ip_limit"),
3329-
),
3330-
tu.InlineKeyboardRow(
3331-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitDisable")).WithCallbackData("add_client_submit_disable"),
3332-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitEnable")).WithCallbackData("add_client_submit_enable"),
3333-
),
3334-
tu.InlineKeyboardRow(
3335-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.cancel")).WithCallbackData("add_client_cancel"),
3336-
),
3337-
)
3338-
if len(messageID) > 0 {
3339-
t.editMessageTgBot(chatId, messageID[0], msg, inlineKeyboard)
3340-
} else {
3341-
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
33423348
}
33433349
case model.Trojan:
3344-
inlineKeyboard := tu.InlineKeyboard(
3350+
protocolRows = [][]telego.InlineKeyboardButton{
33453351
tu.InlineKeyboardRow(
33463352
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_email")).WithCallbackData("add_client_ch_default_email"),
33473353
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_password")).WithCallbackData("add_client_ch_default_pass_tr"),
33483354
),
3349-
tu.InlineKeyboardRow(
3350-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.limitTraffic")).WithCallbackData("add_client_ch_default_traffic"),
3351-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.resetExpire")).WithCallbackData("add_client_ch_default_exp"),
3352-
),
3353-
tu.InlineKeyboardRow(
3354-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_comment")).WithCallbackData("add_client_ch_default_comment"),
3355-
tu.InlineKeyboardButton("ip limit").WithCallbackData("add_client_ch_default_ip_limit"),
3356-
),
3357-
tu.InlineKeyboardRow(
3358-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitDisable")).WithCallbackData("add_client_submit_disable"),
3359-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitEnable")).WithCallbackData("add_client_submit_enable"),
3360-
),
3361-
tu.InlineKeyboardRow(
3362-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.cancel")).WithCallbackData("add_client_cancel"),
3363-
),
3364-
)
3365-
if len(messageID) > 0 {
3366-
t.editMessageTgBot(chatId, messageID[0], msg, inlineKeyboard)
3367-
} else {
3368-
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
33693355
}
33703356
case model.Shadowsocks:
3371-
inlineKeyboard := tu.InlineKeyboard(
3357+
protocolRows = [][]telego.InlineKeyboardButton{
33723358
tu.InlineKeyboardRow(
33733359
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_email")).WithCallbackData("add_client_ch_default_email"),
33743360
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_password")).WithCallbackData("add_client_ch_default_pass_sh"),
33753361
),
3376-
tu.InlineKeyboardRow(
3377-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.limitTraffic")).WithCallbackData("add_client_ch_default_traffic"),
3378-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.resetExpire")).WithCallbackData("add_client_ch_default_exp"),
3379-
),
3380-
tu.InlineKeyboardRow(
3381-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_comment")).WithCallbackData("add_client_ch_default_comment"),
3382-
tu.InlineKeyboardButton("ip limit").WithCallbackData("add_client_ch_default_ip_limit"),
3383-
),
3384-
tu.InlineKeyboardRow(
3385-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitDisable")).WithCallbackData("add_client_submit_disable"),
3386-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.submitEnable")).WithCallbackData("add_client_submit_enable"),
3387-
),
3388-
tu.InlineKeyboardRow(
3389-
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.cancel")).WithCallbackData("add_client_cancel"),
3390-
),
3391-
)
3392-
3393-
if len(messageID) > 0 {
3394-
t.editMessageTgBot(chatId, messageID[0], msg, inlineKeyboard)
3395-
} else {
3396-
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
33973362
}
33983363
}
33993364

3365+
commonRows := t.getCommonClientButtons()
3366+
inlineKeyboard := tu.InlineKeyboard(append(protocolRows, commonRows...)...)
3367+
3368+
if len(messageID) > 0 {
3369+
t.editMessageTgBot(chatId, messageID[0], msg, inlineKeyboard)
3370+
} else {
3371+
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
3372+
}
3373+
34003374
}
34013375

34023376
// searchInbound searches for inbounds by remark and sends the results.

0 commit comments

Comments
 (0)