Browse Source

[tgbot] - some fixes and improvments (#542)

somebodywashere 1 year ago
parent
commit
8442836512

+ 103 - 24
web/service/tgbot.go

@@ -697,14 +697,21 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
 		return
 	}
 
+	now := time.Now().Unix()
 	for _, traffic := range traffics {
 		expiryTime := ""
+		flag := false
+		diff := traffic.ExpiryTime/1000 - now
 		if traffic.ExpiryTime == 0 {
 			expiryTime = t.I18nBot("tgbot.unlimited")
+		} 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 = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+			expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
+			flag = true
 		}
 
 		total := ""
@@ -715,13 +722,22 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
 		}
 
 		output := ""
-		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 += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
 
 		t.SendMsgToTgbot(chatId, output)
 	}
@@ -819,13 +835,20 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
 		return
 	}
 
+	now := time.Now().Unix()
 	expiryTime := ""
+	flag := false
+	diff := traffic.ExpiryTime/1000 - now
 	if traffic.ExpiryTime == 0 {
-		expiryTime = t.I18nBot("tgbot.unlimited")
+	expiryTime = t.I18nBot("tgbot.unlimited")
+	} 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 = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+		expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
+		flag = true
 	}
 
 	total := ""
@@ -836,13 +859,22 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
 	}
 
 	output := ""
-	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 += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
 
 	inlineKeyboard := tu.InlineKeyboard(
 		tu.InlineKeyboardRow(
@@ -886,7 +918,8 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
 		t.SendMsgToTgbot(chatId, msg)
 		return
 	}
-
+	
+	now := time.Now().Unix()
 	for _, inbound := range inbouds {
 		info := ""
 		info += t.I18nBot("tgbot.messages.inbound", "Remark=="+inbound.Remark)
@@ -902,12 +935,18 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
 
 		for _, traffic := range inbound.ClientStats {
 			expiryTime := ""
+			flag := false
+			diff := traffic.ExpiryTime/1000 - now
 			if traffic.ExpiryTime == 0 {
 				expiryTime = t.I18nBot("tgbot.unlimited")
+			} 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 = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+				expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
+				flag = true
 			}
 
 			total := ""
@@ -918,13 +957,22 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
 			}
 
 			output := ""
-			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 += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
 
 			t.SendMsgToTgbot(chatId, output)
 		}
@@ -945,13 +993,20 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
 		return
 	}
 
+	now := time.Now().Unix()
 	expiryTime := ""
+	flag := false
+	diff := traffic.ExpiryTime/1000 - now
 	if traffic.ExpiryTime == 0 {
-		expiryTime = t.I18nBot("tgbot.unlimited")
+	expiryTime = t.I18nBot("tgbot.unlimited")
+	} 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 = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+		expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
+		flag = true
 	}
 
 	total := ""
@@ -962,13 +1017,22 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
 	}
 
 	output := ""
-	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 += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
 
 	t.SendMsgToTgbot(chatId, output)
 }
@@ -1052,12 +1116,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 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"))
+				expiryTime = fmt.Sprintf("%d %s", traffic.ExpiryTime/-86400000, t.I18nBot("tgbot.days"))
+				flag = true
 			} else {
-				expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+				expiryTime = fmt.Sprintf("%d %s", diff/3600, t.I18nBot("tgbot.hours"))
+				flag = true
 			}
 
 			total := ""
@@ -1067,13 +1137,22 @@ 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 += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
 			output += "\r\n \r\n"
 		}
 	}

+ 9 - 7
web/translation/translate.en_US.toml

@@ -384,6 +384,7 @@
 "months" = "Months"
 "day" = "Day"
 "days" = "Days"
+"hours" = "Hours"
 "unknown" = "Unknown"
 "inbounds" = "Inbounds"
 "clients" = "Clients"
@@ -424,20 +425,21 @@
 "time" = "⏰ Time: {{ .Time }}\r\n"
 "inbound" = "📍 Inbound: {{ .Remark }}\r\n"
 "port" = "🔌 Port: {{ .Port }}\r\n"
-"expire" = "📅 Expire Date: {{ .DateTime }}\r\n \r\n"
-"expireIn" = "📅 Expire In: {{ .Time }}\r\n \r\n"
-"active" = "💡 Active: {{ .Enable }}\r\n"
+"expire" = "📅 Expire Date: {{ .Time }}\r\n"
+"expireIn" = "📅 Expire In: {{ .Time }}\r\n"
+"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"
 "disabled" = "🛑 Disabled: {{ .Disabled }}\r\n"
 "depleteSoon" = "🔜 Deplete soon: {{ .Deplete }}\r\n \r\n"
 "backupTime" = "🗄 Backup Time: {{ .Time }}\r\n"
-"refreshedOn" = "🔄🕒 Refreshed On: {{ .Time }}\r\n"
+"refreshedOn" = "\r\n📋🔄 Refreshed On: {{ .Time }}\r\n \r\n"
 
 [tgbot.buttons]
 "closeKeyboard" = "❌ Close Keyboard"

+ 7 - 5
web/translation/translate.fa_IR.toml

@@ -384,6 +384,7 @@
 "months" = "ماه‌ها"
 "day" = "روز"
 "days" = "روزها"
+"hours" = "ساعت ها"
 "unknown" = "نامشخص"
 "inbounds" = "ورودی‌ها"
 "clients" = "کلاینت‌ها"
@@ -424,20 +425,21 @@
 "time" = "⏰ زمان: {{ .Time }}\r\n"
 "inbound" = "📍 ورودی: {{ .Remark }}\r\n"
 "port" = "🔌 پورت: {{ .Port }}\r\n"
