TheHamkerCat 5 лет назад
Родитель
Сommit
85945065ab

+ 1 - 0
sample_config.py

@@ -3,6 +3,7 @@ API_ID = 69
 API_HASH = "e46b6c854d2bf580"
 API_HASH = "e46b6c854d2bf580"
 OWNER_ID = 1243703097
 OWNER_ID = 1243703097
 MAIN_CHATS = [-1001485393652]  # NOTE These are the chats where main functions of bot will work, like music downloading etc.
 MAIN_CHATS = [-1001485393652]  # NOTE These are the chats where main functions of bot will work, like music downloading etc.
+SUDO_USER_ID = [51635132416, 1342121354245, 23452465243]
 SUDO_CHAT_ID = [354165569, 564426514, 686215463]
 SUDO_CHAT_ID = [354165569, 564426514, 686215463]
 LOG_GROUP_ID = -1001337393587
 LOG_GROUP_ID = -1001337393587
 FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM="
 FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM="

+ 2 - 1
wbb/__init__.py

@@ -1,7 +1,8 @@
 from config import (
 from config import (
     BOT_TOKEN, API_ID ,API_HASH, OWNER_ID, SUDO_USER_ID,
     BOT_TOKEN, API_ID ,API_HASH, OWNER_ID, SUDO_USER_ID,
     LOG_GROUP_ID, FERNET_ENCRYPTION_KEY, MONGO_DB_URI,
     LOG_GROUP_ID, FERNET_ENCRYPTION_KEY, MONGO_DB_URI,
-    WELCOME_DELAY_KICK_SEC, ARQ_API_BASE_URL as ARQ_API
+    WELCOME_DELAY_KICK_SEC, ARQ_API_BASE_URL as ARQ_API,
+    SUDO_CHAT_ID
     )
     )
 from pyrogram import Client
 from pyrogram import Client
 from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
 from motor.motor_asyncio import AsyncIOMotorClient as MongoClient

+ 0 - 8
wbb/modules/__main__.py

@@ -1,8 +0,0 @@
-# Group for filters
-# group=1 = Check flood
-# group=2 = Filter
-# group=3 = locks
-# group=4 = Blacklist
-# group=5 = Blacklist sticker
-# group=6 = AFK & reply AFK
-# group=10 = logging users

+ 2 - 1
wbb/modules/chatbot.py

@@ -2,6 +2,7 @@ from wbb import app, arq
 from wbb.utils.fetch import fetch
 from wbb.utils.fetch import fetch
 from wbb.utils.errors import capture_err
 from wbb.utils.errors import capture_err
 from wbb.utils.botinfo import BOT_ID
 from wbb.utils.botinfo import BOT_ID
+from wbb.utils.filter_groups import chatbot_group
 from pyrogram import filters
 from pyrogram import filters
 
 
 
 
@@ -48,7 +49,7 @@ async def chatbot_status(_, message):
 
 
 
 
 @app.on_message(filters.text & filters.reply & ~filters.bot &
 @app.on_message(filters.text & filters.reply & ~filters.bot &
-        ~filters.via_bot & ~filters.forwarded, group=2)
+        ~filters.via_bot & ~filters.forwarded, group=chatbot_group)
 @capture_err
 @capture_err
 async def chatbot_talk(_, message):
 async def chatbot_talk(_, message):
     if message.chat.id not in active_chats:
     if message.chat.id not in active_chats:

+ 2 - 2
wbb/modules/filters.py

@@ -7,7 +7,7 @@ from wbb.utils.dbfunctions import (
         )
         )
 from pyrogram import filters
 from pyrogram import filters
 from wbb.utils.errors import capture_err
 from wbb.utils.errors import capture_err
-
+from wbb.utils.filter_groups import chat_filters_group
 
 
 __MODULE__ = "Filters"
 __MODULE__ = "Filters"
 __HELP__ = """/filters To Get All The Filters In The Chat.
 __HELP__ = """/filters To Get All The Filters In The Chat.
