浏览代码

Fix: Chat info error (#253)

SI_NN_ER_LS 2 年之前
父节点
当前提交
d6c6f494e7
共有 5 个文件被更改,包括 56 次插入 和 38 次删除
  1. 10 5
      wbb/core/sections.py
  2. 3 5
      wbb/modules/autoapprove.py
  3. 40 27
      wbb/modules/feds.py
  4. 1 1
      wbb/modules/filters.py
  5. 2 0
      wbb/modules/sudoers.py

+ 10 - 5
wbb/core/sections.py

@@ -40,9 +40,14 @@ def section(
     text = (bold_ul(title) + n) if underline else bold(title) + n
 
     for key, value in body.items():
-        text += (
-            indent * w
-            + bold(key)
-            + ((value[0] + n) if isinstance(value, list) else mono(value))
-        )
+        if value is not None:
+            text += (
+                indent * w
+                + bold(key)
+                + (
+                    (value[0] + n)
+                    if isinstance(value, list) and isinstance(value[0], str)
+                    else mono(value)
+                )
+            )
     return text

+ 3 - 5
wbb/modules/autoapprove.py

@@ -206,14 +206,12 @@ async def manual(app, cb):
                 f"You don't have the required permission.\n Permission: {permission}",
                 show_alert=True,
             )
-    datas = cb.data.split("_", 1)[1]
-    data = datas.split("_", 1)
-    dis = data[0]
-    id = data[1]
+    datas = cb.data.split("_", 2)
+    dis = datas[1]
+    id = datas[2]
     if dis == "approve":
         await app.approve_chat_join_request(chat_id=chat.id, user_id=id)
         # No need to verify user as admin is the one who accept the request
-        await send_welcome_message(chat, id, True)
     if dis == "decline":
         await app.decline_chat_join_request(chat_id=chat.id, user_id=id)
     await approvaldb.update_one(

+ 40 - 27
wbb/modules/feds.py

@@ -27,7 +27,7 @@ import uuid
 
 from pyrogram import filters
 from pyrogram.enums import ChatMemberStatus, ChatType, ParseMode
-from pyrogram.errors import FloodWait, PeerIdInvalid
+from pyrogram.errors import FloodWait, PeerIdInvalid, ChatAdminRequired
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
 
 from wbb import BOT_ID, LOG_GROUP_ID, SUDOERS, app
@@ -256,41 +256,54 @@ async def fed_log(client, message):
     chat = message.chat
     user = message.from_user
     if message.chat.type == ChatType.PRIVATE:
-        return await message.reply_text(
-            "Send this command on the chat which you need to set as fed log channel."
-        )
+        if len(message.command) < 3:
+            return await message.reply_text(
+                f"Usage:\n\n /{message.command[0]} [channel_id] [fed_id]."
+            )
+        ids = message.text.split(" ", 2)
+        chat_id = ids[1]
+        fed_id = ids[2]
 
-    member = await app.get_chat_member(chat.id, user.id)
-    if (
-        member.status == ChatMemberStatus.OWNER
-        or member.status == ChatMemberStatus.ADMINISTRATOR
-    ):
+    else:
+        chat_id = chat.id 
         if len(message.command) < 2:
             return await message.reply_text(
                 "Please provide the Id of the federation with the command!"
             )
         fed_id = message.text.split(" ", 1)[1].strip()
-        info = await get_fed_info(fed_id)
-        if info is False:
-            return await message.reply_text("This federation does not exist.")
 
-        if await is_user_fed_owner(fed_id, user.id):
-            if "/unsetfedlog" in message.text:
-                log_group_id = LOG_GROUP_ID
-            else:
-                log_group_id = chat.id
-            loged = await set_log_chat(fed_id, log_group_id)
-            if "/unsetfedlog" in message.text:
-                return await message.reply_text(
-                    "log channel removed successfully."
-                )
-            else:
-                await message.reply_text("log channel set successfully.")
-    else:
-        await message.reply_text(
-            "You need to be the chat owner or admin to use this command."
+    try:
+        chat_member = await app.get_chat_member(chat_id, user.id)
+        
+    except ChatAdminRequired:
+        return await message.reply_text("I need to be an admin in the channel")
+        
+    except Exception as e:
+        print(e)
+        return
+        
+    if not chat_member.status in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
+        return await message.reply_text(
+            "You need to be the channel owner or admin to use this command"
         )
 
+    info = await get_fed_info(fed_id)
+    if info is False:
+        return await message.reply_text("This federation does not exist.")
+
+    if await is_user_fed_owner(fed_id, user.id):
+        if "/unsetfedlog" in message.text:
+            log_group_id = LOG_GROUP_ID
+        else:
+            log_group_id = chat_id
+        loged = await set_log_chat(fed_id, log_group_id)
+        if "/unsetfedlog" in message.text:
+            return await message.reply_text(
+                "log channel removed successfully."
+            )
+        else:
+            await message.reply_text("log channel set successfully.")
+
 
 @app.on_message(filters.command("chatfed"))
 @capture_err

+ 1 - 1
wbb/modules/filters.py

@@ -170,7 +170,7 @@ async def del_filter(_, message):
 
 
 @app.on_message(
-    filters.text & ~filters.private & ~filters.via_bot & ~filters.forwarded,
+    filters.text & ~filters.private & ~filters.channel & ~filters.via_bot & ~filters.forwarded,
     group=chat_filters_group,
 )
 @capture_err

+ 2 - 0
wbb/modules/sudoers.py

@@ -67,6 +67,8 @@ __HELP__ = """
 
 /update - To Update And Restart The Bot
 
+/restart - To Restart the bot
+
 /eval - Execute Python Code
 
 /sh - Execute Shell Code