Prechádzať zdrojové kódy

fix: change in function.py (#240)

* Update functions.py

* Newline at the EOF
SI_NN_ER_LS 2 rokov pred
rodič
commit
a2ee44d5c1
1 zmenil súbory, kde vykonal 33 pridanie a 27 odobranie
  1. 33 27
      wbb/utils/functions.py

+ 33 - 27
wbb/utils/functions.py

@@ -37,6 +37,7 @@ import speedtest
 from PIL import Image, ImageDraw, ImageFilter, ImageFont
 from pyrogram.enums import MessageEntityType
 from pyrogram.types import Message
+from pyrogram import errors
 
 from wbb import aiohttpsession as aiosession
 from wbb.utils.dbfunctions import start_restart_stage
@@ -213,38 +214,43 @@ async def extract_user_and_reason(message, sender_chat=False):
     text = message.text
     user = None
     reason = None
-    if message.reply_to_message:
-        reply = message.reply_to_message
-        # if reply to a message and no reason is given
-        if not reply.from_user:
-            if (
-                reply.sender_chat
-                and reply.sender_chat != message.chat.id
-                and sender_chat
-            ):
-                id_ = reply.sender_chat.id
+
+    try:
+        if message.reply_to_message:
+            reply = message.reply_to_message
+            # if reply to a message and no reason is given
+            if not reply.from_user:
+                if (
+                    reply.sender_chat
+                    and reply.sender_chat != message.chat.id
+                    and sender_chat
+                ):
+                    id_ = reply.sender_chat.id
+                else:
+                    return None, None
             else:
-                return None, None
-        else:
-            id_ = reply.from_user.id
+                id_ = reply.from_user.id
 
-        if len(args) < 2:
-            reason = None
-        else:
-            reason = text.split(None, 1)[1]
-        return id_, reason
+            if len(args) < 2:
+                reason = None
+            else:
+                reason = text.split(None, 1)[1]
+            return id_, reason
+
+        # if not reply to a message and no reason is given
+        if len(args) == 2:
+            user = text.split(None, 1)[1]
+            return await extract_userid(message, user), None
 
-    # if not reply to a message and no reason is given
-    if len(args) == 2:
-        user = text.split(None, 1)[1]
-        return await extract_userid(message, user), None
+        # if reason is given
+        if len(args) > 2:
+            user, reason = text.split(None, 2)[1:]
+            return await extract_userid(message, user), reason
 
-    # if reason is given
-    if len(args) > 2:
-        user, reason = text.split(None, 2)[1:]
-        return await extract_userid(message, user), reason
+        return user, reason
 
-    return user, reason
+    except errors.UsernameInvalid:
+        return "", ""
 
 
 async def extract_user(message):