TheHamkerCat пре 4 година
родитељ
комит
1d3ccbb59f
2 измењених фајлова са 21 додато и 5 уклоњено
  1. 8 2
      wbb/modules/admin.py
  2. 13 3
      wbb/utils/functions.py

+ 8 - 2
wbb/modules/admin.py

@@ -217,7 +217,8 @@ async def kickFunc(_, message: Message):
 )
 @adminsOnly("can_restrict_members")
 async def banFunc(_, message: Message):
-    user_id, reason = await extract_user_and_reason(message)
+    user_id, reason = await extract_user_and_reason(message, sender_chat=True)
+
     if not user_id:
         return await message.reply_text("I can't find that user.")
     if user_id == BOT_ID:
@@ -232,7 +233,12 @@ async def banFunc(_, message: Message):
         return await message.reply_text(
             "I can't ban an admin, You know the rules, so do i."
         )
-    mention = (await app.get_users(user_id)).mention
+
+    try:
+        mention = (await app.get_users(user_id)).mention
+    except IndexError:
+        mention = message.reply_to_message.sender_chat.title
+
     msg = (
         f"**Banned User:** {mention}\n"
         f"**Banned By:** {message.from_user.mention if message.from_user else 'Anon'}\n"

+ 13 - 3
wbb/utils/functions.py

@@ -206,7 +206,7 @@ async def extract_userid(message, text: str):
     return None
 
 
-async def extract_user_and_reason(message):
+async def extract_user_and_reason(message, sender_chat=False):
     args = message.text.strip().split()
     text = message.text
     user = None
@@ -215,12 +215,22 @@ async def extract_user_and_reason(message):
         reply = message.reply_to_message
         # if reply to a message and no reason is given
         if not reply.from_user:
-            return None, None
+            if (
+                reply.sender_chat
+                and reply.sender_chat != message.chat.id
+                and sender_chat
+            ):
+                id_ = reply.sender_chat.id
+            else:
+                return None, None
+        else:
+            id_ = reply.from_user.id
+
         if len(args) < 2:
             reason = None
         else:
             reason = text.split(None, 1)[1]
-        return reply.from_user.id, reason
+        return id_, reason
 
     # if not reply to a message and no reason is given
     if len(args) == 2: