[tgbot] - some fixes and improvments

This commit is contained in:
somebodywashere 2023-05-30 09:05:36 +00:00
parent fb0ec65cff
commit 72c289df2b
3 changed files with 64 additions and 44 deletions

View file

@ -697,14 +697,14 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
return
}
now := time.Now().Unix() * 1000
now := time.Now().Unix()
for _, traffic := range traffics {
expiryTime := ""
flag := false
diff := traffic.ExpiryTime - now
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 259200 || !traffic.Enable {
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
@ -725,17 +725,18 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
if (traffic.Enable) {
output += t.I18nBot("tgbot.messages.active")
} else {
output += t.I18nBot("tgbot.messages.inactive")
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
if (traffic.Enable&&flag) {
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
} else {
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
} else {
output += t.I18nBot("tgbot.messages.inactive")
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
output += ""
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
@ -835,13 +836,13 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
return
}
now := time.Now().Unix() * 1000
now := time.Now().Unix()
expiryTime := ""
flag := false
diff := traffic.ExpiryTime - now
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 259200 || !traffic.Enable {
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
@ -862,17 +863,18 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
if (traffic.Enable) {
output += t.I18nBot("tgbot.messages.active")
} else {
output += t.I18nBot("tgbot.messages.inactive")
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
if (traffic.Enable&&flag) {
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
} else {
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
} else {
output += t.I18nBot("tgbot.messages.inactive")
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
output += ""
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
@ -919,7 +921,7 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
return
}
now := time.Now().Unix() * 1000
now := time.Now().Unix()
for _, inbound := range inbouds {
info := ""
info += t.I18nBot("tgbot.messages.inbound", "Remark=="+inbound.Remark)
@ -936,10 +938,10 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
for _, traffic := range inbound.ClientStats {
expiryTime := ""
flag := false
diff := traffic.ExpiryTime - now
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 259200 || !traffic.Enable {
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
@ -960,17 +962,18 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
if (traffic.Enable) {
output += t.I18nBot("tgbot.messages.active")
} else {
output += t.I18nBot("tgbot.messages.inactive")
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
if (traffic.Enable&&flag) {
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
} else {
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
} else {
output += t.I18nBot("tgbot.messages.inactive")
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
output += ""
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
@ -993,13 +996,13 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
return
}
now := time.Now().Unix() * 1000
now := time.Now().Unix()
expiryTime := ""
flag := false
diff := traffic.ExpiryTime - now
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 259200 || !traffic.Enable {
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
@ -1020,17 +1023,18 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
if (traffic.Enable) {
output += t.I18nBot("tgbot.messages.active")
} else {
output += t.I18nBot("tgbot.messages.inactive")
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
if (traffic.Enable&&flag) {
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
} else {
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
} else {
output += t.I18nBot("tgbot.messages.inactive")
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
output += ""
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
@ -1116,12 +1120,18 @@ func (t *Tgbot) getExhausted() string {
for _, traffic := range exhaustedClients {
expiryTime := ""
flag := false
diff := (traffic.ExpiryTime - now)/1000
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if traffic.ExpiryTime < 0 {
expiryTime += fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
} else {
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
flag = true
} else {
expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
flag = true
}
total := ""
@ -1131,13 +1141,23 @@ func (t *Tgbot) getExhausted() string {
total = common.FormatTraffic((traffic.Total))
}
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
output += t.I18nBot("tgbot.messages.active", "Enable=="+strconv.FormatBool(traffic.Enable))
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
if (traffic.Enable) {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
} else {
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
} else {
output += t.I18nBot("tgbot.messages.inactive")
output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime)
}
output += t.I18nBot("tgbot.messages.upload", "Upload=="+common.FormatTraffic(traffic.Up))
output += t.I18nBot("tgbot.messages.download", "Download=="+common.FormatTraffic(traffic.Down))
output += t.I18nBot("tgbot.messages.total", "UpDown=="+common.FormatTraffic((traffic.Up+traffic.Down)), "Total=="+total)
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
output += ""
output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
output += "\r\n \r\n"
}
}

View file

@ -430,9 +430,9 @@
"active" = "💡 Active: ✅ Yes\r\n"
"inactive" = "💡 Active: ❌ No\r\n"
"email" = "📧 Email: {{ .Email }}\r\n"
"upload" = "🔼 Upload: {{ .Upload }}\r\n"
"download" = "🔽 Download: {{ .Download }}\r\n"
"total" = "🔄 Total: {{ .UpDown }} / {{ .Total }}\r\n"
"upload" = "🔼 Upload: {{ .Upload }}\r\n"
"download" = "🔽 Download: {{ .Download }}\r\n"
"total" = "🔄 Total: ↑↓{{ .UpDown }} / {{ .Total }}\r\n"
"TGUser" = "👤 Telegram User: {{ .TelegramID }}\r\n"
"exhaustedMsg" = "🚨 Exhausted {{ .Type }}:\r\n"
"exhaustedCount" = "🚨 Exhausted {{ .Type }} count:\r\n"

View file

@ -430,9 +430,9 @@
"active" = "💡 Активен: ✅ Да\r\n"
"inactive" = "💡 Активен: ❌ Нет\r\n"
"email" = "📧 Email: {{ .Email }}\r\n"
"upload" = "🔼 Исходящий трафик: {{ .Upload }}\r\n"
"download" = "🔽 Входящий трафик: {{ .Download }}\r\n"
"total" = "🔄 Всего: {{ .UpDown }} / {{ .Total }}\r\n"
"upload" = "🔼 Исходящий трафик: {{ .Upload }}\r\n"
"download" = "🔽 Входящий трафик: {{ .Download }}\r\n"
"total" = "🔄 Всего: ↑↓{{ .UpDown }} из {{ .Total }}\r\n"
"TGUser" = "👤 Пользователь Telegram: {{ .TelegramID }}\r\n"
"exhaustedMsg" = "🚨 Исчерпаны {{ .Type }}:\r\n"
"exhaustedCount" = "🚨 Количество исчерпанных {{ .Type }}:\r\n"