瀏覽代碼

feat: List fedbans (#249)

SI_NN_ER_LS 2 年之前
父節點
當前提交
351e6c562e
共有 3 個文件被更改,包括 38 次插入 和 5 次删除
  1. 25 5
      wbb/modules/feds.py
  2. 2 0
      wbb/modules/filters.py
  3. 11 0
      wbb/utils/dbfeds.py

+ 25 - 5
wbb/modules/feds.py

@@ -210,7 +210,7 @@ async def myfeds(client, message):
     if is_feds:
         response_text = "\n\n".join(
             [
-                f"{i + 1}.\n**Fed Name:** {fed['fed_name']}\n**Fed Id:** `{fed['fed_id']}`"
+                f"{i + 1}) **Fed Name:** {fed['fed_name']}\n  **Fed Id:** `{fed['fed_id']}`"
                 for i, fed in enumerate(is_feds)
             ]
         )
@@ -847,7 +847,25 @@ __**New Federation UnBan**__
         )
 
 
+async def status(message, user_id):
+    status = await get_user_fstatus(user_id)
+    user = await app.get_users(user_id)
+    if status:
+        response_text = "\n\n".join(
+            [
+                f"{i + 1}) **Fed Name:** {fed['fed_name']}\n  **Fed Id:** `{fed['fed_id']}`"
+                for i, fed in enumerate(status)
+            ]
+        )
+        await message.reply_text(
+            f"**Here is the list of federations that {user.mention} were banned in:**\n\n{response_text}"
+        )
+    else:
+        return await message.reply_text(f"**{user.mention} is not banned in any federations.**")
+
+
 @app.on_message(filters.command("fedstat"))
+@capture_err
 async def fedstat(client, message):
     user = message.from_user
     if message.chat.type != ChatType.PRIVATE:
@@ -856,16 +874,16 @@ async def fedstat(client, message):
         )
 
     if len(message.command) < 2:
-        return await message.reply_text("Please provide me the user name and Fed Id!")
+        user_id = user.id
+        return await status(message, user_id)
 
     user_id, fed_id = await extract_user_and_reason(message)
     if not user_id:
         user_id = message.from_user.id
         fed_id = message.text.split(" ", 1)[1].strip()
     if not fed_id:
-        return await message.reply_text(
-            "provide me a Fed Id along with the command to search for."
-        )
+        return await status(message, user_id)
+
     info = await get_fed_info(fed_id)
     if not info:
         await message.reply_text("Please enter a valid fed id")
@@ -1023,6 +1041,8 @@ async def fed_owner_help(client, cb):
 • /fedadmins <FedID>: List the admins in a federation.
 • /joinfed <FedID>: Join the current chat to a federation. A chat can only join one federation. Chat owners only.
 • /leavefed: Leave the current federation. Only chat owners can do this.
+• /fedstat: List all the federations that you have been banned in.
+• /fedstat <user ID>: List all the federations that a user has been banned in.
 • /fedstat <FedID>: Gives information about your ban in a federation.
 • /fedstat <user ID> <FedID>: Gives information about a user's ban in a federation.
 • /chatfed: Information about the federation the current chat is in.

+ 2 - 0
wbb/modules/filters.py

@@ -175,6 +175,8 @@ async def del_filter(_, message):
 )
 @capture_err
 async def filters_re(_, message):
+    if not message.from_user:
+        return
     user_id = message.from_user.id
     chat_id = message.chat.id
     text = message.text.lower().strip()

+ 11 - 0
wbb/utils/dbfeds.py

@@ -186,3 +186,14 @@ async def check_banned_user(fed_id, user_id):
                 return {"reason": user.get("reason"), "date": user.get("date")}
 
     return False
+
+
+async def get_user_fstatus(user_id):
+    cursor = fedsdb.find({"banned_users.user_id": user_id})
+    feds = await cursor.to_list(length=None)
+    if not feds:
+        return False
+    federations = [
+        {"fed_id": fed["fed_id"], "fed_name": fed["fed_name"]} for fed in feds
+    ]
+    return federations