@@ -77,7 +77,7 @@ async def del_filter(_, message):
 
 
 @app.on_message(filters.text & ~filters.edited &
 @app.on_message(filters.text & ~filters.edited &
                 ~filters.private & ~filters.via_bot &
                 ~filters.private & ~filters.via_bot &
-                ~filters.forwarded, group=1)
+                ~filters.forwarded, group=chat_filters_group)
 async def filters_re(_, message):
 async def filters_re(_, message):
     try:
     try:
         if message.text[0] != "/":
         if message.text[0] != "/":

+ 55 - 0
wbb/modules/global_stats.py

@@ -0,0 +1,55 @@
+from wbb import app
+from wbb.utils.filter_groups import global_stats_group
+from wbb.utils.errors import capture_err
+from wbb.utils.botinfo import BOT_ID, BOT_NAME
+from wbb.utils.dbfunctions import (
+        is_served_chat,
+        get_served_chats,
+        add_served_chat,
+        remove_served_chat,
+        alpha_to_int
+        )
+from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
+
+
+@app.on_message(filters.new_chat_members & filters.left_chat_member)
+@capture_err
+async def chat_watcher(_, message):
+    chat_id = message.chat.id
+    served_chat = await is_served_chat(chat_id)
+    if served_chat:
+        return
+    await add_served_chat(chat_id)
+
+
+@app.on_message(filters.command("/global_stats") & ~filters.edited)
+@capture_err
+async def global_stats(_, message):
+    m = await message.reply_text("__**Analysing Stats, Might Take 10-30 Seconds.**__")
+    served_chats = []
+    total_users = 0
+    chats = await get_served_chats 
+    for chat in chats:
+        served_chats.append(await alpha_to_int(chat))
+    for served_chat in served_chats:
+        try:
+            await app.get_chat_member(served_chat, BOT_ID)
+        except UserNotParticipant:
+            await remove_served_chat(served_chat)
+            served_chats.remove(served_chat)
+            pass
+    for i in served_chats:
+        total_users += int((await app.get_chat(i)).members_count)
+    msg = f"""**Global Stats of {BOT_NAME}**:
+0 gbanned users.
+0 blacklist triggers, across 0 chats.
+0 filters, across 0 chats.
+0 notes, across 0 chats.
+0 welcome messages are set.
+{total_users} users, across {len(served_chats)} chats.
+0 warns, across 0 chats.
+0 """
+    await m.edit(msg)
+
+
+

+ 5 - 2
wbb/modules/karma.py

@@ -4,6 +4,7 @@ from wbb.utils.errors import capture_err
 from wbb.utils.json_prettify import json_prettify
 from wbb.utils.json_prettify import json_prettify
 from wbb.utils.dbfunctions import (update_karma, get_karma, get_karmas,
 from wbb.utils.dbfunctions import (update_karma, get_karma, get_karmas,
     int_to_alpha, alpha_to_int)
     int_to_alpha, alpha_to_int)
+from wbb.utils.filter_groups import karma_positive_group, karma_negative_group
 from pyrogram import filters
 from pyrogram import filters
 
 
 __MODULE__ = "Karma"
 __MODULE__ = "Karma"
@@ -24,7 +25,8 @@ regex_downvote = r"^(\-|\-\-|\-1|👎)$"
                 & filters.regex(regex_upvote)
                 & filters.regex(regex_upvote)
                 & ~filters.via_bot
                 & ~filters.via_bot
                 & ~filters.bot
                 & ~filters.bot
-                & ~filters.edited, group=3)
+                & ~filters.edited,
+                group=karma_positive_group)
 async def upvote(_, message):
 async def upvote(_, message):
     if message.reply_to_message.from_user.id == message.from_user.id:
     if message.reply_to_message.from_user.id == message.from_user.id:
         return
         return
@@ -53,7 +55,8 @@ async def upvote(_, message):
                 & filters.regex(regex_downvote)
                 & filters.regex(regex_downvote)
                 & ~filters.via_bot
                 & ~filters.via_bot
                 & ~filters.bot
                 & ~filters.bot
-                & ~filters.edited, group=4)
+                & ~filters.edited,
+                group=karma_negative_group)
 async def downvote(_, message):
 async def downvote(_, message):
     if message.reply_to_message.from_user.id == message.from_user.id:
     if message.reply_to_message.from_user.id == message.from_user.id:
         return
         return

+ 2 - 1
wbb/modules/regex.py

@@ -1,6 +1,7 @@
 import re
 import re
 import sre_constants
 import sre_constants
 from wbb import app
 from wbb import app
+from wbb.utils.filter_groups import regex_group
 from pyrogram import filters
 from pyrogram import filters
 
 
 
 
@@ -11,7 +12,7 @@ __HELP__ = "**Usage:**\ns/foo/bar"
 DELIMITERS = ("/", ":", "|", "_")
 DELIMITERS = ("/", ":", "|", "_")
 
 
 
 
-@app.on_message(filters.regex(r"s([{}]).*?\1.*".format("".join(DELIMITERS))), group=7)
+@app.on_message(filters.regex(r"s([{}]).*?\1.*".format("".join(DELIMITERS))), group=regex_group)
 async def sed(_, message):
 async def sed(_, message):
     sed_result = separate_sed(message.text)
     sed_result = separate_sed(message.text)
     if message.reply_to_message:
     if message.reply_to_message:

+ 52 - 2
wbb/utils/dbfunctions.py

@@ -6,6 +6,9 @@ notesdb = db.notes
 filtersdb = db.filters
 filtersdb = db.filters
 warnsdb = db.warns
 warnsdb = db.warns
 karmadb = db.karma
 karmadb = db.karma
+usersdb = db.users
+chatsdb = db.chats
+
 
 
 """ Notes functions """
 """ Notes functions """
 
 
@@ -101,7 +104,6 @@ async def save_filter(chat_id: int, name: str, _filter: dict):
     name = name.lower().strip()
     name = name.lower().strip()
     _filters = await _get_filters(chat_id)
     _filters = await _get_filters(chat_id)
     _filters[name] = _filter
     _filters[name] = _filter
-
     await filtersdb.update_one(
     await filtersdb.update_one(
         {"chat_id": chat_id},
         {"chat_id": chat_id},
         {
         {
@@ -131,7 +133,9 @@ async def delete_filter(chat_id: int, name: str) -> bool:
     return False
     return False
 
 
 
 
-""" Warn function """
+""" Warn functions """
+
+
 async def int_to_alpha(user_id: int) -> str:
 async def int_to_alpha(user_id: int) -> str:
     alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
     alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
     text = ""
     text = ""
@@ -233,3 +237,49 @@ async def update_karma(chat_id: int, name: str, karma: dict):
         },
         },
         upsert=True
         upsert=True
     )
     )
+
+
+""" Chats log functions """
+
+async def is_served_chat(chat_id: int) -> bool:
+    chats = await chatsdb.find_one({"chats": "chats"})
+    chats = chats['chats']
+    for chat in chats:
+        if chat == await int_to_alpha(chat_id): return True
+
+
+async def get_served_chats():
+    chats = await chatsdb.find_one({"chats": "chats"})
+    chats = chats['chats']
+    return chats
+
+
+async def add_served_chat(chat_id: int):
+    is_served = await is_served_chat(chat_id)
+    if is_served: return
+    chats = await get_served_chats()
+    chats[await int_to_alpha(chat_id)] = {"chat_id": chat_id}
+    await chatsdb.update_one(
+            {"chats": "chats"},
+            {
+                "$set": {
+                    "chats": chats
+                }
+            },
+            upsert=True
+            )
+
+async def remove_served_chat(chat_id: int):
+    is_served = await is_served_chat(chat_id)
+    if not is_served: return
+    chats = await get_served_chats()
+    del chats[await int_to_alpha(chat_id)]
+    await chatsdb.update_one(
+            {"chats": "chats"},
+            {
+                "$set": {
+                    "chats": chats
+                }
+            },
+            upsert=True
+            )

+ 5 - 0
wbb/utils/filter_groups.py

@@ -0,0 +1,5 @@
+chat_filters_group = 1
+chatbot_group = 2
+karma_positive_group = 3
+karma_negative_group = 4
+regex_group = 5