mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 13:32:24 +00:00
minor changes
This commit is contained in:
parent
bea19a263d
commit
3ded4ee658
4 changed files with 157 additions and 171 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
# Ignore log files
|
# Ignore log files
|
||||||
*.log
|
*.log
|
||||||
access.log
|
|
||||||
error.log
|
|
||||||
|
|
||||||
# Ignore temporary files
|
# Ignore temporary files
|
||||||
tmp/
|
tmp/
|
||||||
|
|
|
@ -56,6 +56,9 @@
|
||||||
.dark .ant-input-password-icon {
|
.dark .ant-input-password-icon {
|
||||||
color: var(--dark-color-text-primary);
|
color: var(--dark-color-text-primary);
|
||||||
}
|
}
|
||||||
|
.ant-collapse-content-box .ant-alert {
|
||||||
|
margin-block-end: 12px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
.ant-list-item>li {
|
.ant-list-item>li {
|
||||||
padding: 10px 20px !important;
|
padding: 10px 20px !important;
|
||||||
}
|
}
|
||||||
|
.ant-collapse-content-box .ant-alert {
|
||||||
|
margin-block-end: 12px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
||||||
|
|
|
@ -33,38 +33,35 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bot *telego.Bot
|
bot *telego.Bot
|
||||||
botHandler *th.BotHandler
|
botHandler *th.BotHandler
|
||||||
adminIds []int64
|
adminIds []int64
|
||||||
isRunning bool
|
isRunning bool
|
||||||
hostname string
|
hostname string
|
||||||
hashStorage *global.HashStorage
|
hashStorage *global.HashStorage
|
||||||
handler *th.Handler
|
handler *th.Handler
|
||||||
|
|
||||||
// clients data to adding new client
|
// clients data to adding new client
|
||||||
receiver_inbound_ID int
|
receiver_inbound_ID int
|
||||||
client_Id string
|
client_Id string
|
||||||
client_Flow string
|
client_Flow string
|
||||||
client_Email string
|
client_Email string
|
||||||
client_LimitIP int
|
client_LimitIP int
|
||||||
client_TotalGB int64
|
client_TotalGB int64
|
||||||
client_ExpiryTime int64
|
client_ExpiryTime int64
|
||||||
client_Enable bool
|
client_Enable bool
|
||||||
client_TgID string
|
client_TgID string
|
||||||
client_SubID string
|
client_SubID string
|
||||||
client_Comment string
|
client_Comment string
|
||||||
client_Reset int
|
client_Reset int
|
||||||
client_Security string
|
client_Security string
|
||||||
client_ShPassword string
|
client_ShPassword string
|
||||||
client_TrPassword string
|
client_TrPassword string
|
||||||
client_Method string
|
client_Method string
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var userStates = make(map[int64]string)
|
var userStates = make(map[int64]string)
|
||||||
|
|
||||||
|
|
||||||
type LoginStatus byte
|
type LoginStatus byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -73,8 +70,6 @@ const (
|
||||||
EmptyTelegramUserID = int64(0)
|
EmptyTelegramUserID = int64(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type Tgbot struct {
|
type Tgbot struct {
|
||||||
inboundService InboundService
|
inboundService InboundService
|
||||||
settingService SettingService
|
settingService SettingService
|
||||||
|
@ -83,7 +78,6 @@ type Tgbot struct {
|
||||||
lastStatus *Status
|
lastStatus *Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) NewTgbot() *Tgbot {
|
func (t *Tgbot) NewTgbot() *Tgbot {
|
||||||
return new(Tgbot)
|
return new(Tgbot)
|
||||||
}
|
}
|
||||||
|
@ -263,7 +257,7 @@ func (t *Tgbot) OnReceive() {
|
||||||
}, th.AnyCommand())
|
}, th.AnyCommand())
|
||||||
|
|
||||||
botHandler.HandleCallbackQuery(func(_ *telego.Bot, query telego.CallbackQuery) {
|
botHandler.HandleCallbackQuery(func(_ *telego.Bot, query telego.CallbackQuery) {
|
||||||
delete(userStates,query.Message.GetChat().ID)
|
delete(userStates, query.Message.GetChat().ID)
|
||||||
t.answerCallback(&query, checkAdmin(query.From.ID))
|
t.answerCallback(&query, checkAdmin(query.From.ID))
|
||||||
}, th.AnyCallbackQueryWithMessage())
|
}, th.AnyCallbackQueryWithMessage())
|
||||||
|
|
||||||
|
@ -384,8 +378,8 @@ func (t *Tgbot) OnReceive() {
|
||||||
t.SendMsgToTgbotDeleteAfter(message.Chat.ID, t.I18nBot("tgbot.messages.received_comment"), 3, tu.ReplyKeyboardRemove())
|
t.SendMsgToTgbotDeleteAfter(message.Chat.ID, t.I18nBot("tgbot.messages.received_comment"), 3, tu.ReplyKeyboardRemove())
|
||||||
delete(userStates, message.Chat.ID)
|
delete(userStates, message.Chat.ID)
|
||||||
inbound, _ := t.inboundService.GetInbound(receiver_inbound_ID)
|
inbound, _ := t.inboundService.GetInbound(receiver_inbound_ID)
|
||||||
message_text, _ := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
message_text, _ := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||||
t.addClient(message.Chat.ID, message_text)
|
t.addClient(message.Chat.ID, message_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,7 +493,6 @@ func (t *Tgbot) sendResponse(chatId int64, msg string, onlyMessage, isAdmin bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) randomLowerAndNum(length int) string {
|
func (t *Tgbot) randomLowerAndNum(length int) string {
|
||||||
charset := "abcdefghijklmnopqrstuvwxyz0123456789"
|
charset := "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
bytes := make([]byte, length)
|
bytes := make([]byte, length)
|
||||||
|
@ -510,7 +503,6 @@ func (t *Tgbot) randomLowerAndNum(length int) string {
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) randomShadowSocksPassword() string {
|
func (t *Tgbot) randomShadowSocksPassword() string {
|
||||||
array := make([]byte, 32)
|
array := make([]byte, 32)
|
||||||
_, err := rand.Read(array)
|
_, err := rand.Read(array)
|
||||||
|
@ -520,7 +512,6 @@ func (t *Tgbot) randomShadowSocksPassword() string {
|
||||||
return base64.StdEncoding.EncodeToString(array)
|
return base64.StdEncoding.EncodeToString(array)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
|
func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
|
||||||
chatId := callbackQuery.Message.GetChat().ID
|
chatId := callbackQuery.Message.GetChat().ID
|
||||||
|
|
||||||
|
@ -695,7 +686,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
}
|
}
|
||||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||||
|
|
||||||
t.addClient(chatId,message_text,messageId)
|
t.addClient(chatId, message_text, messageId)
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
||||||
case "add_client_limit_traffic_in":
|
case "add_client_limit_traffic_in":
|
||||||
if len(dataArray) >= 2 {
|
if len(dataArray) >= 2 {
|
||||||
|
@ -910,7 +901,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
}
|
}
|
||||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||||
|
|
||||||
t.addClient(chatId,message_text,messageId)
|
t.addClient(chatId, message_text, messageId)
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
||||||
case "add_client_reset_exp_in":
|
case "add_client_reset_exp_in":
|
||||||
if len(dataArray) >= 2 {
|
if len(dataArray) >= 2 {
|
||||||
|
@ -1173,7 +1164,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.chooseClient", "Inbound=="+inbound.Remark), clients)
|
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.chooseClient", "Inbound=="+inbound.Remark), clients)
|
||||||
case "add_client_to":
|
case "add_client_to":
|
||||||
// assign default values to clients variables
|
// assign default values to clients variables
|
||||||
client_Id = uuid.New().String()
|
client_Id = uuid.New().String()
|
||||||
client_Flow = ""
|
client_Flow = ""
|
||||||
client_Email = t.randomLowerAndNum(8)
|
client_Email = t.randomLowerAndNum(8)
|
||||||
client_LimitIP = 0
|
client_LimitIP = 0
|
||||||
|
@ -1184,10 +1175,10 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
client_SubID = t.randomLowerAndNum(16)
|
client_SubID = t.randomLowerAndNum(16)
|
||||||
client_Comment = ""
|
client_Comment = ""
|
||||||
client_Reset = 0
|
client_Reset = 0
|
||||||
client_Security="auto"
|
client_Security = "auto"
|
||||||
client_ShPassword=t.randomShadowSocksPassword()
|
client_ShPassword = t.randomShadowSocksPassword()
|
||||||
client_TrPassword=t.randomLowerAndNum(10)
|
client_TrPassword = t.randomLowerAndNum(10)
|
||||||
client_Method=""
|
client_Method = ""
|
||||||
|
|
||||||
inboundId := dataArray[1]
|
inboundId := dataArray[1]
|
||||||
inboundIdInt, err := strconv.Atoi(inboundId)
|
inboundIdInt, err := strconv.Atoi(inboundId)
|
||||||
|
@ -1260,7 +1251,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.commands.helpAdminCommands"))
|
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.commands.helpAdminCommands"))
|
||||||
case "add_client":
|
case "add_client":
|
||||||
// assign default values to clients variables
|
// assign default values to clients variables
|
||||||
client_Id = uuid.New().String()
|
client_Id = uuid.New().String()
|
||||||
client_Flow = ""
|
client_Flow = ""
|
||||||
client_Email = t.randomLowerAndNum(8)
|
client_Email = t.randomLowerAndNum(8)
|
||||||
client_LimitIP = 0
|
client_LimitIP = 0
|
||||||
|
@ -1271,10 +1262,10 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
client_SubID = t.randomLowerAndNum(16)
|
client_SubID = t.randomLowerAndNum(16)
|
||||||
client_Comment = ""
|
client_Comment = ""
|
||||||
client_Reset = 0
|
client_Reset = 0
|
||||||
client_Security="auto"
|
client_Security = "auto"
|
||||||
client_ShPassword=t.randomShadowSocksPassword()
|
client_ShPassword = t.randomShadowSocksPassword()
|
||||||
client_TrPassword=t.randomLowerAndNum(10)
|
client_TrPassword = t.randomLowerAndNum(10)
|
||||||
client_Method=""
|
client_Method = ""
|
||||||
|
|
||||||
inbounds, err := t.getInboundsAddClient()
|
inbounds, err := t.getInboundsAddClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1332,7 +1323,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
prompt_message := t.I18nBot("tgbot.messages.comment_prompt", "ClientComment=="+client_Comment)
|
prompt_message := t.I18nBot("tgbot.messages.comment_prompt", "ClientComment=="+client_Comment)
|
||||||
t.SendMsgToTgbot(chatId, prompt_message, cancel_btn_markup)
|
t.SendMsgToTgbot(chatId, prompt_message, cancel_btn_markup)
|
||||||
case "add_client_ch_default_traffic":
|
case "add_client_ch_default_traffic":
|
||||||
inlineKeyboard := tu.InlineKeyboard(
|
inlineKeyboard := tu.InlineKeyboard(
|
||||||
tu.InlineKeyboardRow(
|
tu.InlineKeyboardRow(
|
||||||
|
@ -1410,7 +1401,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||||
t.addClient(chatId,message_text,messageId)
|
t.addClient(chatId, message_text, messageId)
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.canceled", "Email=="+client_Email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.canceled", "Email=="+client_Email))
|
||||||
case "add_client_submit_disable":
|
case "add_client_submit_disable":
|
||||||
client_Enable = false
|
client_Enable = false
|
||||||
|
@ -1425,9 +1416,8 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string, protocol model.Protocol) (string, error) {
|
||||||
func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol model.Protocol) (string, error) {
|
var message string
|
||||||
var message string
|
|
||||||
|
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
timestampMillis := currentTime.UnixNano() / int64(time.Millisecond)
|
timestampMillis := currentTime.UnixNano() / int64(time.Millisecond)
|
||||||
|
@ -1447,34 +1437,33 @@ func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol mo
|
||||||
traffic_value := ""
|
traffic_value := ""
|
||||||
if client_TotalGB == 0 {
|
if client_TotalGB == 0 {
|
||||||
traffic_value = "♾️ Unlimited(Reset)"
|
traffic_value = "♾️ Unlimited(Reset)"
|
||||||
}else {
|
} else {
|
||||||
traffic_value = common.FormatTraffic(client_TotalGB)
|
traffic_value = common.FormatTraffic(client_TotalGB)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch protocol {
|
switch protocol {
|
||||||
case model.VMESS, model.VLESS:
|
case model.VMESS, model.VLESS:
|
||||||
message = t.I18nBot("tgbot.messages.inbound_client_data_id", "InboundRemark=="+inbound_remark,"ClientId=="+client_Id,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
message = t.I18nBot("tgbot.messages.inbound_client_data_id", "InboundRemark=="+inbound_remark, "ClientId=="+client_Id, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||||
|
|
||||||
case model.Trojan:
|
case model.Trojan:
|
||||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark,"ClientPass=="+client_TrPassword,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark, "ClientPass=="+client_TrPassword, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||||
|
|
||||||
case model.Shadowsocks:
|
case model.Shadowsocks:
|
||||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark,"ClientPass=="+client_ShPassword,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark, "ClientPass=="+client_ShPassword, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "", errors.New("unknown protocol")
|
return "", errors.New("unknown protocol")
|
||||||
}
|
}
|
||||||
|
|
||||||
return message, nil
|
return message, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||||
var jsonString string
|
var jsonString string
|
||||||
|
|
||||||
switch protocol {
|
switch protocol {
|
||||||
case model.VMESS:
|
case model.VMESS:
|
||||||
jsonString = fmt.Sprintf(`{
|
jsonString = fmt.Sprintf(`{
|
||||||
"clients": [{
|
"clients": [{
|
||||||
"id": "%s",
|
"id": "%s",
|
||||||
"security": "%s",
|
"security": "%s",
|
||||||
|
@ -1490,8 +1479,8 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||||
}]
|
}]
|
||||||
}`, client_Id, client_Security, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
}`, client_Id, client_Security, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
||||||
|
|
||||||
case model.VLESS:
|
case model.VLESS:
|
||||||
jsonString = fmt.Sprintf(`{
|
jsonString = fmt.Sprintf(`{
|
||||||
"clients": [{
|
"clients": [{
|
||||||
"id": "%s",
|
"id": "%s",
|
||||||
"flow": "%s",
|
"flow": "%s",
|
||||||
|
@ -1507,8 +1496,8 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||||
}]
|
}]
|
||||||
}`, client_Id, client_Flow, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
}`, client_Id, client_Flow, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
||||||
|
|
||||||
case model.Trojan:
|
case model.Trojan:
|
||||||
jsonString = fmt.Sprintf(`{
|
jsonString = fmt.Sprintf(`{
|
||||||
"clients": [{
|
"clients": [{
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
"email": "%s",
|
"email": "%s",
|
||||||
|
@ -1523,8 +1512,8 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||||
}]
|
}]
|
||||||
}`, client_TrPassword, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
}`, client_TrPassword, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
||||||
|
|
||||||
case model.Shadowsocks:
|
case model.Shadowsocks:
|
||||||
jsonString = fmt.Sprintf(`{
|
jsonString = fmt.Sprintf(`{
|
||||||
"clients": [{
|
"clients": [{
|
||||||
"method": "%s",
|
"method": "%s",
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
|
@ -1540,25 +1529,21 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||||
}]
|
}]
|
||||||
}`, client_Method, client_ShPassword, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
}`, client_Method, client_ShPassword, client_Email, client_LimitIP, client_TotalGB, client_ExpiryTime, client_Enable, client_TgID, client_SubID, client_Comment, client_Reset)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "", errors.New("unknown protocol")
|
return "", errors.New("unknown protocol")
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonString, nil
|
return jsonString, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) SubmitAddClient() (bool, error) {
|
func (t *Tgbot) SubmitAddClient() (bool, error) {
|
||||||
|
|
||||||
|
|
||||||
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
|
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("getIboundClients run failed:", err)
|
logger.Warning("getIboundClients run failed:", err)
|
||||||
return false, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
return false, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jsonString, err := t.BuildJSONForProtocol(inbound.Protocol)
|
jsonString, err := t.BuildJSONForProtocol(inbound.Protocol)
|
||||||
|
|
||||||
newInbound := &model.Inbound{
|
newInbound := &model.Inbound{
|
||||||
|
@ -1566,7 +1551,6 @@ func (t *Tgbot) SubmitAddClient() (bool, error) {
|
||||||
Settings: jsonString,
|
Settings: jsonString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return t.inboundService.AddInboundClient(newInbound)
|
return t.inboundService.AddInboundClient(newInbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1862,7 +1846,7 @@ func (t *Tgbot) getInbounds() (*telego.InlineKeyboardMarkup, error) {
|
||||||
if inbound.Enable {
|
if inbound.Enable {
|
||||||
status = "✅"
|
status = "✅"
|
||||||
}
|
}
|
||||||
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","get_clients", inbound.Id))
|
callbackData := t.encodeQuery(fmt.Sprintf("%s %d", "get_clients", inbound.Id))
|
||||||
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1888,11 +1872,11 @@ func (t *Tgbot) getInboundsAddClient() (*telego.InlineKeyboardMarkup, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
excludedProtocols := map[model.Protocol]bool{
|
excludedProtocols := map[model.Protocol]bool{
|
||||||
model.DOKODEMO: true,
|
model.DOKODEMO: true,
|
||||||
model.Socks: true,
|
model.Socks: true,
|
||||||
model.WireGuard: true,
|
model.WireGuard: true,
|
||||||
model.HTTP: true,
|
model.HTTP: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
var buttons []telego.InlineKeyboardButton
|
var buttons []telego.InlineKeyboardButton
|
||||||
for _, inbound := range inbounds {
|
for _, inbound := range inbounds {
|
||||||
|
@ -1904,7 +1888,7 @@ func (t *Tgbot) getInboundsAddClient() (*telego.InlineKeyboardMarkup, error) {
|
||||||
if inbound.Enable {
|
if inbound.Enable {
|
||||||
status = "✅"
|
status = "✅"
|
||||||
}
|
}
|
||||||
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","add_client_to", inbound.Id))
|
callbackData := t.encodeQuery(fmt.Sprintf("%s %d", "add_client_to", inbound.Id))
|
||||||
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2216,8 +2200,8 @@ func (t *Tgbot) addClient(chatId int64, msg string, messageID ...int) {
|
||||||
|
|
||||||
protocol := inbound.Protocol
|
protocol := inbound.Protocol
|
||||||
|
|
||||||
switch protocol {
|
switch protocol {
|
||||||
case model.VMESS, model.VLESS:
|
case model.VMESS, model.VLESS:
|
||||||
inlineKeyboard := tu.InlineKeyboard(
|
inlineKeyboard := tu.InlineKeyboard(
|
||||||
tu.InlineKeyboardRow(
|
tu.InlineKeyboardRow(
|
||||||
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_email")).WithCallbackData("add_client_ch_default_email"),
|
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.change_email")).WithCallbackData("add_client_ch_default_email"),
|
||||||
|
@ -2287,7 +2271,7 @@ func (t *Tgbot) addClient(chatId int64, msg string, messageID ...int) {
|
||||||
} else {
|
} else {
|
||||||
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
|
t.SendMsgToTgbot(chatId, msg, inlineKeyboard)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2662,43 +2646,42 @@ func (t *Tgbot) editMessageTgBot(chatId int64, messageID int, text string, inlin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup) {
|
func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup) {
|
||||||
// Determine if replyMarkup was passed; otherwise, set it to nil
|
// Determine if replyMarkup was passed; otherwise, set it to nil
|
||||||
var replyMarkupParam telego.ReplyMarkup
|
var replyMarkupParam telego.ReplyMarkup
|
||||||
if len(replyMarkup) > 0 {
|
if len(replyMarkup) > 0 {
|
||||||
replyMarkupParam = replyMarkup[0] // Use the first element
|
replyMarkupParam = replyMarkup[0] // Use the first element
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the message
|
// Send the message
|
||||||
sentMsg, err := bot.SendMessage(&telego.SendMessageParams{
|
sentMsg, err := bot.SendMessage(&telego.SendMessageParams{
|
||||||
ChatID: tu.ID(chatId),
|
ChatID: tu.ID(chatId),
|
||||||
Text: msg,
|
Text: msg,
|
||||||
ReplyMarkup: replyMarkupParam, // Use the correct replyMarkup value
|
ReplyMarkup: replyMarkupParam, // Use the correct replyMarkup value
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("Failed to send message:", err)
|
logger.Warning("Failed to send message:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the sent message after the specified number of seconds
|
// Delete the sent message after the specified number of seconds
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(delayInSeconds) * time.Second) // Wait for the specified delay
|
time.Sleep(time.Duration(delayInSeconds) * time.Second) // Wait for the specified delay
|
||||||
t.deleteMessageTgBot(chatId, sentMsg.MessageID) // Delete the message
|
t.deleteMessageTgBot(chatId, sentMsg.MessageID) // Delete the message
|
||||||
delete(userStates, chatId)
|
delete(userStates, chatId)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) deleteMessageTgBot(chatId int64, messageID int) {
|
func (t *Tgbot) deleteMessageTgBot(chatId int64, messageID int) {
|
||||||
params := telego.DeleteMessageParams{
|
params := telego.DeleteMessageParams{
|
||||||
ChatID: tu.ID(chatId),
|
ChatID: tu.ID(chatId),
|
||||||
MessageID: messageID,
|
MessageID: messageID,
|
||||||
}
|
}
|
||||||
if err := bot.DeleteMessage(¶ms); err != nil {
|
if err := bot.DeleteMessage(¶ms); err != nil {
|
||||||
logger.Warning("Failed to delete message:", err)
|
logger.Warning("Failed to delete message:", err)
|
||||||
} else {
|
} else {
|
||||||
logger.Info("Message deleted successfully")
|
logger.Info("Message deleted successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) isSingleWord(text string) bool {
|
func (t *Tgbot) isSingleWord(text string) bool {
|
||||||
|
@ -2706,4 +2689,3 @@ func (t *Tgbot) isSingleWord(text string) bool {
|
||||||
re := regexp.MustCompile(`\s+`)
|
re := regexp.MustCompile(`\s+`)
|
||||||
return re.MatchString(text)
|
return re.MatchString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue