thehamkercat 5 vuotta sitten
vanhempi
sitoutus
3bddeeef31

+ 23 - 0
wbb/core/decorators/permissions.py

@@ -1,3 +1,26 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
 from functools import wraps
 
 from pyrogram.errors.exceptions.forbidden_403 import ChatWriteForbidden

+ 46 - 0
wbb/modules/chat_watcher.py

@@ -0,0 +1,46 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
+from pyrogram import filters
+
+from wbb import app
+from wbb.utils.filter_groups import chat_watcher_group
+from wbb.utils.dbfunctions import (blacklisted_chats, is_served_chat,
+        add_served_chat, is_served_user,
+        add_served_user)
+
+
+@app.on_message(group=chat_watcher_group)
+async def chat_watcher_func(_, message):
+    chat_id = message.chat.id
+    blacklisted_chats_list = await blacklisted_chats()
+    if chat_id in blacklisted_chats_list:
+        return await app.leave_chat(chat_id)
+    is_served = await is_served_chat(chat_id)
+    if not is_served:
+        await add_served_chat(chat_id)
+    if message.from_user:
+        user_id = message.from_user.id
+        is_served = await is_served_user(user_id)
+        if not is_served:
+            await add_served_user(user_id)

+ 2 - 12
wbb/modules/filters.py

@@ -28,9 +28,8 @@ from pyrogram import filters
 from wbb import app
 from wbb.core.decorators.errors import capture_err
 from wbb.core.decorators.permissions import adminsOnly
-from wbb.utils.dbfunctions import (add_served_chat, blacklisted_chats,
-                                   delete_filter, get_filter,
-                                   get_filters_names, is_served_chat,
+from wbb.utils.dbfunctions import (delete_filter, get_filter,
+                                   get_filters_names,
                                    save_filter)
 from wbb.utils.filter_groups import chat_filters_group
 
@@ -138,12 +137,3 @@ async def filters_re(_, message):
                     if text[0] == "~":
                         return await message.delete()
                 await message.reply_sticker(data)
-
-    """ CHAT WATCHER """
-    blacklisted_chats_list = await blacklisted_chats()
-    if chat_id in blacklisted_chats_list:
-        return await app.leave_chat(chat_id)
-    served_chat = await is_served_chat(chat_id)
-    if served_chat:
-        return
-    await add_served_chat(chat_id)

+ 3 - 12
wbb/modules/global_stats.py

@@ -32,7 +32,7 @@ from wbb.utils.dbfunctions import (get_blacklist_filters_count,
                                    get_filters_count, get_gbans_count,
                                    get_karmas_count, get_notes_count,
                                    get_served_chats, get_warns_count,
-                                   remove_served_chat)
+                                   remove_served_chat, get_served_users)
 from wbb.utils.fetch import fetch
 from wbb.utils.inlinefuncs import keywords_list
 
@@ -52,7 +52,6 @@ async def global_stats(_, message):
 
     # For bot served chat and users count
     served_chats = []
-    total_users = 0
     chats = await get_served_chats()
     for chat in chats:
         served_chats.append(int(chat["chat_id"]))
@@ -68,15 +67,7 @@ async def global_stats(_, message):
             await remove_served_chat(served_chat)
             served_chats.remove(served_chat)
             pass
-    for i in served_chats:
-        try:
-            mc = (await app.get_chat(i)).members_count
-            total_users += int(mc)
-        except Exception:
-            await remove_served_chat(served_chat)
-            pass
-        await asyncio.sleep(2)
-
+    served_users = await get_served_users()
     # Gbans count
     gbans = await get_gbans_count()
     _notes = await get_notes_count()
@@ -124,7 +115,7 @@ async def global_stats(_, message):
 **{notes_count}** Notes, Across **{notes_chats_count}** chats.
 **{warns_count}** Warns, Across **{warns_chats_count}** chats.
 **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
-**{total_users}** Users, Across **{len(served_chats)}** chats.
+**{len(served_users)}** Users, Across **{len(served_chats)}** chats.
 **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
 """
     await m.edit(msg, disable_web_page_preview=True)

+ 23 - 0
wbb/modules/info.py

@@ -1,3 +1,26 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
 import os
 
 from pyrogram import filters

+ 23 - 0
wbb/modules/quotly.py

@@ -1,3 +1,26 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
 from io import BytesIO
 from traceback import format_exc
 

+ 23 - 0
wbb/modules/taglogger.py

@@ -1,3 +1,26 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
 from pykeyboard import InlineKeyboard
 from pyrogram import filters
 from pyrogram.types import InlineKeyboardButton, Message

+ 23 - 0
wbb/modules/ytdl.py

@@ -1,3 +1,26 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
 import traceback
 from asyncio import gather
 from os import remove

+ 25 - 0
wbb/utils/dbfunctions.py

@@ -31,6 +31,7 @@ filtersdb = db.filters
 warnsdb = db.warns
 karmadb = db.karma
 chatsdb = db.chats
+usersdb = db.users
 gbansdb = db.gban
 coupledb = db.couple
 captchadb = db.captcha
@@ -346,6 +347,30 @@ async def remove_served_chat(chat_id: int):
     return await chatsdb.delete_one({"chat_id": chat_id})
 
 
+""" USER LOG FUNCTIONS """
+
+async def is_served_user(user_id: int) -> bool:
+    user = await usersdb.find_one({"user_id": user_id})
+    if not user:
+        return False
+    return True
+
+async def get_served_users() -> list:
+    users = usersdb.find({"user_id": {"$gt": 0}})
+    if not users:
+        return []
+    users_list = []
+    for user in await users.to_list(length=1000000000):
+        users_list.append(user)
+    return users_list
+
+async def add_served_user(user_id: int):
+    is_served = await is_served_user(user_id)
+    if is_served:
+        return
+    return await usersdb.insert_one({"user_id": user_id})
+
+
 """ Gban functions """
 
 

+ 1 - 0
wbb/utils/filter_groups.py

@@ -32,3 +32,4 @@ nsfw_detect_group = 8
 blacklist_filters_group = 9
 pipes_group = 10
 taglog_group = 11
+chat_watcher_group = 12