Browse Source

Fix ability to use userId in tgId

Masoud Hidden 1 year ago
parent
commit
7f8f0b0f2d
1 changed files with 13 additions and 11 deletions
  1. 13 11
      web/service/tgbot.go

+ 13 - 11
web/service/tgbot.go

@@ -330,7 +330,7 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
 	case "get_backup":
 		t.sendBackup(callbackQuery.From.ID)
 	case "client_traffic":
-		t.getClientUsage(callbackQuery.From.ID, callbackQuery.From.UserName, "#"+strconv.FormatInt(callbackQuery.From.ID, 10))
+		t.getClientUsage(callbackQuery.From.ID, callbackQuery.From.UserName, strconv.FormatInt(callbackQuery.From.ID, 10))
 	case "client_commands":
 		t.SendMsgToTgbot(callbackQuery.From.ID, "To search for statistics, just use folowing command:\r\n \r\n<code>/usage [UID|Password]</code>\r\n \r\nUse UID for vmess/vless and Password for Trojan.")
 	case "commands":
@@ -531,16 +531,21 @@ func (t *Tgbot) getInboundUsages() string {
 }
 
 func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string) {
-	if len(tgUserName) == 0 && len(tgUserID) == 0 {
-		msg := "Your configuration is not found!\nYou should configure your telegram username and ask Admin to add it to your configuration."
+	traffics, err := t.inboundService.GetClientTrafficTgBot(tgUserID)
+	if err != nil {
+		logger.Warning(err)
+		msg := "❌ Something went wrong!"
 		t.SendMsgToTgbot(chatId, msg)
 		return
 	}
-	userIdentifier := tgUserName
-	if len(userIdentifier) == 0 {
-		userIdentifier = tgUserID
+	if len(traffics) == 0 {
+		if len(tgUserName) == 0 {
+			msg := "Your configuration is not found!\nPlease ask your Admin to use your telegram user id in your configuration(s).\n\nYour user id: <b>" + tgUserID + "</b>"
+			t.SendMsgToTgbot(chatId, msg)
+			return
+		}
+		traffics, err = t.inboundService.GetClientTrafficTgBot(tgUserName)
 	}
-	traffics, err := t.inboundService.GetClientTrafficTgBot(userIdentifier)
 	if err != nil {
 		logger.Warning(err)
 		msg := "❌ Something went wrong!"
@@ -548,10 +553,7 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
 		return
 	}
 	if len(traffics) == 0 {
-		if len(tgUserName) > 0 {
-			userIdentifier = "@" + tgUserName
-		}
-		msg := "Your configuration is not found!\nPlease ask your Admin to use your telegram username in your configuration(s).\n\nYour username: <b>" + userIdentifier + "</b>"
+		msg := "Your configuration is not found!\nPlease ask your Admin to use your telegram username or user id in your configuration(s).\n\nYour username: <b>@" + tgUserName + "</b>\n\nYour user id: <b>" + tgUserID + "</b>"
 		t.SendMsgToTgbot(chatId, msg)
 		return
 	}