Bläddra i källkod

Fixed chat blacklist

I don't even know what was the problem, anyways, this fixed it.
Co-authored-by: Roj Serbest <49933115+rojserbest@users.noreply.github.com>
TheHamkerCat 5 år sedan
förälder
incheckning
29a0c0604e
2 ändrade filer med 15 tillägg och 21 borttagningar
  1. 2 2
      wbb/modules/blacklist_chat.py
  2. 13 19
      wbb/utils/dbfunctions.py

+ 2 - 2
wbb/modules/blacklist_chat.py

@@ -54,7 +54,7 @@ async def whitelist_chat_func(_, message: Message):
 @app.on_message(filters.command("blacklisted_chats") & filters.user(SUDOERS))
 async def blacklisted_chats_func(_, message: Message):
     text = ""
-    for count, chat_id in enumerate(await blacklisted_chats()):
+    for count, chat_id in enumerate(await blacklisted_chats(), 1):
         title = (await app.get_chat(chat_id)).title
-        text += f"**{count}. {title}** [`chat_id`]\n"
+        text += f"**{count}. {title}** [`{chat_id}`]\n"
     await message.reply_text(text)

+ 13 - 19
wbb/utils/dbfunctions.py

@@ -39,10 +39,10 @@ pmpermitdb = db.pmpermit
 welcomedb = db.welcome_text
 nsfwdb = db.nsfw
 captcha_cachedb = db.captcha_cache
-blacklist_filtersdb = db.blacklist_filters
+blacklist_filtersdb = db.blacklistFilters
 pipesdb = db.pipes
 sudoersdb = db.sudoers
-blacklist_chatdb = db.blacklist_chat
+blacklist_chatdb = db.blacklistChat
 
 """ Notes functions """
 
@@ -642,29 +642,23 @@ async def remove_sudo(user_id: int) -> bool:
     return True
 
 
-""" BLACKLIST CHATS FUNCTIONS """
+""" BLACKLISTED CHATS """
 
 
 async def blacklisted_chats() -> list:
-    chats = await blacklist_chatdb.find_one({"chat": "chat"})
-    if not chats:
-        return []
-    return chats["chats"]
+    chats = blacklist_chatdb.find({"chat_id": {"$lt": 0}})
+    return [chat["chat_id"] for chat in await chats.to_list(length=1000000000)]
 
 
 async def blacklist_chat(chat_id: int) -> bool:
-    chats = await blacklisted_chats()
-    chats.append(chats)
-    await blacklist_chatdb.update_one(
-        {"chat": "chat"}, {"$set": {"chats": chats}}, upsert=True
-    )
-    return True
+    if not await blacklist_chatdb.find_one({"chat_id": chat_id}):
+        await blacklist_chatdb.insert_one({"chat_id": chat_id})
+        return True
+    return False
 
 
 async def whitelist_chat(chat_id: int) -> bool:
-    chats = await blacklisted_chats()
-    chats.remove(chats)
-    await blacklist_chatdb.update_one(
-        {"chat": "chat"}, {"$set": {"chats": chats}}, upsert=True
-    )
-    return True
+    if await blacklist_chatdb.find_one({"chat_id": chat_id}):
+        await blacklist_chatdb.delete_one({"chat_id": chat_id})
+        return True
+    return False