浏览代码

Improve argument validation in Telegram bot commands - Update checks for command arguments to ensure proper handling of empty inputs, enhancing user feedback for commands like /long, /short, /exit, /coo, /sl, and /tp.

Carles Sentis 6 天之前
父节点
当前提交
54b5e220e1
共有 1 个文件被更改,包括 7 次插入7 次删除
  1. 7 7
      src/telegram_bot.py

+ 7 - 7
src/telegram_bot.py

@@ -394,7 +394,7 @@ For support, contact your bot administrator.
         
         # Check if token filter is provided
         token_filter = None
-        if len(context.args) >= 1:
+        if context.args and len(context.args) >= 1:
             token_filter = context.args[0].upper()
         
         orders = self.client.get_open_orders()
@@ -1049,7 +1049,7 @@ For support, contact your bot administrator.
             return
         
         try:
-            if len(context.args) < 2:
+            if not context.args or len(context.args) < 2:
                 await update.message.reply_text(
                     "❌ Usage: /long [token] [USDC amount] [price (optional)]\n"
                     "Examples:\n"
@@ -1136,7 +1136,7 @@ For support, contact your bot administrator.
             return
         
         try:
-            if len(context.args) < 2:
+            if not context.args or len(context.args) < 2:
                 await update.message.reply_text(
                     "❌ Usage: /short [token] [USDC amount] [price (optional)]\n"
                     "Examples:\n"
@@ -1223,7 +1223,7 @@ For support, contact your bot administrator.
             return
         
         try:
-            if len(context.args) < 1:
+            if not context.args or len(context.args) < 1:
                 await update.message.reply_text(
                     "❌ Usage: /exit [token]\n"
                     "Example: /exit BTC"
@@ -1327,7 +1327,7 @@ This will place a market {exit_side} order to close your entire {token} position
             return
         
         try:
-            if len(context.args) < 1:
+            if not context.args or len(context.args) < 1:
                 await update.message.reply_text(
                     "❌ Usage: /coo [token]\n"
                     "Example: /coo BTC\n\n"
@@ -1402,7 +1402,7 @@ This action cannot be undone.
             return
         
         try:
-            if len(context.args) < 2:
+            if not context.args or len(context.args) < 2:
                 await update.message.reply_text(
                     "❌ Usage: /sl [token] [price]\n"
                     "Example: /sl BTC 44000\n\n"
@@ -1529,7 +1529,7 @@ This will place a limit {exit_side} order at ${stop_price:,.2f} to protect your
             return
         
         try:
-            if len(context.args) < 2:
+            if not context.args or len(context.args) < 2:
                 await update.message.reply_text(
                     "❌ Usage: /tp [token] [price]\n"
                     "Example: /tp BTC 50000\n\n"