From 72c289df2ba5052311552c08f2a9bc41a37e803a Mon Sep 17 00:00:00 2001 From: somebodywashere <68244480+somebodywashere@users.noreply.github.com> Date: Tue, 30 May 2023 09:05:36 +0000 Subject: [PATCH] [tgbot] - some fixes and improvments --- web/service/tgbot.go | 96 +++++++++++++++++----------- web/translation/translate.en_US.toml | 6 +- web/translation/translate.ru_RU.toml | 6 +- 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/web/service/tgbot.go b/web/service/tgbot.go index b1fcdc2c..047df27e 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -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") + 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) - if (traffic.Enable&&flag) { - output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime) - } else { - output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime) - } 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") + 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) - if (traffic.Enable&&flag) { - output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime) - } else { - output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime) - } 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") + 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) - if (traffic.Enable&&flag) { - output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime) - } else { - output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime) - } 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") + 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) - if (traffic.Enable&&flag) { - output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime) - } else { - output += t.I18nBot("tgbot.messages.expire", "Time=="+expiryTime) - } 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" } } diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml index f6b4dea8..901533b6 100644 --- a/web/translation/translate.en_US.toml +++ b/web/translation/translate.en_US.toml @@ -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" diff --git a/web/translation/translate.ru_RU.toml b/web/translation/translate.ru_RU.toml index fff50f4c..29b27f46 100644 --- a/web/translation/translate.ru_RU.toml +++ b/web/translation/translate.ru_RU.toml @@ -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"