-"expire" = "📅 تاریخ انقضا: {{ .DateTime }}\r\n \r\n"
-"expireIn" = "📅 باقیمانده از انقضا: {{ .Time }}\r\n \r\n"
-"active" = "💡 فعال: {{ .Enable }}\r\n"
+"expire" = "📅 تاریخ انقضا: {{ .Time }}\r\n"
+"expireIn" = "📅 باقیمانده از انقضا: {{ .Time }}\r\n"
+"active" = "💡 فعال: ✅\r\n"
+"inactive" = "💡 فعال: ❌\r\n"
 "email" = "📧 ایمیل: {{ .Email }}\r\n"
 "upload" = "🔼 آپلود↑: {{ .Upload }}\r\n"
 "download" = "🔽 دانلود↓: {{ .Download }}\r\n"
-"total" = "🔄 کل: {{ .UpDown }} / {{ .Total }}\r\n"
+"total" = "📊 کل: {{ .UpDown }} / {{ .Total }}\r\n"
 "TGUser" = "👤 کاربر تلگرام: {{ .TelegramID }}\r\n"
 "exhaustedMsg" = "🚨 {{ .Type }} به اتمام رسیده است:\r\n"
 "exhaustedCount" = "🚨 تعداد {{ .Type }} به اتمام رسیده:\r\n"
 "disabled" = "🛑 غیرفعال: {{ .Disabled }}\r\n"
 "depleteSoon" = "🔜 به زودی به پایان خواهد رسید: {{ .Deplete }}\r\n \r\n"
 "backupTime" = "🗄 زمان پشتیبان‌گیری: {{ .Time }}\r\n"
-"refreshedOn" = "🔄🕒 تازه‌سازی شده در: {{ .Time }}\r\n"
+"refreshedOn" = "\r\n📋🔄 تازه‌سازی شده در: {{ .Time }}\r\n \r\n"
 
 [tgbot.buttons]
 "closeKeyboard" = "❌ بستن کیبورد"

+ 9 - 7
web/translation/translate.ru_RU.toml

@@ -384,6 +384,7 @@
 "months" = "Месяцев"
 "day" = "День"
 "days" = "Дней"
+"hours" = "Часов"
 "unknown" = "Неизвестно"
 "inbounds" = "Входящие"
 "clients" = "Клиенты"
@@ -424,20 +425,21 @@
 "time" = "⏰ Время: {{ .Time }}\r\n"
 "inbound" = "📍 Входящий поток: {{ .Remark }}\r\n"
 "port" = "🔌 Порт: {{ .Port }}\r\n"
-"expire" = "📅 Дата окончания: {{ .DateTime }}\r\n \r\n"
-"expireIn" = "📅 Окончание через: {{ .Time }}\r\n \r\n"
-"active" = "💡 Активен: {{ .Enable }}\r\n"
+"expire" = "📅 Дата окончания: {{ .Time }}\r\n"
+"expireIn" = "📅 Окончание через: {{ .Time }}\r\n"
+"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"
 "disabled" = "🛑 Отключено: {{ .Disabled }}\r\n"
 "depleteSoon" = "🔜 Скоро исчерпание: {{ .Deplete }}\r\n \r\n"
 "backupTime" = "🗄 Время резервного копирования: {{ .Time }}\r\n"
-"refreshedOn" = "🔄🕒 Обновлено: {{ .Time }}\r\n"
+"refreshedOn" = "\r\n📋🔄 Обновлено: {{ .Time }}\r\n \r\n"
 
 [tgbot.buttons]
 "closeKeyboard" = "❌ Закрыть клавиатуру"

+ 7 - 5
web/translation/translate.zh_Hans.toml

@@ -384,6 +384,7 @@
 "months" = "月"
 "day" = "天"
 "days" = "天"
+"hours" = "小时"
 "unknown" = "未知"
 "inbounds" = "入站连接"
 "clients" = "客户端"
@@ -424,20 +425,21 @@
 "time" = "⏰ 时间:{{ .Time }}\r\n"
 "inbound" = "📍 入站:{{ .Remark }}\r\n"
 "port" = "🔌 端口:{{ .Port }}\r\n"
-"expire" = "📅 过期日期:{{ .DateTime }}\r\n \r\n"
-"expireIn" = "📅 剩余时间:{{ .Time }}\r\n \r\n"
-"active" = "💡 激活:{{ .Enable }}\r\n"
+"expire" = "📅 过期日期:{{ .Time }}\r\n"
+"expireIn" = "📅 剩余时间:{{ .Time }}\r\n"
+"active" = "💡 激活:✅\r\n"
+"inactive" = "💡 激活: ❌\r\n"
 "email" = "📧 邮箱:{{ .Email }}\r\n"
 "upload" = "🔼 上传↑:{{ .Upload }}\r\n"
 "download" = "🔽 下载↓:{{ .Download }}\r\n"
-"total" = "🔄 总计:{{ .UpDown }} / {{ .Total }}\r\n"
+"total" = "📊 总计:{{ .UpDown }} / {{ .Total }}\r\n"
 "TGUser" = "👤 电报用户:{{ .TelegramID }}\r\n"
 "exhaustedMsg" = "🚨 耗尽的{{ .Type }}:\r\n"
 "exhaustedCount" = "🚨 耗尽的{{ .Type }}数量:\r\n"
 "disabled" = "🛑 禁用:{{ .Disabled }}\r\n"
 "depleteSoon" = "🔜 即将耗尽:{{ .Deplete }}\r\n \r\n"
 "backupTime" = "🗄 备份时间:{{ .Time }}\r\n"
-"refreshedOn" = "🔄🕒 刷新时间:{{ .Time }}\r\n"
+"refreshedOn" = "\r\n📋🔄 刷新时间:{{ .Time }}\r\n \r\n"
 
 [tgbot.buttons]
 "closeKeyboard" = "❌ 关闭键盘"