From 56ff298b838de6cd1025d86fade414e5444d0a15 Mon Sep 17 00:00:00 2001 From: Captain Ezio Date: Mon, 21 Oct 2024 19:32:39 +0530 Subject: [PATCH] almost done --- Powers/__init__.py | 20 +-- Powers/bot_class.py | 1 + Powers/database/antispam_db.py | 3 +- Powers/database/approve_db.py | 2 - Powers/database/blacklist_db.py | 2 - Powers/database/chats_db.py | 1 - Powers/database/disable_db.py | 2 - Powers/database/filters_db.py | 10 +- Powers/database/greetings_db.py | 2 - Powers/database/locks_db.py | 52 +++--- Powers/database/pins_db.py | 1 - Powers/database/reporting_db.py | 2 - Powers/database/rules_db.py | 2 - Powers/database/users_db.py | 1 - Powers/database/warns_db.py | 4 - Powers/plugins/admin.py | 29 ++-- Powers/plugins/antispam.py | 17 +- Powers/plugins/approve.py | 6 - Powers/plugins/auto_join.py | 5 +- Powers/plugins/bans.py | 66 ++------ Powers/plugins/birthday.py | 16 +- Powers/plugins/blacklist.py | 9 - Powers/plugins/captcha.py | 5 +- Powers/plugins/chat_blacklist.py | 3 - Powers/plugins/clean_db.py | 1 - Powers/plugins/dev.py | 29 +++- Powers/plugins/disable.py | 7 - Powers/plugins/filters.py | 11 +- Powers/plugins/flood.py | 12 +- Powers/plugins/formatting.py | 1 - Powers/plugins/fun.py | 20 +-- Powers/plugins/greetings.py | 26 +-- Powers/plugins/info.py | 21 ++- Powers/plugins/locks.py | 55 +++---- Powers/plugins/muting.py | 44 ++--- Powers/plugins/notes.py | 18 +- Powers/plugins/pin.py | 14 +- Powers/plugins/report.py | 16 +- Powers/plugins/rules.py | 9 +- Powers/plugins/scheduled_jobs.py | 3 - Powers/plugins/start.py | 15 +- Powers/plugins/stats.py | 7 +- Powers/plugins/stickers.py | 55 ++----- Powers/plugins/utils.py | 10 +- Powers/plugins/warns.py | 24 +-- Powers/plugins/watchers.py | 24 +-- Powers/plugins/web_con.py | 45 +++-- Powers/supports.py | 14 +- Powers/utils/admin_check.py | 13 +- Powers/utils/caching.py | 3 - Powers/utils/custom_filters.py | 14 +- Powers/utils/extract_user.py | 2 +- Powers/utils/start_utils.py | 7 +- Powers/utils/sticker_help.py | 59 ++----- Powers/utils/web_scrapper.py | 273 +++++++++++++++++-------------- Powers/vars.py | 8 +- app.json | 10 -- requirements.txt | 10 +- 58 files changed, 443 insertions(+), 698 deletions(-) diff --git a/Powers/__init__.py b/Powers/__init__.py index bb348d48..9150bb5d 100644 --- a/Powers/__init__.py +++ b/Powers/__init__.py @@ -123,23 +123,11 @@ SUPPORT_GROUP = Config.SUPPORT_GROUP SUPPORT_CHANNEL = Config.SUPPORT_CHANNEL -# Users Config +# Users Config OWNER_ID = Config.OWNER_ID -DEV = Config.DEV_USERS -DEVS_USER = set(DEV) -SUDO_USERS = Config.SUDO_USERS -WHITELIST_USERS = Config.WHITELIST_USERS - - -defult_dev = [1344569458, 1432756163, 5294360309] + [int(OWNER_ID)] - -Defult_dev = set(defult_dev) - -DEVS = DEVS_USER | Defult_dev -DEV_USERS = list(DEVS) - -CHROME_BIN = Config.CHROME_BIN -CHROME_DRIVER = Config.CHROME_DRIVER +DEV_USERS = set(Config.DEV_USERS) +SUDO_USERS = set(Config.SUDO_USERS) +WHITELIST_USERS = set(Config.WHITELIST_USERS) # Plugins, DB and Workers DB_URI = Config.DB_URI diff --git a/Powers/bot_class.py b/Powers/bot_class.py index cdad2714..f9648c56 100644 --- a/Powers/bot_class.py +++ b/Powers/bot_class.py @@ -67,6 +67,7 @@ async def start(self): # Get cmds and keys cmd_list = await load_cmds(await all_plugins()) await load_support_users() + await cache_support() LOGGER.info(f"Plugins Loaded: {cmd_list}") scheduler.add_job(clean_my_db, 'cron', [ self], hour=3, minute=0, second=0) diff --git a/Powers/database/antispam_db.py b/Powers/database/antispam_db.py index d90ece23..67ff591c 100644 --- a/Powers/database/antispam_db.py +++ b/Powers/database/antispam_db.py @@ -28,6 +28,7 @@ def add_gban(self, user_id: int, reason: str, by_user: int): return self.update_gban_reason(user_id, reason) # If not already gbanned, then add to gban + ANTISPAM_BANNED.add(user_id) time_rn = datetime.now(TZ) return self.insert_one( { @@ -43,8 +44,8 @@ def remove_gban(self, user_id: int): with INSERTION_LOCK: # Check if user is already gbanned or not if self.find_one({"_id": user_id}): + ANTISPAM_BANNED.remove(user_id) return self.delete_one({"_id": user_id}) - return "User not gbanned!" def get_gban(self, user_id: int): diff --git a/Powers/database/approve_db.py b/Powers/database/approve_db.py index f9c3314c..899af43e 100644 --- a/Powers/database/approve_db.py +++ b/Powers/database/approve_db.py @@ -81,8 +81,6 @@ def __ensure_in_db(self): if not chat_data: new_data = {"_id": self.chat_id, "users": []} self.insert_one(new_data) - LOGGER.info( - f"Initialized Approve Document for chat {self.chat_id}") return new_data return chat_data # Migrate if chat id changes! diff --git a/Powers/database/blacklist_db.py b/Powers/database/blacklist_db.py index b2f29cef..7252ae28 100644 --- a/Powers/database/blacklist_db.py +++ b/Powers/database/blacklist_db.py @@ -110,8 +110,6 @@ def __ensure_in_db(self): "reason": "Automated blacklisted word: {{}}", } self.insert_one(new_data) - LOGGER.info( - f"Initialized Blacklist Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/chats_db.py b/Powers/database/chats_db.py index b4029a41..e580f7ff 100644 --- a/Powers/database/chats_db.py +++ b/Powers/database/chats_db.py @@ -107,7 +107,6 @@ def __ensure_in_db(self): if not chat_data: new_data = {"_id": self.chat_id, "chat_name": "", "users": []} self.insert_one(new_data) - LOGGER.info(f"Initialized Chats Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/disable_db.py b/Powers/database/disable_db.py index e4b21430..6f821b78 100644 --- a/Powers/database/disable_db.py +++ b/Powers/database/disable_db.py @@ -149,8 +149,6 @@ def __ensure_in_db(self): DISABLED_CMDS[self.chat_id] = { "commands": [], "action": "none"} self.insert_one(new_data) - LOGGER.info( - f"Initialized Disabling Document for chat {self.chat_id}") return new_data DISABLED_CMDS[self.chat_id] = chat_data return chat_data diff --git a/Powers/database/filters_db.py b/Powers/database/filters_db.py index fa6c3dc5..3172a62e 100644 --- a/Powers/database/filters_db.py +++ b/Powers/database/filters_db.py @@ -24,7 +24,15 @@ def save_filter( # Database update curr = self.find_one({"chat_id": chat_id, "keyword": keyword}) if curr: - return False + self.update( + {"chat_id": chat_id, "keyword": keyword}, + { + "filter_reply": filter_reply, + "msgtype": msgtype, + "fileid": fileid + } + ) + return return self.insert_one( { "chat_id": chat_id, diff --git a/Powers/database/greetings_db.py b/Powers/database/greetings_db.py index d758dfe4..3a00e445 100644 --- a/Powers/database/greetings_db.py +++ b/Powers/database/greetings_db.py @@ -161,8 +161,6 @@ def __ensure_in_db(self): "goodbye_mtype": False } self.insert_one(new_data) - LOGGER.info( - f"Initialized Greetings Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/locks_db.py b/Powers/database/locks_db.py index 6637c002..222ecbc0 100644 --- a/Powers/database/locks_db.py +++ b/Powers/database/locks_db.py @@ -58,35 +58,47 @@ def remove_lock_channel(self, chat: int, locktype: str): else: return False - def get_lock_channel(self, locktype: str = "all", chat: int = 0): + def get_lock_channel(self, chat: int, locktype: str = "all"): """ locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links, bot """ if locktype not in ["anti_c_send", "anti_fwd", "anti_fwd_u", "anti_fwd_c", "anti_links", "bot", "all"]: return False else: - if locktype == "all": - find = {} + if locktype != "all": + curr = self.find_one( + {"chat_id": chat, "locktype": locktype}) + return bool(curr) else: - find = {"locktype": locktype} - if chat: - if find: - curr = self.find_one( - {"chat_id": chat, "locktype": locktype}) - return bool(curr) - else: - to_return = [] - for i in lock_t: - curr = self.find_one({"chat_id": chat, "locktype": i}) - to_return.append(bool(curr)) - return all(to_return) - else: - curr = self.find_all(find) + to_return = { + "anti_channel": False, + "anti_fwd": { + "user": False, + "chat": False + }, + "anti_links": False, + "bot": False + } + curr = self.find_all({"chat_id": chat}) if not curr: - list_ = [] + return None else: - list_ = [i["chat_id"] for i in curr] - return list_ + for i in list(curr): + if i["locktype"] == "anti_c_send": + to_return["anti_channel"] = True + elif i["locktype"] == "anti_fwd": + to_return["anti_fwd"]["user"] = to_return["anti_fwd"]["chat"] = True + elif i["locktype"] == "anti_fwd_u": + to_return["anti_fwd"]["user"] = True + elif i["locktype"] == "anti_fwd_c": + to_return["anti_fwd"]["chat"] = True + elif i["anti_links"] == "anti_links": + to_return["anti_links"] = True + elif i["locktype"] == "bot": + to_return["bot"] = True + else: + continue + return to_return def merge_u_and_c(self, chat: int, locktype: str): if locktype == "anti_fwd_u": diff --git a/Powers/database/pins_db.py b/Powers/database/pins_db.py index 6edfc137..20644a9c 100644 --- a/Powers/database/pins_db.py +++ b/Powers/database/pins_db.py @@ -62,7 +62,6 @@ def __ensure_in_db(self): "cleanlinked": False, } self.insert_one(new_data) - LOGGER.info(f"Initialized Pins Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/reporting_db.py b/Powers/database/reporting_db.py index 6009d49d..9b9f1e7d 100644 --- a/Powers/database/reporting_db.py +++ b/Powers/database/reporting_db.py @@ -45,8 +45,6 @@ def __ensure_in_db(self): new_data = {"_id": self.chat_id, "status": True, "chat_type": chat_type} self.insert_one(new_data) - LOGGER.info( - f"Initialized Language Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/rules_db.py b/Powers/database/rules_db.py index 0704cd89..4f0790cd 100644 --- a/Powers/database/rules_db.py +++ b/Powers/database/rules_db.py @@ -68,8 +68,6 @@ def __ensure_in_db(self): if not chat_data: new_data = {"_id": self.chat_id, "privrules": False, "rules": ""} self.insert_one(new_data) - LOGGER.info( - f"Initialized Language Document for chat {self.chat_id}") return new_data return chat_data diff --git a/Powers/database/users_db.py b/Powers/database/users_db.py index d9135055..4a194fe3 100644 --- a/Powers/database/users_db.py +++ b/Powers/database/users_db.py @@ -70,7 +70,6 @@ def __ensure_in_db(self): new_data = {"_id": self.user_id, "username": "", "name": "unknown_till_now"} self.insert_one(new_data) - LOGGER.info(f"Initialized User Document for {self.user_id}") return new_data return chat_data diff --git a/Powers/database/warns_db.py b/Powers/database/warns_db.py index 216705d4..c7117db7 100644 --- a/Powers/database/warns_db.py +++ b/Powers/database/warns_db.py @@ -109,8 +109,6 @@ def __ensure_in_db(self, user_id: int): "num_warns": 0, } self.insert_one(new_data) - LOGGER.info( - f"Initialized Warn Document for {user_id} in {self.chat_id}") return new_data return chat_data @@ -129,8 +127,6 @@ def __ensure_in_db(self): new_data = {"_id": self.chat_id, "warn_mode": "none", "warn_limit": 3} self.insert_one(new_data) - LOGGER.info( - f"Initialized Warn Settings Document for {self.chat_id}") return new_data return chat_data diff --git a/Powers/plugins/admin.py b/Powers/plugins/admin.py index bacf2b4a..a28b925b 100644 --- a/Powers/plugins/admin.py +++ b/Powers/plugins/admin.py @@ -11,18 +11,15 @@ RPCError, UserAdminInvalid) from pyrogram.types import ChatPrivileges, Message -from Powers import LOGGER, OWNER_ID +from Powers import DEV_USERS, LOGGER, OWNER_ID, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.approve_db import Approve from Powers.database.reporting_db import Reporting -from Powers.supports import get_support_staff from Powers.utils.caching import (ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK, admin_cache_reload) -from Powers.utils.custom_filters import (admin_filter, command, owner_filter, - promote_filter) +from Powers.utils.custom_filters import admin_filter, command, promote_filter from Powers.utils.extract_user import extract_user from Powers.utils.parser import mention_html -from Powers.vars import Config @Gojo.on_message(command("adminlist")) @@ -67,7 +64,7 @@ async def adminlist_show(_, m: Message): adminstr += "\n\nBots:\n" adminstr += "\n".join(f"- {i}" for i in mention_bots) await m.reply_text(adminstr + "\n\n" + note) - LOGGER.info(f"Adminlist cmd use in {m.chat.id} by {m.from_user.id}") + except Exception as ef: if str(ef) == str(m.chat.id): await m.reply_text(text="Use /admincache to reload admins!") @@ -95,7 +92,11 @@ async def zombie_clean(c: Gojo, m: Message): except UserAdminInvalid: failed += 1 except FloodWait as e: - await sleep(e.x) + await sleep(e.value) + try: + await c.ban_chat_member(m.chat.id, member.user.id) + except: + pass if zombie == 0: return await wait.edit_text("Group is clean!") await wait.delete() @@ -110,7 +111,7 @@ async def reload_admins(_, m: Message): return await m.reply_text( "This command is made to be used in groups only!", ) - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if ( (m.chat.id in set(TEMP_ADMIN_CACHE_BLOCK.keys())) and (m.from_user.id not in SUPPORT_STAFF) @@ -122,7 +123,6 @@ async def reload_admins(_, m: Message): await admin_cache_reload(m, "admincache") TEMP_ADMIN_CACHE_BLOCK[m.chat.id] = "manualblock" await m.reply_text(text="Reloaded all admins in this chat!") - LOGGER.info(f"Admincache cmd use in {m.chat.id} by {m.from_user.id}") except RPCError as ef: await m.reply_text( text=f"Some error occured, report it using `/bug` \n Error: {ef}" @@ -206,9 +206,6 @@ async def fullpromote_usr(c: Gojo, m: Message): except Exception as e: LOGGER.error(e) LOGGER.error(format_exc()) - LOGGER.info( - f"{m.from_user.id} fullpromoted {user_id} in {m.chat.id} with title '{title}'", - ) await m.reply_text( ( "{promoter} promoted {promoted} in chat {chat_title} with full rights!" @@ -311,9 +308,7 @@ async def promote_usr(c: Gojo, m: Message): except Exception as e: LOGGER.error(e) LOGGER.error(format_exc()) - LOGGER.info( - f"{m.from_user.id} promoted {user_id} in {m.chat.id} with title '{title}'", - ) + await m.reply_text( ("{promoter} promoted {promoted} in chat {chat_title}!").format( promoter=(await mention_html(m.from_user.first_name, m.from_user.id)), @@ -382,7 +377,6 @@ async def demote_usr(c: Gojo, m: Message): user_id=user_id, privileges=ChatPrivileges(can_manage_chat=False), ) - LOGGER.info(f"{m.from_user.id} demoted {user_id} in {m.chat.id}") # ----- Remove admin from cache ----- try: admin_list = ADMIN_CACHE[m.chat.id] @@ -426,7 +420,7 @@ async def demote_usr(c: Gojo, m: Message): async def get_invitelink(c: Gojo, m: Message): # Bypass the bot devs, sudos and owner - DEV_LEVEL = get_support_staff("dev_level") + DEV_LEVEL = DEV_USERS if m.from_user.id not in DEV_LEVEL: user = await m.chat.get_member(m.from_user.id) if not user.privileges.can_invite_users and user.status != CMS.OWNER: @@ -438,7 +432,6 @@ async def get_invitelink(c: Gojo, m: Message): text=f"Invite Link for Chat {m.chat.id}: {link}", disable_web_page_preview=True, ) - LOGGER.info(f"{m.from_user.id} exported invite link in {m.chat.id}") except ChatAdminRequired: await m.reply_text(text="I'm not admin or I don't have rights.") except ChatAdminInviteRequired: diff --git a/Powers/plugins/antispam.py b/Powers/plugins/antispam.py index a5027070..eb278055 100644 --- a/Powers/plugins/antispam.py +++ b/Powers/plugins/antispam.py @@ -5,16 +5,15 @@ from pyrogram.errors import MessageTooLong, PeerIdInvalid, UserIsBlocked from pyrogram.types import Message -from Powers import LOGGER, MESSAGE_DUMP, SUPPORT_GROUP, TIME_ZONE +from Powers import (DEV_USERS, LOGGER, MESSAGE_DUMP, SUDO_USERS, SUPPORT_GROUP, + WHITELIST_USERS) from Powers.bot_class import Gojo from Powers.database.antispam_db import GBan from Powers.database.users_db import Users -from Powers.supports import get_support_staff from Powers.utils.clean_file import remove_markdown_and_html from Powers.utils.custom_filters import command from Powers.utils.extract_user import extract_user from Powers.utils.parser import mention_html -from Powers.vars import Config # Initialize db = GBan() @@ -38,7 +37,7 @@ async def gban(c: Gojo, m: Message): else: gban_reason = m.text.split(None, 2)[2] - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text(text="This user is part of my Support!, Can't ban our own!") @@ -61,7 +60,6 @@ async def gban(c: Gojo, m: Message): f"Added {user_first_name} to GBan List. \n They will now be banned in all groups where I'm admin!" ) ) - LOGGER.info(f"{m.from_user.id} gbanned {user_id} from {m.chat.id}") date = datetime.utcnow().strftime("%H:%M - %d-%m-%Y") log_msg = f"#GBAN \n Originated from: {m.chat.id} \n Admin: {await mention_html(m.from_user.first_name, m.from_user.id)} \n Gbanned User: {await mention_html(user_first_name, user_id)} \n Gbanned User ID: {user_id} \\ nEvent Stamp: {date}" await c.send_message(MESSAGE_DUMP, log_msg) @@ -71,6 +69,10 @@ async def gban(c: Gojo, m: Message): user_id, f"You have been added to my global ban list! \n Reason: {gban_reason} \n Appeal Chat: @{SUPPORT_GROUP}", ) + try: + await c.ban_chat_member(m.chat.id, user_id) + except Exception as e: + await m.reply_text(f"Failed to ban this user\n{e}") except UserIsBlocked: LOGGER.error("Could not send PM Message, user blocked bot") except PeerIdInvalid: @@ -93,7 +95,7 @@ async def ungban(c: Gojo, m: Message): user_id, user_first_name, _ = await extract_user(c, m) - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text(text="This user is part of my Support!, Can't ban our own!") @@ -110,7 +112,6 @@ async def ungban(c: Gojo, m: Message): db.remove_gban(user_id) await m.reply_text(text=f"Removed {user_first_name} from Global Ban List.") time = ((datetime.utcnow().strftime("%H:%M - %d-%m-%Y")),) - LOGGER.info(f"{m.from_user.id} ungbanned {user_id} from {m.chat.id}") log_msg = f"""#UNGBAN Originated from: {m.chat.id} Admin: {(await mention_html(m.from_user.first_name, m.from_user.id))} @@ -140,7 +141,6 @@ async def gban_count(_, m: Message): await m.reply_text( text=f"Number of people gbanned: {(db.count_gbans())}" ) - LOGGER.info(f"{m.from_user.id} counting gbans in {m.chat.id}") return @@ -170,7 +170,6 @@ async def gban_list(_, m: Message): document=f, caption="Here are all the globally banned geys!\n\n" ) - LOGGER.info(f"{m.from_user.id} exported gbanlist in {m.chat.id}") return diff --git a/Powers/plugins/approve.py b/Powers/plugins/approve.py index 9e9c667e..f84822f4 100644 --- a/Powers/plugins/approve.py +++ b/Powers/plugins/approve.py @@ -51,7 +51,6 @@ async def approve_user(c: Gojo, m: Message): ) return db.add_approve(user_id, user_first_name) - LOGGER.info(f"{user_id} approved by {m.from_user.id} in {m.chat.id}") # Allow all permissions try: @@ -90,7 +89,6 @@ async def disapprove_user(c: Gojo, m: Message): except UserNotParticipant: if already_approved: # If user is approved and not in chat, unapprove them. db.remove_approve(user_id) - LOGGER.info(f"{user_id} disapproved in {m.chat.id} as UserNotParticipant") await m.reply_text("This user is not in this chat, unapproved them.") return except RPCError as ef: @@ -110,7 +108,6 @@ async def disapprove_user(c: Gojo, m: Message): return db.remove_approve(user_id) - LOGGER.info(f"{user_id} disapproved by {m.from_user.id} in {m.chat.id}") # Set permission same as of current user by fetching them from chat! await m.chat.restrict_member( @@ -147,7 +144,6 @@ async def check_approved(_, m: Message): pass msg += f"- `{user_id}`: {user_name}\n" await m.reply_text(msg) - LOGGER.info(f"{m.from_user.id} checking approved users in {m.chat.id}") return @@ -160,7 +156,6 @@ async def check_approval(c: Gojo, m: Message): except Exception: return check_approve = db.check_approve(user_id) - LOGGER.info(f"{m.from_user.id} checking approval of {user_id} in {m.chat.id}") if not user_id: await m.reply_text( @@ -218,7 +213,6 @@ async def unapproveall_callback(_, q: CallbackQuery): permissions=q.message.chat.permissions, ) await q.message.delete() - LOGGER.info(f"{user_id} disapproved all users in {q.message.chat.id}") await q.answer("Disapproved all users!", show_alert=True) return diff --git a/Powers/plugins/auto_join.py b/Powers/plugins/auto_join.py index f7cc8fe5..c2e807d0 100644 --- a/Powers/plugins/auto_join.py +++ b/Powers/plugins/auto_join.py @@ -7,10 +7,9 @@ from pyrogram.types import InlineKeyboardMarkup as ikm from pyrogram.types import Message -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.autojoin_db import AUTOJOIN -from Powers.supports import get_support_staff from Powers.utils.custom_filters import admin_filter, auto_join_filter, command @@ -96,7 +95,7 @@ async def join_request_handler(c: Gojo, j: ChatJoinRequest): chat = j.chat.id aj = AUTOJOIN() join_type = aj.get_autojoin(chat) - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if not join_type: return diff --git a/Powers/plugins/bans.py b/Powers/plugins/bans.py index f7efb9c1..69b035b8 100644 --- a/Powers/plugins/bans.py +++ b/Powers/plugins/bans.py @@ -9,16 +9,15 @@ InlineKeyboardButton, InlineKeyboardMarkup, Message) -from Powers import LOGGER, MESSAGE_DUMP, OWNER_ID +from Powers import (DEV_USERS, LOGGER, MESSAGE_DUMP, OWNER_ID, SUDO_USERS, + WHITELIST_USERS) from Powers.bot_class import Gojo -from Powers.supports import get_support_staff from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload from Powers.utils.custom_filters import command, restrict_filter from Powers.utils.extract_user import extract_user from Powers.utils.extras import BAN_GIFS, KICK_GIFS from Powers.utils.parser import mention_html from Powers.utils.string import extract_time -from Powers.vars import Config @Gojo.on_message(command("tban") & restrict_filter) @@ -39,15 +38,13 @@ async def tban_usr(c: Gojo, m: Message): await m.reply_text("WTF?? Why would I ban myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() r_id = m.reply_to_message.id if m.reply_to_message else m.id @@ -86,7 +83,6 @@ async def tban_usr(c: Gojo, m: Message): admin = await mention_html(m.from_user.first_name, m.from_user.id) banned = await mention_html(user_first_name, user_id) chat_title = m.chat.title - LOGGER.info(f"{m.from_user.id} tbanned {user_id} in {m.chat.id}") await m.chat.ban_member( user_id, until_date=bantime) @@ -161,7 +157,7 @@ async def stban_usr(c: Gojo, m: Message): await m.reply_text(text="I can't ban nothing!") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) try: user_id, _, _ = await extract_user(c, m) @@ -179,9 +175,7 @@ async def stban_usr(c: Gojo, m: Message): await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() if m.reply_to_message and len(m.text.split()) >= 2: @@ -215,7 +209,6 @@ async def stban_usr(c: Gojo, m: Message): await m.stop_propagation() try: - LOGGER.info(f"{m.from_user.id} stbanned {user_id} in {m.chat.id}") await m.chat.ban_member(user_id, until_date=bantime) await m.delete() if m.reply_to_message: @@ -269,13 +262,11 @@ async def dtban_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I ban myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text(text="I am not going to ban one of my support staff") - LOGGER.info( - f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() if m.reply_to_message and len(m.text.split()) >= 2: @@ -312,7 +303,6 @@ async def dtban_usr(c: Gojo, m: Message): admin = await mention_html(m.from_user.first_name, m.from_user.id) banned = await mention_html(user_first_name, user_id) chat_title = m.chat.title - LOGGER.info(f"{m.from_user.id} dtbanned {user_id} in {m.chat.id}") await m.chat.ban_member(user_id, until_date=bantime) await m.reply_to_message.delete() txt = f"{admin} banned {banned} in {chat_title}!" @@ -399,15 +389,13 @@ async def kick_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I kick myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to kick {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() try: @@ -423,7 +411,6 @@ async def kick_usr(c: Gojo, m: Message): admin = await mention_html(m.from_user.first_name, m.from_user.id) kicked = await mention_html(user_first_name, user_id) chat_title = m.chat.title - LOGGER.info(f"{m.from_user.id} kicked {user_id} in {m.chat.id}") await m.chat.ban_member(user_id) txt = f"{admin} kicked {kicked} in {chat_title}!" if reason: @@ -490,15 +477,13 @@ async def skick_usr(c: Gojo, m: Message): await m.reply_text("Nuh Hu, why would I kick myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to skick {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() try: @@ -511,7 +496,6 @@ async def skick_usr(c: Gojo, m: Message): await m.stop_propagation() try: - LOGGER.info(f"{m.from_user.id} skicked {user_id} in {m.chat.id}") await m.chat.ban_member(user_id) await m.delete() if m.reply_to_message: @@ -564,15 +548,13 @@ async def dkick_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I kick myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to dkick {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.stop_propagation() try: @@ -585,7 +567,6 @@ async def dkick_usr(c: Gojo, m: Message): await m.stop_propagation() try: - LOGGER.info(f"{m.from_user.id} dkicked {user_id} in {m.chat.id}") await m.reply_to_message.delete() await m.chat.ban_member(user_id) admin = await mention_html(m.from_user.first_name, m.from_user.id) @@ -715,15 +696,12 @@ async def sban_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I ban myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to sban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.stop_propagation() try: @@ -736,7 +714,6 @@ async def sban_usr(c: Gojo, m: Message): await m.stop_propagation() try: - LOGGER.info(f"{m.from_user.id} sbanned {user_id} in {m.chat.id}") await m.chat.ban_member(user_id) await m.delete() if m.reply_to_message: @@ -796,15 +773,12 @@ async def dban_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I ban myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to dban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.stop_propagation() try: @@ -821,7 +795,6 @@ async def dban_usr(c: Gojo, m: Message): reason = m.text.split(None, 1)[1] try: - LOGGER.info(f"{m.from_user.id} dbanned {user_id} in {m.chat.id}") await m.reply_to_message.delete() await m.chat.ban_member(user_id) txt = f"{m.from_user.mention} banned {m.reply_to_message.from_user.mention} in {m.chat.title}!" @@ -897,15 +870,12 @@ async def ban_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I ban myself?") await m.stop_propagation() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.stop_propagation() try: @@ -928,7 +898,6 @@ async def ban_usr(c: Gojo, m: Message): reason = m.text.split(None, 2)[2] try: - LOGGER.info(f"{m.from_user.id} banned {user_id} in {m.chat.id}") await m.chat.ban_member(user_id) banned = await mention_html(user_first_name, user_id) txt = f"{m.from_user.mention} banned {banned} in {m.chat.title}!" @@ -1024,7 +993,6 @@ async def kickme(c: Gojo, m: Message): if len(m.text.split()) >= 2: reason = m.text.split(None, 1)[1] try: - LOGGER.info(f"{m.from_user.id} kickme used by {m.from_user.id} in {m.chat.id}") mem = await c.get_chat_member(m.chat.id,m.from_user.id) if mem.status in [enums.ChatMemberStatus.ADMINISTRATOR, enums.ChatMemberStatus.OWNER]: try: diff --git a/Powers/plugins/birthday.py b/Powers/plugins/birthday.py index e660eb9a..ddaccb54 100644 --- a/Powers/plugins/birthday.py +++ b/Powers/plugins/birthday.py @@ -125,7 +125,7 @@ async def who_is_next(c: Gojo, m: Message): if m.chat.type == ChatType.PRIVATE: await m.reply_text("Use it in group") return - curr = datetime.now(TIME_ZONE).date() + curr = datetime.now().date() xx = await m.reply_text("📆") users = [] if blist: @@ -173,7 +173,7 @@ async def cant_recall_it(c: Gojo, m: Message): await m.reply_text(f"Got an error\n{e}") return - curr = datetime.now(TIME_ZONE).date() + curr = datetime.now().date() u_dob = give_date(result["dob"]) formatted = str(u_dob.strftime('%d' + '%B %Y'))[2:-5] day = int(result["dob"].split('/')[0]) @@ -182,7 +182,7 @@ async def cant_recall_it(c: Gojo, m: Message): if (u_dob.day,u_dob.month) < (curr.day,curr.month): next_b = date(curr.year + 1, u_dob.month, u_dob.day) days_left = (next_b - curr).days - txt = f"{men} 's birthday is passed 🫤\nDays left until next one {days_left}" + txt = f"{men} 's birthday is passed 🫤\nDays left until next one {abs(days_left)}" txt += f"\nBirthday on: {bday_on}" txt += f"\n\nDate of birth: {result['dob']}" elif (u_dob.day,u_dob.month) == (curr.day,curr.month): @@ -190,7 +190,7 @@ async def cant_recall_it(c: Gojo, m: Message): else: u_dobm = date(curr.year, u_dob.month, u_dob.day) days_left = (u_dobm - curr).days - txt = f"User's birthday is coming🥳\nDays left : {days_left}" + txt = f"User's birthday is coming🥳\nDays left: {abs(days_left)}" txt += f"\nBirthday on: {bday_on}" txt += f"\n\nDate of birth: {result['dob']}" txt+= "\n\n**NOTE**:\nDOB may be wrong if user haven't entered his/her birth year" @@ -218,7 +218,7 @@ async def chat_birthday_settings(c: Gojo, m: Message): await m.reply_text("Do you want to wish members for their birthday in the group?",reply_markup=kb) return -@Gojo.on_callback_query(filters.regex("^switchh_")) +@Gojo.on_callback_query(filters.regex(r"^switchh_(yes|no)$")) async def switch_on_off(c:Gojo, q: CallbackQuery): user = (await q.message.chat.get_member(q.from_user.id)).status await q.message.chat.get_member(q.from_user.id) @@ -227,11 +227,11 @@ async def switch_on_off(c:Gojo, q: CallbackQuery): return data = q.data.split("_")[1] chats = q.message.chat.id - xXx = {"chat_id":chats} + query = {"chat_id":chats} if data == "yes": - bday_cinfo.delete_one(xXx) + bday_cinfo.delete_one(query) elif data == "no": - bday_cinfo.insert_one(xXx) + bday_cinfo.insert_one(query) await q.edit_message_text(f"Done! I will {'wish' if data == 'yes' else 'not wish'}",reply_markup=IKM([[IKB("Close", "f_close")]])) return diff --git a/Powers/plugins/blacklist.py b/Powers/plugins/blacklist.py index 92030964..768a5e4b 100644 --- a/Powers/plugins/blacklist.py +++ b/Powers/plugins/blacklist.py @@ -15,8 +15,6 @@ async def view_blacklist(_, m: Message): db = Blacklist(m.chat.id) - LOGGER.info(f"{m.from_user.id} checking blacklists in {m.chat.id}") - chat_title = m.chat.title blacklists_chat = f"Current Blacklisted words in {chat_title}:\n\n" all_blacklisted = db.get_blacklists() @@ -58,7 +56,6 @@ async def add_blacklist(_, m: Message): ", ".join([f"{i}" for i in bl_words]) + " already added in blacklist, skipped them!" ) - LOGGER.info(f"{m.from_user.id} added new blacklists ({bl_words}) in {m.chat.id}") trigger = ", ".join(f"{i}" for i in bl_words) await m.reply_text( text=f"Added {trigger} in blacklist words!" @@ -116,7 +113,6 @@ async def rm_blacklist(_, m: Message): "Could not find " + ", ".join(f"{i}" for i in non_found_words) ) + " in blcklisted words, skipped them." - LOGGER.info(f"{m.from_user.id} removed blacklists ({bl_words}) in {m.chat.id}") bl_words = ", ".join(f"{i}" for i in bl_words) await m.reply_text( text=f"Removed {bl_words} from blacklist words!" @@ -145,13 +141,9 @@ async def set_bl_action(_, m: Message): return db.set_action(action) - LOGGER.info( - f"{m.from_user.id} set blacklist action to '{action}' in {m.chat.id}", - ) await m.reply_text(text=f"Set action for blacklist for this to {action}") elif len(m.text.split()) == 1: action = db.get_action() - LOGGER.info(f"{m.from_user.id} checking blacklist action in {m.chat.id}") await m.reply_text( text=f"""The current action for blacklists in this chat is {action} All blacklist modes delete the message containing blacklist word.""" @@ -201,7 +193,6 @@ async def rm_allbl_callback(_, q: CallbackQuery): return db.rm_all_blacklist() await q.message.delete() - LOGGER.info(f"{user_id} removed all blacklists in {q.message.chat.id}") await q.answer("Cleared all Blacklists!", show_alert=True) return diff --git a/Powers/plugins/captcha.py b/Powers/plugins/captcha.py index a9ce22de..b57065c1 100644 --- a/Powers/plugins/captcha.py +++ b/Powers/plugins/captcha.py @@ -8,10 +8,9 @@ from pyrogram.types import InlineKeyboardMarkup as ikm from pyrogram.types import Message -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.captcha_db import CAPTCHA, CAPTCHA_DATA -from Powers.supports import get_support_staff from Powers.utils.captcha_helper import (genrator, get_image_captcha, get_qr_captcha) from Powers.utils.custom_filters import admin_filter, command @@ -138,7 +137,7 @@ async def on_chat_members_updatess(c: Gojo, u: ChatMemberUpdated): captcha = CAPTCHA() cap_data = CAPTCHA_DATA() - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user in SUPPORT_STAFF: return diff --git a/Powers/plugins/chat_blacklist.py b/Powers/plugins/chat_blacklist.py index 84bedbea..16960625 100644 --- a/Powers/plugins/chat_blacklist.py +++ b/Powers/plugins/chat_blacklist.py @@ -18,7 +18,6 @@ async def blacklist_chat(c: Gojo, m: Message): if len(m.text.split()) >= 2: chat_ids = m.text.split()[1:] replymsg = await m.reply_text(f"Adding {len(chat_ids)} chats to blacklist") - LOGGER.info(f"{m.from_user.id} blacklisted {chat_ids} groups for bot") for chat in chat_ids: try: get_chat = await c.get_chat(chat) @@ -51,7 +50,6 @@ async def unblacklist_chat(c: Gojo, m: Message): if len(m.text.split()) >= 2: chat_ids = m.text.split()[1:] replymsg = await m.reply_text(f"Removing {len(chat_ids)} chats from blacklist") - LOGGER.info(f"{m.from_user.id} removed blacklisted {chat_ids} groups for bot") bl_chats = db.list_all_chats() for chat in chat_ids: try: @@ -89,7 +87,6 @@ async def unblacklist_chat(c: Gojo, m: Message): ) async def list_blacklist_chats(_, m: Message): bl_chats = db.list_all_chats() - LOGGER.info(f"{m.from_user.id} checking group blacklists in {m.chat.id}") if bl_chats: txt = ( ( diff --git a/Powers/plugins/clean_db.py b/Powers/plugins/clean_db.py index 7dc77a2c..23a9d4ee 100644 --- a/Powers/plugins/clean_db.py +++ b/Powers/plugins/clean_db.py @@ -18,7 +18,6 @@ from Powers.database.reporting_db import Reporting # from Powers.database.users_db import Users from Powers.database.warns_db import Warns, WarnSettings -from Powers.vars import Config async def clean_my_db(c: Gojo, is_cmd=False, id=None): diff --git a/Powers/plugins/dev.py b/Powers/plugins/dev.py index 010cf386..c37e2dfe 100644 --- a/Powers/plugins/dev.py +++ b/Powers/plugins/dev.py @@ -16,15 +16,15 @@ from pyrogram.types import InlineKeyboardMarkup as IKM from pyrogram.types import Message -from Powers import (BOT_TOKEN, LOG_DATETIME, LOGFILE, LOGGER, MESSAGE_DUMP, - OWNER_ID, UPTIME) +from Powers import (BOT_TOKEN, DEV_USERS, LOG_DATETIME, LOGFILE, LOGGER, + MESSAGE_DUMP, OWNER_ID, SUDO_USERS, UPTIME, + WHITELIST_USERS) from Powers.bot_class import Gojo from Powers.database import MongoDB from Powers.database.chats_db import Chats from Powers.database.support_db import SUPPORTS from Powers.database.users_db import Users from Powers.plugins.scheduled_jobs import clean_my_db -from Powers.supports import get_support_staff from Powers.utils.clean_file import remove_markdown_and_html from Powers.utils.custom_filters import command from Powers.utils.extract_user import extract_user @@ -80,6 +80,12 @@ async def add_support(c: Gojo, m:Message): return else: support.insert_support_user(userr,to) + if to == "dev": + DEV_USERS.add(userr) + elif to == "sudo": + SUDO_USERS.add(userr) + else: + WHITELIST_USERS.add(userr) await m.reply_text(f"This user is now a {to} user") return can_do = can_change_type(curr_user,to) @@ -196,6 +202,9 @@ async def rm_support(c: Gojo, m: Message): can_user = can_change_type(curr_user,to_user) if m.from_user.id == int(OWNER_ID) or can_user: support.delete_support_user(curr) + DEV_USERS.discard(curr) + SUDO_USERS.discard(curr) + WHITELIST_USERS.discard(curr) await m.reply_text("Done! User now no longer belongs to the support staff") else: await m.reply_text("Sorry you can't do that...") @@ -203,7 +212,6 @@ async def rm_support(c: Gojo, m: Message): @Gojo.on_message(command("ping", sudo_cmd=True)) async def ping(_, m: Message): - LOGGER.info(f"{m.from_user.id} used ping cmd in {m.chat.id}") start = time() replymsg = await m.reply_text(text="Pinging...", quote=True) delta_ping = time() - start @@ -386,6 +394,10 @@ async def evaluate_code(c: Gojo, m: Message): MESSAGE_DUMP, f"@{m.from_user.username} TREID TO FETCH ENV OF BOT \n userid = {m.from_user.id}", ) + final_output = f"**EVAL**: ```python\n{cmd}```\n\nOUTPUT:\n```powershell\n{evaluation}``` \n" + await sm.edit(final_output) + return + for j in HARMFUL: if j in evaluation.split() or j in cmd: if m.from_user.id != OWNER_ID: @@ -393,6 +405,9 @@ async def evaluate_code(c: Gojo, m: Message): await c.send_message( MESSAGE_DUMP, f"@{m.from_user.username} TREID TO FETCH ENV OF BOT \n userid = {m.from_user.id}") + final_output = f"**EVAL**: ```python\n{cmd}```\n\nOUTPUT:\n```powershell\n{evaluation}``` \n" + await sm.edit(final_output) + return for i in evaluation.split(): for j in i.split("="): if j and j[0] in HARMFUL: @@ -402,10 +417,12 @@ async def evaluate_code(c: Gojo, m: Message): MESSAGE_DUMP, f"@{m.from_user.username} TREID TO FETCH ENV OF BOT \n userid = {m.from_user.id}" ) - + final_output = f"**EVAL**: ```python\n{cmd}```\n\nOUTPUT:\n```powershell\n{evaluation}``` \n" + await sm.edit(final_output) + return try: - final_output = f"**EVAL**: ```python\n{cmd}```\n\nOUTPUT:\n```python\n{evaluation}``` \n" + final_output = f"**EVAL**: ```python\n{cmd}```\n\nOUTPUT:\n```powershell\n{evaluation}``` \n" await sm.edit(final_output) except MessageTooLong: final_output = f"EVAL: {cmd}\n\nOUTPUT:\n{evaluation} \n" diff --git a/Powers/plugins/disable.py b/Powers/plugins/disable.py index e2334947..a616edeb 100644 --- a/Powers/plugins/disable.py +++ b/Powers/plugins/disable.py @@ -24,7 +24,6 @@ async def disableit(_, m: Message): db = Disabling(m.chat.id) disable_list = db.get_disabled() - LOGGER.info(f"{m.from_user.id} used disabled cmd in {m.chat.id}") if str(m.text.split(None, 1)[1]) in disable_list: return await m.reply_text("It's already disabled!") @@ -48,8 +47,6 @@ async def set_dsbl_action(_, m: Message): cur = True args = m.text.split(" ", 1) - LOGGER.info(f"{m.from_user.id} disabledel used in {m.chat.id}") - if len(args) >= 2: if args[1].lower() == "on": db.set_action("del") @@ -73,7 +70,6 @@ async def enableit(_, m: Message): if str(m.text.split(None, 1)[1]) not in disable_list: return await m.reply_text("It's not disabled!") db.remove_disabled((str(m.text.split(None, 1)[1])).lower()) - LOGGER.info(f"{m.from_user.id} enabled something in {m.chat.id}") return await m.reply_text(f"Enabled {m.text.split(None, 1)[1]}!") @@ -86,7 +82,6 @@ async def disabling(_, m: Message): ) tes = "List of commnds that can be disabled:\n" tes += "\n".join(f" • {escape(i)}" for i in disable_cmd_keys) - LOGGER.info(f"{m.from_user.id} checked disableable {m.chat.id}") return await m.reply_text(tes) @@ -99,7 +94,6 @@ async def disabled(_, m: Message): return tex = "Disabled commands:\n" tex += "\n".join(f" • {escape(i)}" for i in disable_list) - LOGGER.info(f"{m.from_user.id} checked disabled {m.chat.id}") return await m.reply_text(tex) @@ -145,7 +139,6 @@ async def enablealll(_, q: CallbackQuery): return db = Disabling(q.message.chat.id) db.rm_all_disabled() - LOGGER.info(f"{user_id} enabled all in {q.message.chat.id}") await q.message.edit_text("Enabled all!", show_alert=True) return diff --git a/Powers/plugins/filters.py b/Powers/plugins/filters.py index 34e7f93f..222dbc3a 100644 --- a/Powers/plugins/filters.py +++ b/Powers/plugins/filters.py @@ -25,8 +25,6 @@ @Gojo.on_message(command("filters") & filters.group & ~filters.bot) async def view_filters(_, m: Message): - LOGGER.info(f"{m.from_user.id} checking filters in {m.chat.id}") - filters_chat = f"Filters in {m.chat.title}:\n" all_filters = db.get_all_filters(m.chat.id) actual_filters = [j for i in all_filters for j in i.split("|")] @@ -66,9 +64,9 @@ async def add_filter(_, m: Message): extracted = await split_quotes(args[1]) keyword = extracted[0].lower() - for k in keyword.split("|"): - if k in actual_filters: - return await m.reply_text(f"Filter {k} already exists!") + # for k in keyword.split("|"): + # if k in actual_filters: + # return await m.reply_text(f"Filter {k} already exists!") if not keyword: return await m.reply_text( @@ -98,7 +96,6 @@ async def add_filter(_, m: Message): ) add = db.save_filter(m.chat.id, keyword, teks, msgtype, file_id) - LOGGER.info(f"{m.from_user.id} added new filter ({keyword}) in {m.chat.id}") if add: await m.reply_text( f"Saved filter for '{', '.join(keyword.split('|'))}' in {m.chat.title}!", @@ -122,7 +119,6 @@ async def stop_filter(_, m: Message): for keyword in act_filters: if keyword == m.text.split(None, 1)[1].lower(): db.rm_filter(m.chat.id, m.text.split(None, 1)[1].lower()) - LOGGER.info(f"{m.from_user.id} removed filter ({keyword}) in {m.chat.id}") await m.reply_text( f"Okay, I'll stop replying to that filter and it's aliases in {m.chat.title}.", ) @@ -171,7 +167,6 @@ async def rm_allfilters_callback(_, q: CallbackQuery): return db.rm_all_filters(q.message.chat.id) await q.message.edit_text(f"Cleared all filters for {q.message.chat.title}") - LOGGER.info(f"{user_id} removed all filter from {q.message.chat.id}") await q.answer("Cleared all Filters!", show_alert=True) return diff --git a/Powers/plugins/flood.py b/Powers/plugins/flood.py index dd7c220f..51effc8f 100644 --- a/Powers/plugins/flood.py +++ b/Powers/plugins/flood.py @@ -11,13 +11,11 @@ InlineKeyboardButton, InlineKeyboardMarkup, Message) -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.flood_db import Floods -from Powers.supports import get_support_staff from Powers.utils.custom_filters import admin_filter, command, flood_filter from Powers.utils.extras import BAN_GIFS, KICK_GIFS, MUTE_GIFS -from Powers.vars import Config on_key = ["on", "start", "disable"] off_key = ["off", "end", "enable", "stop"] @@ -230,7 +228,7 @@ async def flood_set(c: Gojo, m: Message): @Gojo.on_callback_query(filters.regex("^f_")) async def callbacks(c: Gojo, q: CallbackQuery): - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) data = q.data if data == "f_close": await q.answer("Closed") @@ -352,7 +350,7 @@ async def reverse_callbacks(c: Gojo, q: CallbackQuery): data = q.data.split("_") action = data[1] user_id = int(q.data.split("=")[1]) - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if not q.from_user: return q.answer("Looks like you are not an user 👀") if action == "ban": @@ -572,13 +570,13 @@ async def flood_watcher(c: Gojo, m: Message): elif action == "kick": try: - await m.chat.ban_member(u_id) + await m.chat.ban_member(u_id, datetime.now()+timedelta(seconds=10)) txt = "Don't dare to spam here if I am around! Nothing can escape my 6 eyes\nAction: kicked\nReason: Spaming" await m.reply_animation( animation=str(choice(KICK_GIFS)), caption=txt, ) - await m.chat.unban_member(u_id) + await m.chat.unban_member(m.from_user.id) dic[c_id][u_id][1].clear() dic[c_id][u_id][0].clear() return diff --git a/Powers/plugins/formatting.py b/Powers/plugins/formatting.py index d727370e..2d4bcddf 100644 --- a/Powers/plugins/formatting.py +++ b/Powers/plugins/formatting.py @@ -35,7 +35,6 @@ async def markdownhelp(_, m: Message): quote=True, reply_markup=(await gen_formatting_kb(m)), ) - LOGGER.info(f"{m.from_user.id} used cmd '{m.command}' in {m.chat.id}") return diff --git a/Powers/plugins/fun.py b/Powers/plugins/fun.py index 42e56f58..303aab62 100644 --- a/Powers/plugins/fun.py +++ b/Powers/plugins/fun.py @@ -5,15 +5,13 @@ from pyrogram.errors import MessageTooLong from pyrogram.types import Message -from Powers import LOGGER +from Powers import DEV_USERS from Powers.bot_class import Gojo -from Powers.supports import get_support_staff from Powers.utils import extras from Powers.utils.custom_filters import command from Powers.utils.extras import NOWYES as NO from Powers.utils.extras import YESWNO as YES -DEV_USERS = get_support_staff("dev") @Gojo.on_message(command("shout")) async def fun_shout(_, m: Message): @@ -33,7 +31,6 @@ async def fun_shout(_, m: Message): result = "".join(result) msg = "```\n" + result + "```" await m.reply_text(msg, parse_mode=enums.ParseMode.MARKDOWN) - LOGGER.info(f"{m.from_user.id} shouted in {m.chat.id}") return except MessageTooLong as e: await m.reply_text(f"Error: {e}") @@ -43,7 +40,6 @@ async def fun_shout(_, m: Message): @Gojo.on_message(command("runs")) async def fun_run(_, m: Message): await m.reply_text(choice(extras.RUN_STRINGS)) - LOGGER.info(f"{m.from_user.id} runed in {m.chat.id}") return @@ -79,7 +75,6 @@ async def fun_slap(c: Gojo, m: Message): reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) await reply_text(reply) - LOGGER.info(f"{m.from_user.id} slaped in {m.chat.id}") return @@ -87,7 +82,6 @@ async def fun_slap(c: Gojo, m: Message): async def fun_roll(_, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text await reply_text(choice(range(1, 7))) - LOGGER.info(f"{m.from_user.id} roll in {m.chat.id}") return @@ -95,7 +89,6 @@ async def fun_roll(_, m: Message): async def fun_toss(_, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text await reply_text(choice(extras.TOSS)) - LOGGER.info(f"{m.from_user.id} tossed in {m.chat.id}") return @@ -108,13 +101,9 @@ async def insult(c: Gojo, m: Message): user_first_name = m.reply_to_message.from_user.first_name if user_id in DEV_USERS: await m.reply_text("Sorry! I can't insult my devs....") - return LOGGER.info( - f"{m.from_user.id} tried to insult {user_first_name} in {m.chat.id}" - ) else: Insult_omp = choice(extras.INSULT_STRINGS) await m.reply_to_message.reply_text(Insult_omp) - LOGGER.info(f"{m.from_user.id} insulted {user_first_name} in {m.chat.id}") @Gojo.on_message(command("yes")) @@ -122,7 +111,6 @@ async def yesw(c: Gojo, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text rtext = YES[0] await reply_text(rtext) - LOGGER.info(f"{m.from_user.id} said YES or may be NO in {m.chat.id}") return @@ -131,7 +119,6 @@ async def now(c: Gojo, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text rtext = NO[0] await reply_text(rtext) - LOGGER.info(f"{m.from_user.id} said NO or may be YES in {m.chat.id}") return @@ -139,7 +126,6 @@ async def now(c: Gojo, m: Message): async def fun_shrug(_, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text await reply_text(r"¯\_(ツ)_/¯") - LOGGER.info(f"{m.from_user.id} shruged in {m.chat.id}") return @@ -149,7 +135,6 @@ async def fun_bluetext(_, m: Message): await reply_text( "|| /BLUE /TEXT\n/MUST /CLICK\n/I /AM /A /STUPID /ANIMAL /THAT /IS /ATTRACTED /TO /COLORS ||", ) - LOGGER.info(f"{m.from_user.id} bluetexted in {m.chat.id}") return @@ -157,7 +142,6 @@ async def fun_bluetext(_, m: Message): async def fun_decide(_, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text await reply_text(choice(extras.DECIDE)) - LOGGER.info(f"{m.from_user.id} decided in {m.chat.id}") return @@ -165,7 +149,6 @@ async def fun_decide(_, m: Message): async def fun_table(_, m: Message): reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text await reply_text(choice(extras.REACTIONS)) - LOGGER.info(f"{m.from_user.id} reacted in {m.chat.id}") return @@ -199,7 +182,6 @@ async def weebify(_, m: Message): text=f"""Weebified String: {string}""" ) - LOGGER.info(f"{m.from_user.id} weebified '{args}' in {m.chat.id}") return diff --git a/Powers/plugins/greetings.py b/Powers/plugins/greetings.py index 169f1268..e7207c2b 100644 --- a/Powers/plugins/greetings.py +++ b/Powers/plugins/greetings.py @@ -7,11 +7,10 @@ from pyrogram.errors import ChannelPrivate, ChatAdminRequired, RPCError from pyrogram.types import ChatMemberUpdated, Message -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER from Powers.bot_class import Gojo from Powers.database.antispam_db import GBan from Powers.database.greetings_db import Greetings -from Powers.supports import get_support_staff from Powers.utils.cmd_senders import send_cmd from Powers.utils.custom_filters import admin_filter, bot_admin_filter, command from Powers.utils.kbhelpers import ikb @@ -19,13 +18,10 @@ from Powers.utils.parser import escape_markdown, mention_html from Powers.utils.string import (build_keyboard, escape_invalid_curly_brackets, parse_button) -from Powers.vars import Config # Initialize gdb = GBan() -DEV_USERS = get_support_staff("dev") - ChatType = enums.ChatType @@ -243,11 +239,7 @@ async def cleannnnn(_, m: Message): @Gojo.on_chat_member_updated(filters.group, group=69) async def member_has_joined(c: Gojo, member: ChatMemberUpdated): - if ( - member.new_chat_member - and member.new_chat_member.status not in {CMS.BANNED, CMS.LEFT, CMS.RESTRICTED} - and not member.old_chat_member - ): + if member.new_chat_member.status not in {CMS.BANNED, CMS.LEFT, CMS.RESTRICTED}: pass else: return @@ -263,7 +255,7 @@ async def member_has_joined(c: Gojo, member: ChatMemberUpdated): await c.send_animation( chat_id=member.chat.id, animation="./extras/william.gif", - caption="😳 My **DEV** has also joined the chat!", + caption=f"😳 My **DEV** {user.mention} has also joined the chat!", ) return if banned_users: @@ -345,11 +337,7 @@ async def member_has_joined(c: Gojo, member: ChatMemberUpdated): @Gojo.on_chat_member_updated(filters.group, group=99) async def member_has_left(c: Gojo, member: ChatMemberUpdated): - if ( - not member.new_chat_member - and member.old_chat_member.status not in {CMS.BANNED, CMS.RESTRICTED} - and member.old_chat_member - ): + if member.old_chat_member.status == CMS.LEFT: pass else: return @@ -395,7 +383,7 @@ async def member_has_left(c: Gojo, member: ChatMemberUpdated): if user.id in DEV_USERS: await c.send_message( member.chat.id, - "Will miss you master :(", + f"Will miss you my master {user.mention} :(", ) return if not teks: @@ -419,6 +407,8 @@ async def member_has_left(c: Gojo, member: ChatMemberUpdated): if ooo: db.set_cleangoodbye_id(int(ooo.id)) return + except ChannelPrivate: + pass except RPCError as e: LOGGER.error(e) LOGGER.error(format_exc(e)) @@ -551,8 +541,6 @@ async def goodbye(c: Gojo, m: Message): reply_markup=button, ) return - return - __PLUGIN__ = "greetings" __alt_name__ = ["welcome", "goodbye", "cleanservice"] diff --git a/Powers/plugins/info.py b/Powers/plugins/info.py index 7e71fea7..c3698ef5 100644 --- a/Powers/plugins/info.py +++ b/Powers/plugins/info.py @@ -9,13 +9,11 @@ from pyrogram.raw.functions.users import GetFullUser from pyrogram.types import Message -from Powers import LOGGER, OWNER_ID +from Powers import DEV_USERS, LOGGER, OWNER_ID, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.antispam_db import GBan -from Powers.supports import get_support_staff from Powers.utils.custom_filters import command from Powers.utils.extract_user import extract_user -from Powers.vars import Config gban_db = GBan() @@ -83,10 +81,7 @@ async def user_info(c: Gojo, user, already=False): about = ll.full_user.about except Exception: pass - SUPPORT_STAFF = get_support_staff() - DEV_USERS = get_support_staff("dev") - SUDO_USERS = get_support_staff("sudo") - WHITELIST_USERS = get_support_staff("whitelist") + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) username = user.username first_name = user.first_name last_name = user.last_name @@ -246,8 +241,12 @@ async def info_func(c: Gojo, message: Message): if message.reply_to_message and message.reply_to_message.sender_chat: await message.reply_text("This is not a user, but rather a channel. Use `/chinfo` to fetch its information.") return - user, _, user_name = await extract_user(c, message) - + try: + user, _, user_name = await extract_user(c, message) + except: + await message.reply_text("Got Some errors failed to fetch user info") + LOGGER.error(e) + LOGGER.error(format_exc) if not user: await message.reply_text("Can't find user to fetch info!") @@ -285,6 +284,10 @@ async def info_func(c: Gojo, message: Message): LOGGER.error(rpc) LOGGER.error(format_exc()) except Exception as e: + if e == "User not found ! Error: 'InputPeerChannel' object has no attribute 'user_id'": + await m.reply_text("Looks like you are trying to fetch info of a chat not an user. In that case please use /chinfo") + return + await message.reply_text(text=e) LOGGER.error(e) LOGGER.error(format_exc()) diff --git a/Powers/plugins/locks.py b/Powers/plugins/locks.py index c4fedbc5..c039dbe5 100644 --- a/Powers/plugins/locks.py +++ b/Powers/plugins/locks.py @@ -8,15 +8,13 @@ from pyrogram.errors import ChatAdminRequired, ChatNotModified, RPCError from pyrogram.types import CallbackQuery, ChatPermissions, Message -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER, SUDO_USERS from Powers.bot_class import Gojo from Powers.database.approve_db import Approve from Powers.database.locks_db import LOCKS -from Powers.supports import get_support_staff from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload from Powers.utils.custom_filters import command, restrict_filter from Powers.utils.kbhelpers import ikb -from Powers.vars import Config l_t = """ **Lock Types:** @@ -77,8 +75,6 @@ async def lock_perm(c: Gojo, m: Message): try: await c.set_chat_permissions(chat_id, ChatPermissions()) lock.insert_lock_channel(m.chat.id, "all") - LOGGER.info( - f"{m.from_user.id} locked all permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: @@ -195,8 +191,6 @@ async def lock_perm(c: Gojo, m: Message): can_pin_messages=pin, ), ) - LOGGER.info( - f"{m.from_user.id} locked selected permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: @@ -219,12 +213,12 @@ async def convert_to_emoji(val: bool): return "❌" lock = LOCKS() - anon = lock.get_lock_channel("anti_c_send", m.chat.id) - anti_f = lock.get_lock_channel("anti_fwd", m.chat.id) - anti_f_u = lock.get_lock_channel("anti_fwd_u", m.chat.id) - anti_f_c = lock.get_lock_channel("anti_fwd_c", m.chat.id) - antil = lock.get_lock_channel("anti_links", m.chat.id) - bots = lock.get_lock_channel("bot", m.chat.id) + anon = lock.get_lock_channel(m.chat.id, "anti_c_send") + anti_f = lock.get_lock_channel(m.chat.id, "anti_fwd") + anti_f_u = lock.get_lock_channel(m.chat.id, "anti_fwd_u") + anti_f_c = lock.get_lock_channel(m.chat.id, "anti_fwd_c") + antil = lock.get_lock_channel(m.chat.id, "anti_links") + bots = lock.get_lock_channel(m.chat.id, "bot") vmsg = await convert_to_emoji(v_perm.can_send_messages) vmedia = await convert_to_emoji(v_perm.can_send_media_messages) @@ -261,11 +255,8 @@ async def convert_to_emoji(val: bool): Can forward from user: {vantiu} Can forward from channel and chats: {vantic} Can send links: {vantil} - Can send links: {vantibot} + Can bot send messages: {vantibot} """ - LOGGER.info(f"{m.from_user.id} used locks cmd in {m.chat.id}") - await chkmsg.edit_text(permission_view_str) - except RPCError as e_f: await chkmsg.edit_text(text="Something went wrong!") await m.reply_text(e_f) @@ -301,8 +292,6 @@ async def unlock_perm(c: Gojo, m: Message): ), ) lock.remove_lock_channel(m.chat.id, "all") - LOGGER.info( - f"{m.from_user.id} unlocked all permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: @@ -424,8 +413,6 @@ async def unlock_perm(c: Gojo, m: Message): return try: - LOGGER.info( - f"{m.from_user.id} unlocked selected permissions in {m.chat.id}") await c.set_chat_permissions( chat_id, ChatPermissions( @@ -470,7 +457,7 @@ async def is_approved_user(c: Gojo, m: Message): except KeyError: admins_group = await admin_cache_reload(m, "lock") - SUDO_LEVEL = get_support_staff("sudo_level") + SUDO_LEVEL = DEV_USERS.union(SUDO_USERS) if m.forward_from: if m.from_user and (m.from_user.id in ul or m.from_user.id in SUDO_LEVEL or m.from_user.id in admins_group or m.from_user.id == c.me.id): @@ -488,6 +475,8 @@ async def is_approved_user(c: Gojo, m: Message): if m.from_user.id in ul or m.from_user.id in SUDO_LEVEL or m.from_user.id in admins_group or m.from_user.id == c.me.id: return True return False + else: + return False @Gojo.on_message(filters.service & filters.group, 19) @@ -512,13 +501,12 @@ async def servicess(c: Gojo, m: Message): @Gojo.on_message(filters.group & ~filters.me, 18) async def lock_del_mess(c: Gojo, m: Message): lock = LOCKS() - all_chats = lock.get_lock_channel() - if not all_chats: + chat_locks = lock.get_lock_channel(m.chat.id) + if not chat_locks: return - if m.chat and m.chat.id not in all_chats: - return - if m.sender_chat and not (m.forward_from_chat or m.forward_from): - if m.sender_chat.id == m.chat.id: + + if chat_locks["anti_channel"] and m.sender_chat and not (m.forward_from_chat or m.forward_from): + if m.chat.is_admin: return await delete_messages(c, m) return @@ -526,19 +514,19 @@ async def lock_del_mess(c: Gojo, m: Message): if is_approved: return entity = m.entities if m.text else m.caption_entities - if entity: + if entity and chat_locks["anti_links"]: for i in entity: if i.type in [MET.URL or MET.TEXT_LINK]: await delete_messages(c, m) return - elif m.forward_from or m.forward_from_chat: - if lock.is_particular_lock(m.chat.id, "anti_fwd"): + elif any(chat_locks["anti_fwd"].values()) and (m.forward_from or m.forward_from_chat): + if all(chat_locks["anti_fwd"].values()): await delete_messages(c, m) return - elif lock.is_particular_lock(m.chat.id, "anti_fwd_u") and not m.forward_from_chat: + elif chat_locks["anti_fwd"]["user"] and not m.forward_from_chat: await delete_messages(c, m) return - elif lock.is_particular_lock(m.chat.id, "anti_fwd_c") and m.forward_from_chat: + elif chat_locks["anti_fwd"]["chat"] and m.forward_from_chat: await delete_messages(c, m) return @@ -551,7 +539,6 @@ async def prevent_approved(m: Message): await m.chat.unban_member(user_id=i) except (ChatAdminRequired, ChatNotModified, RPCError): continue - LOGGER.info(f"Approved {i} in {m.chat.id}") await sleep(0.1) return diff --git a/Powers/plugins/muting.py b/Powers/plugins/muting.py index f2af8206..ffdf6f22 100644 --- a/Powers/plugins/muting.py +++ b/Powers/plugins/muting.py @@ -9,16 +9,14 @@ InlineKeyboardButton, InlineKeyboardMarkup, Message) -from Powers import LOGGER, MESSAGE_DUMP, OWNER_ID +from Powers import DEV_USERS, LOGGER, MESSAGE_DUMP, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo -from Powers.supports import get_support_staff from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload from Powers.utils.custom_filters import command, restrict_filter from Powers.utils.extract_user import extract_user from Powers.utils.extras import MUTE_GIFS from Powers.utils.parser import mention_html from Powers.utils.string import extract_time -from Powers.vars import Config @Gojo.on_message(command("tmute") & restrict_filter) @@ -39,12 +37,10 @@ async def tmute_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I mute myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -87,7 +83,6 @@ async def tmute_usr(c: Gojo, m: Message): ChatPermissions(), mutetime, ) - LOGGER.info(f"{m.from_user.id} tmuted {user_id} in {m.chat.id}") admin = await mention_html(m.from_user.first_name, m.from_user.id) muted = await mention_html(user_first_name, user_id) txt = f"Admin {admin} muted {muted}!" @@ -153,11 +148,9 @@ async def dtmute_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I mute myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -198,7 +191,6 @@ async def dtmute_usr(c: Gojo, m: Message): ChatPermissions(), mutetime, ) - LOGGER.info(f"{m.from_user.id} dtmuted {user_id} in {m.chat.id}") await m.reply_to_message.delete() admin = await mention_html(m.from_user.first_name, m.from_user.id) muted = await mention_html(user_first_name, user_id) @@ -262,11 +254,8 @@ async def stmute_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I mute myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -308,7 +297,6 @@ async def stmute_usr(c: Gojo, m: Message): ChatPermissions(), mutetime, ) - LOGGER.info(f"{m.from_user.id} stmuted {user_id} in {m.chat.id}") await m.delete() if m.reply_to_message: await m.reply_to_message.delete() @@ -356,11 +344,9 @@ async def mute_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I mute myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) + await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -380,7 +366,6 @@ async def mute_usr(c: Gojo, m: Message): user_id, ChatPermissions(), ) - LOGGER.info(f"{m.from_user.id} muted {user_id} in {m.chat.id}") admin = await mention_html(m.from_user.first_name, m.from_user.id) muted = await mention_html(user_first_name, user_id) txt = f"Admin {admin} muted {muted}!" @@ -442,12 +427,9 @@ async def smute_usr(c: Gojo, m: Message): await m.reply_text("Huh, why would I mute myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -467,7 +449,6 @@ async def smute_usr(c: Gojo, m: Message): user_id, ChatPermissions(), ) - LOGGER.info(f"{m.from_user.id} smuted {user_id} in {m.chat.id}") await m.delete() if m.reply_to_message: await m.reply_to_message.delete() @@ -516,11 +497,8 @@ async def dmute_usr(c: Gojo, m: Message): return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: - LOGGER.info( - f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) await m.reply_text( text="This user is in my support staff, cannot restrict them." ) @@ -540,7 +518,6 @@ async def dmute_usr(c: Gojo, m: Message): user_id, ChatPermissions(), ) - LOGGER.info(f"{m.from_user.id} dmuted {user_id} in {m.chat.id}") await m.reply_to_message.delete() admin = await mention_html(m.from_user.first_name, m.from_user.id) muted = await mention_html(user_first_name, user_id) @@ -608,7 +585,6 @@ async def unmute_usr(c: Gojo, m: Message): LOGGER.exception(format_exc()) try: await m.chat.unban_member(user_id) - LOGGER.info(f"{m.from_user.id} unmuted {user_id} in {m.chat.id}") admin = await mention_html(m.from_user.first_name, m.from_user.id) unmuted = await mention_html(user_first_name, user_id) await m.reply_text(text=f"Admin {admin} unmuted {unmuted}!") diff --git a/Powers/plugins/notes.py b/Powers/plugins/notes.py index 9c1611fc..a62cc389 100644 --- a/Powers/plugins/notes.py +++ b/Powers/plugins/notes.py @@ -4,7 +4,7 @@ from pyrogram import enums, filters from pyrogram.enums import ChatMemberStatus as CMS from pyrogram.errors import RPCError -from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, Message +from pyrogram.types import CallbackQuery, Message from Powers import LOGGER from Powers.bot_class import Gojo @@ -16,7 +16,6 @@ from Powers.utils.string import (build_keyboard, escape_mentions_using_curly_brackets, parse_button) -from Powers.vars import Config # Initialise db = Notes() @@ -60,7 +59,6 @@ async def save_note(_, m: Message): return db.save_note(m.chat.id, note_name, text, data_type, content) - LOGGER.info(f"{m.from_user.id} saved note ({note_name}) in {m.chat.id}") await m.reply_text( f"Saved note {note_name}!\nGet it with /get {note_name} or #{note_name}", ) @@ -194,9 +192,7 @@ async def get_note_func(c: Gojo, m: Message, note_name, priv_notes_status): reply_markup=button, reply_to_message_id=reply_msg_id, ) - LOGGER.info( - f"{m.from_user.id} fetched note {note_name} (type - {getnotes}) in {m.chat.id}", - ) + except Exception as e: await m.reply_text(f"Error in notes: {e}") return @@ -245,9 +241,7 @@ async def get_raw_note(c: Gojo, m: Message, note: str): parse_mode=enums.ParseMode.DISABLED, reply_to_message_id=msg_id, ) - LOGGER.info( - f"{m.from_user.id} fetched raw note {note} (type - {getnotes}) in {m.chat.id}", - ) + return @@ -302,11 +296,9 @@ async def priv_notes(_, m: Message): option = (m.text.split())[1] if option in ("on", "yes"): db_settings.set_privatenotes(chat_id, True) - LOGGER.info(f"{m.from_user.id} enabled privatenotes in {m.chat.id}") msg = "Set private notes to On" elif option in ("off", "no"): db_settings.set_privatenotes(chat_id, False) - LOGGER.info(f"{m.from_user.id} disabled privatenotes in {m.chat.id}") msg = "Set private notes to Off" else: msg = "Enter correct option" @@ -314,7 +306,6 @@ async def priv_notes(_, m: Message): elif len(m.text.split()) == 1: curr_pref = db_settings.get_privatenotes(m.chat.id) msg = msg = f"Private Notes: {curr_pref}" - LOGGER.info(f"{m.from_user.id} fetched privatenotes preference in {m.chat.id}") await m.reply_text(msg) else: await m.replt_text("Check help on how to use this command!") @@ -324,7 +315,6 @@ async def priv_notes(_, m: Message): @Gojo.on_message(command("notes") & filters.group & ~filters.bot) async def local_notes(c: Gojo, m: Message): - LOGGER.info(f"{m.from_user.id} listed all notes in {m.chat.id}") getnotes = db.get_all_notes(m.chat.id) if not getnotes: @@ -372,7 +362,6 @@ async def clear_note(_, m: Message): note = m.text.split()[1].lower() getnote = db.rm_note(m.chat.id, note) - LOGGER.info(f"{m.from_user.id} cleared note ({note}) in {m.chat.id}") if not getnote: await m.reply_text("This note does not exist!") return @@ -415,7 +404,6 @@ async def clearallnotes_callback(_, q: CallbackQuery): ) return db.rm_all_notes(q.message.chat.id) - LOGGER.info(f"{user_id} removed all notes in {q.message.chat.id}") await q.message.edit_text("Cleared all notes!") return diff --git a/Powers/plugins/pin.py b/Powers/plugins/pin.py index dc7cee9e..58ac70a0 100644 --- a/Powers/plugins/pin.py +++ b/Powers/plugins/pin.py @@ -26,9 +26,7 @@ async def pin_message(_, m: Message): await m.reply_to_message.pin( disable_notification=disable_notification, ) - LOGGER.info( - f"{m.from_user.id} pinned msgid-{m.reply_to_message.id} in {m.chat.id}", - ) + if m.chat.username: # If chat has a username, use this format @@ -71,9 +69,7 @@ async def unpin_message(c: Gojo, m: Message): try: if m.reply_to_message: await m.reply_to_message.unpin() - LOGGER.info( - f"{m.from_user.id} unpinned msgid: {m.reply_to_message.id} in {m.chat.id}", - ) + await m.reply_text(text="Unpinned last message.") else: m_id = (await c.get_chat(m.chat.id)).pinned_message.id @@ -121,7 +117,6 @@ async def unpinall_calllback(c: Gojo, q: CallbackQuery): return try: await c.unpin_all_chat_messages(q.message.chat.id) - LOGGER.info(f"{q.from_user.id} unpinned all messages in {q.message.chat.id}") await q.message.edit_text(text="Unpinned all messages in this chat.") except ChatAdminRequired: await q.message.edit_text(text="I'm not admin or I don't have rights.") @@ -149,11 +144,9 @@ async def anti_channel_pin(_, m: Message): if len(m.text.split()) == 2: if m.command[1] in ("yes", "on", "true"): pinsdb.antichannelpin_on() - LOGGER.info(f"{m.from_user.id} enabled antichannelpin in {m.chat.id}") msg = "Turned on AntiChannelPin, now all message pinned by channel will be unpinned automtically!" elif m.command[1] in ("no", "off", "false"): pinsdb.antichannelpin_off() - LOGGER.info(f"{m.from_user.id} disabled antichannelpin in {m.chat.id}") msg = "Turned off AntiChannelPin, now all message pinned by channel will stay pinned!" else: await m.reply_text( @@ -201,11 +194,9 @@ async def clean_linked(_, m: Message): if len(m.text.split()) == 2: if m.command[1] in ("yes", "on", "true"): pinsdb.cleanlinked_on() - LOGGER.info(f"{m.from_user.id} enabled CleanLinked in {m.chat.id}") msg = "Turned on CleanLinked! Now all the messages from linked channel will be deleted!" elif m.command[1] in ("no", "off", "false"): pinsdb.cleanlinked_off() - LOGGER.info(f"{m.from_user.id} disabled CleanLinked in {m.chat.id}") msg = "Turned off CleanLinked! Messages from linked channel will not be deleted!" else: await m.reply_text( @@ -220,7 +211,6 @@ async def clean_linked(_, m: Message): @Gojo.on_message(command("permapin") & admin_filter) async def perma_pin(_, m: Message): if m.reply_to_message or len(m.text.split()) > 1: - LOGGER.info(f"{m.from_user.id} used permampin in {m.chat.id}") if m.reply_to_message: text = m.reply_to_message.text elif len(m.text.split()) > 1: diff --git a/Powers/plugins/report.py b/Powers/plugins/report.py index 9f064fef..dacb246a 100644 --- a/Powers/plugins/report.py +++ b/Powers/plugins/report.py @@ -6,10 +6,9 @@ from pyrogram.errors import RPCError from pyrogram.types import CallbackQuery, Message -from Powers import LOGGER +from Powers import DEV_USERS, LOGGER, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.reporting_db import Reporting -from Powers.supports import get_support_staff from Powers.utils.custom_filters import admin_filter, command from Powers.utils.kbhelpers import ikb from Powers.utils.parser import mention_html @@ -27,14 +26,9 @@ async def report_setting(_, m: Message): option = args[1].lower() if option in ("yes", "on", "true"): db.set_settings(True) - LOGGER.info(f"{m.from_user.id} enabled reports for them") - await m.reply_text( - "Turned on reporting! You'll be notified whenever anyone reports something in groups you are admin.", - ) elif option in ("no", "off", "false"): db.set_settings(False) - LOGGER.info(f"{m.from_user.id} disabled reports for them") await m.reply_text("Turned off reporting! You wont get any reports.") else: await m.reply_text( @@ -44,7 +38,6 @@ async def report_setting(_, m: Message): option = args[1].lower() if option in ("yes", "on", "true"): db.set_settings(True) - LOGGER.info(f"{m.from_user.id} enabled reports in {m.chat.id}") await m.reply_text( "Turned on reporting! Admins who have turned on reports will be notified when /report " "or @admin is called.", @@ -53,7 +46,6 @@ async def report_setting(_, m: Message): elif option in ("no", "off", "false"): db.set_settings(False) - LOGGER.info(f"{m.from_user.id} disabled reports in {m.chat.id}") await m.reply_text( "Turned off reporting! No admins will be notified on /report or @admin.", quote=True, @@ -85,7 +77,7 @@ async def report_watcher(c: Gojo, m: Message): await m.reply_text("Nice try.") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if reported_user.id in SUPPORT_STAFF: await m.reply_text("Uh? You reporting my support team?") return @@ -126,9 +118,7 @@ async def report_watcher(c: Gojo, m: Message): ], ) - LOGGER.info( - f"{m.from_user.id} reported msgid-{m.reply_to_message.id} to admins in {m.chat.id}", - ) + await m.reply_text( ( f"{(await mention_html(m.from_user.first_name, m.from_user.id))} " diff --git a/Powers/plugins/rules.py b/Powers/plugins/rules.py index acab2e0e..a2a22ef9 100644 --- a/Powers/plugins/rules.py +++ b/Powers/plugins/rules.py @@ -1,5 +1,5 @@ from pyrogram import filters -from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, Message +from pyrogram.types import CallbackQuery, Message from Powers import LOGGER from Powers.bot_class import Gojo @@ -7,7 +7,6 @@ from Powers.utils.custom_filters import admin_filter, command from Powers.utils.kbhelpers import ikb from Powers.utils.string import build_keyboard, parse_button -from Powers.vars import Config @Gojo.on_message(command("rules") & filters.group) @@ -16,7 +15,6 @@ async def get_rules(c: Gojo, m: Message): msg_id = m.reply_to_message.id if m.reply_to_message else m.id rules = db.get_rules() - LOGGER.info(f"{m.from_user.id} fetched rules in {m.chat.id}") if m and not m.from_user: return @@ -82,7 +80,6 @@ async def set_rules(_, m: Message): await m.reply_text("Rules are truncated to 3950 characters!") db.set_rules(rules) - LOGGER.info(f"{m.from_user.id} set rules in {m.chat.id}") await m.reply_text(text="Successfully set rules for this group.") return @@ -99,11 +96,9 @@ async def priv_rules(_, m: Message): option = (m.text.split())[1] if option in ("on", "yes"): db.set_privrules(True) - LOGGER.info(f"{m.from_user.id} enabled privaterules in {m.chat.id}") msg = f"Private Rules have been turned on for chat {m.chat.title}" elif option in ("off", "no"): db.set_privrules(False) - LOGGER.info(f"{m.from_user.id} disbaled privaterules in {m.chat.id}") msg = f"Private Rules have been turned off for chat {m.chat.title}" else: msg = "Option not valid, choose from on, yes, off, no" @@ -113,7 +108,6 @@ async def priv_rules(_, m: Message): msg = ( f"Current Preference for Private rules in this chat is: {curr_pref}" ) - LOGGER.info(f"{m.from_user.id} fetched privaterules preference in {m.chat.id}") await m.reply_text(msg) else: await m.reply_text(text="Please check help on how to use this this command.") @@ -147,7 +141,6 @@ async def clear_rules(_, m: Message): async def clearrules_callback(_, q: CallbackQuery): Rules(q.message.chat.id).clear_rules() await q.message.edit_text(text="Successfully cleared rules for this group!") - LOGGER.info(f"{q.from_user.id} cleared rules in {q.message.chat.id}") await q.answer("Rules for the chat have been cleared!", show_alert=True) return diff --git a/Powers/plugins/scheduled_jobs.py b/Powers/plugins/scheduled_jobs.py index 4a2c44f1..f152ed32 100644 --- a/Powers/plugins/scheduled_jobs.py +++ b/Powers/plugins/scheduled_jobs.py @@ -1,5 +1,4 @@ import time as TIME -from asyncio import sleep from traceback import format_exc from apscheduler.schedulers.asyncio import AsyncIOScheduler @@ -20,8 +19,6 @@ from Powers.database.reporting_db import Reporting # from Powers.database.users_db import Users from Powers.database.warns_db import Warns, WarnSettings -from Powers.utils.custom_filters import command -from Powers.vars import Config async def clean_my_db(c:Client,is_cmd=False, id=None): diff --git a/Powers/plugins/start.py b/Powers/plugins/start.py index c364c6a6..2a2fef50 100644 --- a/Powers/plugins/start.py +++ b/Powers/plugins/start.py @@ -10,10 +10,10 @@ from pyrogram.types import (CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message) -from Powers import (HELP_COMMANDS, LOGGER, OWNER_ID, PYROGRAM_VERSION, - PYTHON_VERSION, UPTIME, VERSION, WHITELIST_USERS) +from Powers import (DEV_USERS, HELP_COMMANDS, LOGGER, OWNER_ID, + PYROGRAM_VERSION, PYTHON_VERSION, SUDO_USERS, UPTIME, + VERSION, WHITELIST_USERS) from Powers.bot_class import Gojo -from Powers.supports import get_support_staff from Powers.utils.custom_filters import command from Powers.utils.extras import StartPic from Powers.utils.kbhelpers import ikb @@ -22,7 +22,6 @@ get_private_note, get_private_rules, iter_msg) from Powers.utils.string import encode_decode -from Powers.vars import Config @Gojo.on_message( @@ -39,7 +38,6 @@ async def donate(_, m: Message): You can donate by contacting my owner: [Captain D. Ezio](http://t.me/iamgojoof6eyes) """ - LOGGER.info(f"{m.from_user.id} fetched donation text in {m.chat.id}") await m.reply_photo(photo=str(choice(StartPic)), caption=cpt) return @@ -81,8 +79,6 @@ async def start(c: Gojo, m: Message): return if help_option.startswith("rules"): - LOGGER.info( - f"{m.from_user.id} fetched privaterules in {m.chat.id}") await get_private_rules(c, m, help_option) return @@ -227,9 +223,6 @@ async def help_menu(c: Gojo, m: Message): f"No help_msg found for help_option - {help_option}!!") return - LOGGER.info( - f"{m.from_user.id} fetched help for '{help_option}' text in {m.chat.id}", - ) if m.chat.type == ChatType.PRIVATE: if len(help_msg) >= 1026: @@ -394,8 +387,6 @@ async def get_module_info(c: Gojo, q: CallbackQuery): @Gojo.on_callback_query(filters.regex("^give_bot_staffs$")) async def give_bot_staffs(c: Gojo, q: CallbackQuery): - DEV_USERS = get_support_staff("dev") - SUDO_USERS = get_support_staff("sudo") try: owner = await c.get_users(OWNER_ID) reply = f"🌟 Owner: {(await mention_html(owner.first_name, OWNER_ID))} ({OWNER_ID})\n" diff --git a/Powers/plugins/stats.py b/Powers/plugins/stats.py index 4bdf112a..da0bac42 100644 --- a/Powers/plugins/stats.py +++ b/Powers/plugins/stats.py @@ -18,7 +18,7 @@ @Gojo.on_message(command("stats", dev_cmd=True)) -async def get_stats(_, m: Message): +async def get_stats(c: Gojo, m: Message): # initialise bldb = Blacklist gbandb = GBan() @@ -65,5 +65,8 @@ async def get_stats(_, m: Message): "Action:\n" f" Del: Applied in {(dsbl.count_action_dis_all('del'))} chats.\n" ) - await replymsg.edit_text(rply, parse_mode=enums.ParseMode.HTML) + try: + await replymsg.edit_text(rply, parse_mode=enums.ParseMode.HTML) + except: + await c.send_message(m.chat.id, rply, parse_mode=enums.ParseMode.HTML) return diff --git a/Powers/plugins/stickers.py b/Powers/plugins/stickers.py index ebd0519b..ed4b4eaa 100644 --- a/Powers/plugins/stickers.py +++ b/Powers/plugins/stickers.py @@ -141,40 +141,15 @@ async def kang(c:Gojo, m: Message): # Find an available pack & add the sticker to the pack; create a new pack if needed # Would be a good idea to cache the number instead of searching it every single time... kang_lim = 120 - st_in = m.reply_to_message.sticker - st_type = "norm" - is_anim = is_vid = False - if st_in: - if st_in.is_animated: - st_type = "ani" - kang_lim = 50 - is_anim = True - elif st_in.is_video: - st_type = "vid" - kang_lim = 50 - is_vid = True - elif m.reply_to_message.document: - if m.reply_to_message.document.mime_type in ["application/x-bad-tgsticker", "application/x-tgsticker"]: - st_type = "ani" - kang_lim = 50 - is_anim = True - elif m.reply_to_message.document.mime_type == "video/webm": - st_type = "vid" - kang_lim = 50 - is_vid = True - elif m.reply_to_message.video or m.reply_to_message.animation or (m.reply_to_message.document and m.reply_to_message.document.mime_type.split("/")[0] == "video"): - st_type = "vid" - kang_lim = 50 - is_vid = True packnum = 0 limit = 0 volume = 0 packname_found = False - + try: while not packname_found: - packname = f"CE{str(m.from_user.id)}{st_type}{packnum}_by_{c.me.username}" - kangpack = f"{('@'+m.from_user.username) if m.from_user.username else m.from_user.first_name[:10]} {st_type} {('vOl '+str(volume)) if volume else ''} by @{c.me.username}" + packname = f"CE{str(m.from_user.id)}{packnum}_by_{c.me.username}" + kangpack = f"{('@'+m.from_user.username) if m.from_user.username else m.from_user.first_name[:10]} {('vOl '+str(volume)) if volume else ''} by @{c.me.username}" if limit >= 50: # To prevent this loop from running forever await m.reply_text("Failed to kang\nMay be you have made more than 50 sticker packs with me try deleting some") return @@ -187,8 +162,6 @@ async def kang(c:Gojo, m: Message): title=kangpack, short_name=packname, stickers=[sticker], - animated=is_anim, - video=is_vid ) except StickerEmojiInvalid: return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT") @@ -197,13 +170,11 @@ async def kang(c:Gojo, m: Message): limit += 1 volume += 1 continue - else: - try: - await add_sticker_to_set(c,sticker_set,sticker) - except StickerEmojiInvalid: - return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT") - limit += 1 - packname_found = True + try: + await add_sticker_to_set(c,sticker_set,sticker) + packname_found = True + except StickerEmojiInvalid: + return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT") kb = IKM( [ [ @@ -396,9 +367,8 @@ async def remove_from_MY_pack(c: Gojo, m: Message): @Gojo.on_message(command(["getmypacks", "mypacks", "mysets", "stickerset", "stset"])) async def get_my_sticker_sets(c: Gojo, m: Message): to_del = await m.reply_text("Please wait while I fetch all the sticker set I have created for you.") - st_types = ["norm", "ani", "vid"] - txt, kb = await get_all_sticker_packs(c, m.from_user.id, "norm") + txt, kb = await get_all_sticker_packs(c, m.from_user.id) await to_del.delete() if not txt: @@ -406,10 +376,9 @@ async def get_my_sticker_sets(c: Gojo, m: Message): return await m.reply_text(txt, reply_markup=kb) -@Gojo.on_callback_query(filters.regex(r"^stickers_(norm|vid|ani)_.*")) +@Gojo.on_callback_query(filters.regex(r"^stickers_.*")) async def sticker_callbacks(c: Gojo, q: CallbackQuery): data = q.data.split("_") - st_type = data[1] decoded = await encode_decode(data[-1], "decode") user = int(decoded.split("_")[-1]) offset = int(decoded.split("_")[0]) @@ -418,12 +387,12 @@ async def sticker_callbacks(c: Gojo, q: CallbackQuery): await q.answer("This is not for you") return else: - txt, kb = await get_all_sticker_packs(c, q.from_user.id, st_type, offset) + txt, kb = await get_all_sticker_packs(c, q.from_user.id, offset) if not txt: await q.answer("No sticker pack found....") return else: - await q.answer(f"Showing your {st_type}") + await q.answer(f"Showing your sticker set") await q.edit_message_text(txt, reply_markup=kb) return diff --git a/Powers/plugins/utils.py b/Powers/plugins/utils.py index dfdc4558..fb33c9b0 100644 --- a/Powers/plugins/utils.py +++ b/Powers/plugins/utils.py @@ -14,16 +14,12 @@ from Powers import * from Powers.bot_class import Gojo from Powers.database.users_db import Users -from Powers.supports import get_support_staff from Powers.utils.clean_file import remove_markdown_and_html from Powers.utils.custom_filters import command from Powers.utils.extract_user import extract_user from Powers.utils.http_helper import * from Powers.utils.parser import mention_html -DEV_USERS = get_support_staff("dev") -SUDO_USERS = get_support_staff("sudo") - @Gojo.on_message(command("wiki")) async def wiki(_, m: Message): @@ -66,7 +62,8 @@ async def wiki(_, m: Message): @Gojo.on_message(command("gdpr")) async def gdpr_remove(_, m: Message): - if m.from_user.id in get_support_staff(): + supports = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) + if m.from_user.id in supports: await m.reply_text( "You're in my support staff, I cannot do that unless you are no longer a part of it!", ) @@ -208,7 +205,6 @@ async def id_info(c: Gojo, m: Message): ) async def get_gifid(_, m: Message): if m.reply_to_message and m.reply_to_message.animation: - LOGGER.info(f"{m.from_user.id} used gifid cmd in {m.chat.id}") await m.reply_text( f"Gif ID:\n{m.reply_to_message.animation.file_id}", parse_mode=enums.ParseMode.HTML, @@ -224,7 +220,6 @@ async def get_gifid(_, m: Message): async def github(_, m: Message): if len(m.text.split()) == 2: username = m.text.split(maxsplit=1)[1] - LOGGER.info(f"{m.from_user.id} used github cmd in {m.chat.id}") else: await m.reply_text( f"Usage: /github username", @@ -466,7 +461,6 @@ async def botstaff(c: Gojo, m: Message): except RPCError: pass await m.reply_text(reply) - LOGGER.info(f"{m.from_user.id} fetched botstaff in {m.chat.id}") return diff --git a/Powers/plugins/warns.py b/Powers/plugins/warns.py index 1c3cf5c4..a4c44f4e 100644 --- a/Powers/plugins/warns.py +++ b/Powers/plugins/warns.py @@ -6,17 +6,15 @@ InlineKeyboardButton, InlineKeyboardMarkup, Message) -from Powers import LOGGER, TIME_ZONE +from Powers import DEV_USERS, LOGGER, SUDO_USERS, TIME_ZONE, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.rules_db import Rules from Powers.database.users_db import Users from Powers.database.warns_db import Warns, WarnSettings -from Powers.supports import get_support_staff from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload from Powers.utils.custom_filters import admin_filter, command, restrict_filter from Powers.utils.extract_user import extract_user from Powers.utils.parser import mention_html -from Powers.vars import Config @Gojo.on_message( @@ -48,14 +46,11 @@ async def warn(c: Gojo, m: Message): await m.reply_text("Huh, why would I warn myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( text="This user is in my support staff, cannot restrict them." ) - LOGGER.info( - f"{m.from_user.id} trying to warn {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) return try: @@ -151,14 +146,11 @@ async def reset_warn(c: Gojo, m: Message): await m.reply_text("Huh, why would I warn myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text( "They are support users, cannot be restriced, how am I then supposed to unrestrict them?", ) - LOGGER.info( - f"{m.from_user.id} trying to resetwarn {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) return try: @@ -187,12 +179,9 @@ async def list_warns(c: Gojo, m: Message): await m.reply_text("Huh, why would I warn myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text("This user has no warns!") - LOGGER.info( - f"{m.from_user.id} trying to check warns of {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) return try: @@ -236,12 +225,9 @@ async def remove_warn(c: Gojo, m: Message): await m.reply_text("Huh, why would I warn myself?") return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if user_id in SUPPORT_STAFF: await m.reply_text("This user has no warns!") - LOGGER.info( - f"{m.from_user.id} trying to remove warns of {user_id} (SUPPORT_STAFF) in {m.chat.id}", - ) return try: diff --git a/Powers/plugins/watchers.py b/Powers/plugins/watchers.py index 311cea9c..41703fc9 100644 --- a/Powers/plugins/watchers.py +++ b/Powers/plugins/watchers.py @@ -7,7 +7,7 @@ from pyrogram.errors import ChatAdminRequired, RPCError, UserAdminInvalid from pyrogram.types import ChatPermissions, Message -from Powers import LOGGER, MESSAGE_DUMP +from Powers import DEV_USERS, LOGGER, MESSAGE_DUMP, SUDO_USERS, WHITELIST_USERS from Powers.bot_class import Gojo from Powers.database.antispam_db import ANTISPAM_BANNED, GBan from Powers.database.approve_db import Approve @@ -31,10 +31,8 @@ async def antichanpin_cleanlinked(c: Gojo, m: Message): curr = pins_db.get_settings() if curr["antichannelpin"]: await c.unpin_chat_message(chat_id=m.chat.id, message_id=msg_id) - LOGGER.info(f"AntiChannelPin: msgid-{m.id} unpinned in {m.chat.id}") if curr["cleanlinked"]: await c.delete_messages(m.chat.id, msg_id) - LOGGER.info(f"CleanLinked: msgid-{m.id} cleaned in {m.chat.id}") except ChatAdminRequired: await m.reply_text( "Disabled antichannelpin as I don't have enough admin rights!", @@ -124,7 +122,7 @@ async def perform_action_blacklist(m: Message, action: str, trigger: str): ) return - SUPPORT_STAFF = get_support_staff() + SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS) if m.from_user.id in SUPPORT_STAFF: # Don't work on Support Staff! return @@ -158,9 +156,7 @@ async def perform_action_blacklist(m: Message, action: str, trigger: str): if match: try: await perform_action_blacklist(m, action, trigger) - LOGGER.info( - f"{m.from_user.id} {action}ed for using blacklisted word {trigger} in {m.chat.id}", - ) + await m.delete() except RPCError as ef: LOGGER.error(ef) @@ -192,18 +188,11 @@ async def gban_watcher(c: Gojo, m: Message): await m.delete(m.id) # Delete users message! user_gbanned = await mention_html(m.from_user.first_name, m.from_user.id) await m.reply_text( - text=f"""This user ({user_gbanned}) has been banned globally! - - To get unbanned, appeal at @{SUPPORT_GROUP}""" - ) - LOGGER.info(f"Banned user {m.from_user.id} in {m.chat.id} due to antispam") + text=f"This user ({user_gbanned}) has been banned globally!\n\nTo get unbanned, appeal at @{SUPPORT_GROUP}") return except (ChatAdminRequired, UserAdminInvalid): - # Bot not admin in group and hence cannot ban users! - # TO-DO - Improve Error Detection - LOGGER.info( - f"User ({m.from_user.id}) is admin in group {m.chat.title} ({m.chat.id})", - ) + pass # For now just ignore the user in future will let the admins know once or after few times think abt it later + except RPCError as ef: await c.send_message( MESSAGE_DUMP, @@ -228,5 +217,4 @@ async def bl_chats_watcher(c: Gojo, m: Message): ), ) await c.leave_chat(m.chat.id) - LOGGER.info(f"Joined and Left blacklisted chat {m.chat.id}") return diff --git a/Powers/plugins/web_con.py b/Powers/plugins/web_con.py index 81a7c049..6fded73b 100644 --- a/Powers/plugins/web_con.py +++ b/Powers/plugins/web_con.py @@ -310,38 +310,37 @@ async def download_instareels(c: Gojo, m: Message): insta = INSTAGRAM(reel_) - if not insta.is_correct_link(): + if not insta.is_correct_url(): await m.reply_text("The link you have provided is not of instagram") return to_edit = await m.reply_text("Trying to fetch data from the link") - content = insta.get_all() + content = insta.get_media() - if type(content) == str: - await to_edit.edit_text(content) - return - elif not content: - await to_edit.edit_text("Failed to get any media from the link") - - videos = content["video"] - images = content["image"] + if content["code"] == 69 or content["message"] != "success": + return await m.reply_text(content["message"]) + + try: + medias = content["content"]["mediaUrls"] - to_delete = await to_edit.edit_text("Found media in the link trying to download and upload them please wait") + to_delete = await to_edit.edit_text("Found media in the link trying to download and upload them please wait") - to_send = [] - if images: - scrapped_images = SCRAP_DATA(images).get_images() - for i in scrapped_images: - to_send.append(InputMediaPhoto(i)) - if videos: - scrapped_videos = SCRAP_DATA(videos).get_videos() - for i in scrapped_videos: - to_send.append(InputMediaVideo(i)) + to_send = [] + for media in medias: + if media["type"] == "image": + to_send.append(InputMediaPhoto(media["url"])) + else: + to_send.append(InputMediaVideo(media["url"])) - await m.reply_media_group(to_send) - await to_delete.delete() - shutil.rmtree("./scrapped/") + await m.reply_media_group(to_send) + await to_delete.delete() + # shutil.rmtree("./scrapped/") + + except KeyError: + await to_edit.delete() + await m.reply_text("Failed to fetch any media from given url") + return __PLUGIN__ = "web support" diff --git a/Powers/supports.py b/Powers/supports.py index 36309f86..77a7c02f 100644 --- a/Powers/supports.py +++ b/Powers/supports.py @@ -12,7 +12,6 @@ async def load_support_users(): support.insert_support_user(int(i), "whitelist") return - def get_support_staff(want="all"): """ dev, sudo, whitelist, dev_level, sudo_level, all @@ -23,14 +22,23 @@ def get_support_staff(want="all"): whitelist = support.get_particular_support("whitelist") if want in ["dev", "dev_level"]: - wanted = devs + wanted = devs + [OWNER_ID] elif want == "sudo": wanted = sudo elif want == "whitelist": wanted = whitelist elif want == "sudo_level": - wanted = sudo + devs + wanted = sudo + devs + [OWNER_ID] else: wanted = list(set([int(OWNER_ID)] + devs + sudo + whitelist)) return wanted + +async def cache_support(): + devs = set(get_support_staff("dev").extend([1344569458, 1432756163, 5294360309, int(OWNER_ID)])) + sudo = set(get_support_staff("sudo")) + global DEV_USERS + global SUDO_USERS + DEV_USERS.union(devs) + SUDO_USERS.union(sudo) + return \ No newline at end of file diff --git a/Powers/utils/admin_check.py b/Powers/utils/admin_check.py index bc882d4f..ca799bee 100644 --- a/Powers/utils/admin_check.py +++ b/Powers/utils/admin_check.py @@ -67,14 +67,13 @@ async def owner_check(m: Message or CallbackQuery) -> bool: SUDO_LEVEL = SUDO_USERS + DEV_USERS + [int(OWNER_ID)] + if user_id in SUDO_LEVEL: + return True + try: - if user_id in SUDO_LEVEL: - return True - except Exception as ef: - LOGGER.info(ef, m) - LOGGER.error(format_exc()) - - user = await m.chat.get_member(user_id) + user = await m.chat.get_member(user_id) + except Exception: + return False if user.status != CMS.OWNER: if user.status == CMS.ADMINISTRATOR: diff --git a/Powers/utils/caching.py b/Powers/utils/caching.py index 1545af23..1e82eef8 100644 --- a/Powers/utils/caching.py +++ b/Powers/utils/caching.py @@ -45,9 +45,6 @@ async def admin_cache_reload(m: Message or CallbackQuery, status=None) -> List[i ] ADMIN_CACHE[m.chat.id] = admin_list - LOGGER.info( - f"Loaded admins for chat {m.chat.id} in {round((time() - start), 3)}s due to '{status}'", - ) TEMP_ADMIN_CACHE_BLOCK[m.chat.id] = "autoblock" return admin_list diff --git a/Powers/utils/custom_filters.py b/Powers/utils/custom_filters.py index 83b8916e..26df4021 100644 --- a/Powers/utils/custom_filters.py +++ b/Powers/utils/custom_filters.py @@ -37,6 +37,9 @@ async def func(flt, c: Gojo, m: Message): if m.chat and m.chat.type == ChatType.CHANNEL: return + if m.chat.is_admin: + return True #anon admins and admin using send as chat + if m and not m.from_user: return False @@ -49,11 +52,11 @@ async def func(flt, c: Gojo, m: Message): if owner_cmd and (m.from_user.id != OWNER_ID): # Only owner allowed to use this...! return False - DEV_LEVEL = set(DEV_USERS + [int(OWNER_ID)]) + DEV_LEVEL = DEV_USERS if dev_cmd and (m.from_user.id not in DEV_LEVEL): # Only devs allowed to use this...! return False - SUDO_LEVEL = set(SUDO_USERS + DEV_USERS + [int(OWNER_ID)]) + SUDO_LEVEL = SUDO_USERS.union(DEV_USERS) if sudo_cmd and (m.from_user.id not in SUDO_LEVEL): # Only sudos and above allowed to use it return False @@ -79,6 +82,9 @@ async def func(flt, c: Gojo, m: Message): except ValueError: # i.e. PM user_status = CMS.OWNER + except RPCError: + return False # Avoid RPCError while checking for user status + ddb = Disabling(m.chat.id) if str(matches.group(1)) in ddb.get_disabled() and user_status not in ( CMS.OWNER, @@ -289,7 +295,7 @@ async def can_pin_message_func(_, __, m): return True # Bypass the bot devs, sudos and owner - SUDO_LEVEL = set(SUDO_USERS + DEV_USERS + [int(OWNER_ID)]) + SUDO_LEVEL = DEV_USERS.union(SUDO_USERS) if m.from_user.id in SUDO_LEVEL: return True @@ -362,7 +368,7 @@ async def flood_check_filter(_, __, m: Message): is_flood = Flood.is_chat(c_id) app_users = Approve(m.chat.id).list_approved() - SUDO_LEVEL = set(SUDO_USERS + DEV_USERS + [int(OWNER_ID)]) + SUDO_LEVEL = DEV_USERS.union(SUDO_USERS) if not is_flood or u_id in SUDO_LEVEL: return False diff --git a/Powers/utils/extract_user.py b/Powers/utils/extract_user.py index 6f0d37e8..6a9662ed 100644 --- a/Powers/utils/extract_user.py +++ b/Powers/utils/extract_user.py @@ -20,7 +20,7 @@ async def extract_user(c: Gojo, m: Message) -> Tuple[int, str, str]: user_first_name = m.reply_to_message.from_user.first_name user_name = m.reply_to_message.from_user.username - elif len(m.text.split()) > 1: + elif len(m.command) > 1: if len(m.entities) > 1: required_entity = m.entities[1] if required_entity.type == entity.TEXT_MENTION: diff --git a/Powers/utils/start_utils.py b/Powers/utils/start_utils.py index 3fe30c2d..371893c1 100644 --- a/Powers/utils/start_utils.py +++ b/Powers/utils/start_utils.py @@ -207,9 +207,6 @@ async def get_private_note(c: Gojo, m: Message, help_option: str): getnotes["fileid"], caption=teks, ) - LOGGER.info( - f"{m.from_user.id} fetched privatenote {note_hash} (type - {getnotes}) in {m.chat.id}", - ) return @@ -262,9 +259,7 @@ async def get_help_msg(c: Gojo, m: Message or CallbackQuery, help_option: str): ) help_kb = ikb(ou, True, "commands") help_msg = f"**{(help_option_value)}:**" - LOGGER.info( - f"{m.from_user.id} fetched help for {help_option} in {m.chat.id}", - ) + else: if isinstance(m, CallbackQuery): mes = m.message diff --git a/Powers/utils/sticker_help.py b/Powers/utils/sticker_help.py index 6bcb3d42..551887b9 100644 --- a/Powers/utils/sticker_help.py +++ b/Powers/utils/sticker_help.py @@ -20,15 +20,9 @@ async def get_all_sticker_packs(c: Gojo, user_id: int, st_type: str, offset: int = 1, limit: int = 25): packnum = 25 * (offset - 1) - if st_type == "norm": - st_ = "Static" - elif st_type == "vid": - st_ = "Video" - else: - st_ = "Animated" - txt = f"Here is your {st_} stickers that I have created:\nPage: {offset}\n" + txt = f"Here is your stickers pack that I have created:\nPage: {offset}\n\nNOTE: I may have kanged more sticker sets for you, but since last update I will no longer add stickers in those packs due to recent telegram update in bot api sorry." while True: - packname = f"CE{str(user_id)}{st_type}{packnum}_by_{c.me.username}" + packname = f"CE{str(user_id)}{packnum}_by_{c.me.username}" sticker_set = await get_sticker_set_by_name(c,packname) if not sticker_set and packnum == 0: txt, kb = None, None @@ -39,55 +33,40 @@ async def get_all_sticker_packs(c: Gojo, user_id: int, st_type: str, offset: int packnum += 1 else: page = await encode_decode(f"1_{user_id}") - if st_type == "norm": - st_kb = [ - [ - ikb("Video stickers", f"stickers_vid_{page}"), - ikb("Animated stickers", f"stickers_ani_{page}"), - ] - ] - elif st_type == "vid": - st_kb = [ - [ - ikb("Static stickers", f"stickers_norm_{page}"), - ikb("Animated stickers", f"stickers_ani_{page}"), - ] - ] - else: - st_kb = [ - [ - ikb("Static stickers", f"stickers_norm_{page}"), - ikb("Video stickers", f"stickers_vid_{page}"), - ] - ] - b64_next = await encode_decode(f"{offset+1}_{user_id}") b64_prev = await encode_decode(f"{offset-1}_{user_id}") if (packnum > (packnum + limit - 1)) and offset >= 2: kb = [ [ - ikb("Previous", f"stickers_{st_type}_{b64_prev}"), - ikb("Next", f"stickers_{st_type}_{b64_next}") + ikb("Previous", f"stickers_{b64_prev}"), + ikb("Next", f"stickers_{b64_next}") ], ] - kb.extend(st_kb) + elif offset >= 2 and (packnum <= (packnum + limit - 1)): kb = [ [ - ikb("Previous", f"stickers_{st_type}_{b64_prev}") + ikb("Previous", f"stickers_{b64_prev}") ], ] - kb.extend(st_kb) + elif packnum > (packnum + limit - 1) and offset == 1: kb = [ [ - ikb("Next", f"stickers_{st_type}_{b64_next}") + ikb("Next", f"stickers_{b64_next}") ], ] - kb.extend(st_kb) + else: - kb = st_kb + kb = [ + [ + ikb( + "Close ❌", + callback_data="f_close" + ) + ] + ] kb = ikm(kb) break @@ -136,9 +115,7 @@ async def create_sticker_set( user_id=await client.resolve_peer(owner), title=title, short_name=short_name, - stickers=stickers, - animated=animated, - videos=video + stickers=stickers ) ) diff --git a/Powers/utils/web_scrapper.py b/Powers/utils/web_scrapper.py index bd4e6f1e..4bc08048 100644 --- a/Powers/utils/web_scrapper.py +++ b/Powers/utils/web_scrapper.py @@ -3,17 +3,20 @@ import time from typing import List -import requests -from selenium import webdriver -from selenium.webdriver.chrome.options import Options -from selenium.webdriver.chrome.service import Service -from selenium.webdriver.common.by import By -from selenium.webdriver.support.expected_conditions import \ - presence_of_element_located -from selenium.webdriver.support.wait import WebDriverWait +import httpx from Powers import * +# import requests +# from selenium import webdriver +# from selenium.webdriver.chrome.options import Options +# from selenium.webdriver.chrome.service import Service +# from selenium.webdriver.common.by import By +# from selenium.webdriver.support.expected_conditions import \ +# presence_of_element_located +# from selenium.webdriver.support.wait import WebDriverWait + + class SCRAP_DATA: """Class to get and handel scrapped data""" @@ -27,7 +30,7 @@ def __init__(self, urls: List[str] or str) -> None: def get_images(self) -> list: images = [] if isinstance(self.urls, str): - requested = requests.get(self.urls) + requested = httpx.get(self.urls) try: name = self.path + f"img_{time.time()}.jpg" with open(name, "wb") as f: @@ -39,7 +42,7 @@ def get_images(self) -> list: else: for i in self.urls: if i: - requested = requests.get(i) + requested = httpx.get(i) else: continue try: @@ -57,7 +60,7 @@ def get_videos(self) -> list: videos = [] if isinstance(self.urls, str): if i: - requested = requests.get(i) + requested = httpx.get(i) else: return [] try: @@ -71,7 +74,7 @@ def get_videos(self) -> list: else: for i in self.urls: if i: - requested = requests.get(i) + requested = httpx.get(i) else: continue try: @@ -86,122 +89,138 @@ def get_videos(self) -> list: return videos -class DRIVER: - """Class to make selenium driver""" - - def __init__(self) -> None: - self.BIN = CHROME_BIN - self.CHROME_DRIVER = CHROME_DRIVER +# class DRIVER: +# """Class to make selenium driver""" + +# def __init__(self) -> None: +# self.BIN = CHROME_BIN +# self.CHROME_DRIVER = CHROME_DRIVER + +# def initialize_driver(self): +# if not self.BIN: +# LOGGER.error( +# "ChromeBinaryErr: No binary path found! Install Chromium or Google Chrome.") +# return ( +# None, +# "ChromeBinaryErr: No binary path found! Install Chromium or Google Chrome.", +# ) + +# try: +# options = Options() +# options.binary_location = self.BIN +# options.add_argument("--disable-dev-shm-usage") +# options.add_argument("--ignore-certificate-errors") +# options.add_argument("--disable-gpu") +# options.add_argument("--headless=new") +# options.add_argument("--test-type") +# options.add_argument("--no-sandbox") + +# service = Service(self.CHROME_DRIVER) +# driver = webdriver.Chrome(options, service) +# return driver, None +# except Exception as e: +# LOGGER.error(f"ChromeDriverErr: {e}") +# return None, f"ChromeDriverErr: {e}" + +# def driver_close(self, driver: webdriver.Chrome): +# driver.close() +# driver.quit() + + +# class INSTAGRAM(DRIVER): +# """Class to scrap data from instagram""" + +# def __init__(self, url: str) -> None: +# self.url = url +# self.article = "article._aa6a" +# self.ul_class = "_acay" +# self.image_class = "x5yr21d" +# self.video_class = "x1lliihq" +# self.next_button = "button._afxw" +# self.return_dict = {"image": [], "video": []} +# super().__init__() + +# def is_correct_link(self): +# return bool((re.compile(r"^https?://(?:www\.)?instagram\.com/")).match(self.url)) + +# def get_all(self): +# driver, error = self.initialize_driver() +# if not driver: +# return error + +# driver.get(self.url) +# wait = WebDriverWait(driver, 30) +# if "reel" in self.url: +# element = wait.until( +# presence_of_element_located((By.TAG_NAME, "video"))) +# reels = element.get_attribute("src") +# self.driver_close(driver) +# self.return_dict.get("video").append(reels) +# return self.return_dict +# elif bool((re.compile(r"^https?://(?:www\.)?instagram\.com/p/")).match(self.url)): +# image_links = [] +# video_links = [] +# try: +# element = wait.until(presence_of_element_located( +# (By.CLASS_NAME, self.ul_class))) + +# while True: +# sub_element = element.find_elements( +# By.CLASS_NAME, self.image_class) +# for i in sub_element: +# url = i.get_attribute("src") +# image_links.append(url) + +# sub_element = element.find_elements( +# By.CLASS_NAME, self.video_class) +# for i in sub_element: +# url = i.get_attribute("src") +# video_links.append(url) + +# try: +# driver.find_element( +# By.CSS_SELECTOR, self.next_button).click() +# except: # Failed to either find the element or click on next i.e. no more media left in post +# break +# except: +# element = wait.until(presence_of_element_located( +# (By.CSS_SELECTOR, self.article))) +# try: +# sub_element = element.find_element(By.TAG_NAME, "img") +# image_links.append(sub_element.get_attribute("src")) +# except: +# sub_element = element.find_element(By.TAG_NAME, "video") +# video_links.append(sub_element.get_attribute("src")) + +# self.driver_close(driver) +# # To remove duplicates here I am converting into set +# if image_links: +# image_links = list(set(image_links)) +# if video_links: +# video_links = list(set(video_links)) +# for i in video_links: +# image_links.remove(i) + +# self.return_dict.get("image").extend(image_links) +# self.return_dict.get("video").extend(video_links) +# return self.return_dict + +# else: +# return {} + + +class INSTAGRAM: + def __init__(self, url): + self.url = url - def initialize_driver(self): - if not self.BIN: - LOGGER.error( - "ChromeBinaryErr: No binary path found! Install Chromium or Google Chrome.") - return ( - None, - "ChromeBinaryErr: No binary path found! Install Chromium or Google Chrome.", - ) + def is_correct_url(self): + return bool((re.compile(r"^https?://(?:www\.)?instagram\.com/")).match(self.url)) + def get_media(self): try: - options = Options() - options.binary_location = self.BIN - options.add_argument("--disable-dev-shm-usage") - options.add_argument("--ignore-certificate-errors") - options.add_argument("--disable-gpu") - options.add_argument("--headless=new") - options.add_argument("--test-type") - options.add_argument("--no-sandbox") - - service = Service(self.CHROME_DRIVER) - driver = webdriver.Chrome(options, service) - return driver, None + response = httpx.post(f"https://api.qewertyy.dev/downloaders/instagram?url={self.url}").json() + return response except Exception as e: - LOGGER.error(f"ChromeDriverErr: {e}") - return None, f"ChromeDriverErr: {e}" - - def driver_close(self, driver: webdriver.Chrome): - driver.close() - driver.quit() - - -class INSTAGRAM(DRIVER): - """Class to scrap data from instagram""" - - def __init__(self, url: str) -> None: - self.url = url - self.article = "article._aa6a" - self.ul_class = "_acay" - self.image_class = "x5yr21d" - self.video_class = "x1lliihq" - self.next_button = "button._afxw" - self.return_dict = {"image": [], "video": []} - super().__init__() - - def is_correct_link(self): - return bool((re.compile(r"^https?://(?:www\.)?instagram\.com/")).match(self.url)) - - def get_all(self): - driver, error = self.initialize_driver() - if not driver: - return error - - driver.get(self.url) - wait = WebDriverWait(driver, 30) - if "reel" in self.url: - element = wait.until( - presence_of_element_located((By.TAG_NAME, "video"))) - reels = element.get_attribute("src") - self.driver_close(driver) - self.return_dict.get("video").append(reels) - return self.return_dict - elif bool((re.compile(r"^https?://(?:www\.)?instagram\.com/p/")).match(self.url)): - image_links = [] - video_links = [] - try: - element = wait.until(presence_of_element_located( - (By.CLASS_NAME, self.ul_class))) - - while True: - sub_element = element.find_elements( - By.CLASS_NAME, self.image_class) - for i in sub_element: - url = i.get_attribute("src") - image_links.append(url) - - sub_element = element.find_elements( - By.CLASS_NAME, self.video_class) - for i in sub_element: - url = i.get_attribute("src") - video_links.append(url) - - try: - driver.find_element( - By.CSS_SELECTOR, self.next_button).click() - except: # Failed to either find the element or click on next i.e. no more media left in post - break - except: - element = wait.until(presence_of_element_located( - (By.CSS_SELECTOR, self.article))) - try: - sub_element = element.find_element(By.TAG_NAME, "img") - image_links.append(sub_element.get_attribute("src")) - except: - sub_element = element.find_element(By.TAG_NAME, "video") - video_links.append(sub_element.get_attribute("src")) - - self.driver_close(driver) - # To remove duplicates here I am converting into set - if image_links: - image_links = list(set(image_links)) - if video_links: - video_links = list(set(video_links)) - for i in video_links: - image_links.remove(i) - - self.return_dict.get("image").extend(image_links) - self.return_dict.get("video").extend(video_links) - return self.return_dict - - else: - return {} - + LOGGER.error(e) + LOGGER.error(format_exc(e)) + return {"code": 69, "message": e} \ No newline at end of file diff --git a/Powers/vars.py b/Powers/vars.py index 8a916c1f..d1dde353 100644 --- a/Powers/vars.py +++ b/Powers/vars.py @@ -38,8 +38,8 @@ class Config: default="" ).split(None) ] - CHROME_BIN = config("CHROME_BIN", "/app/.apt/usr/bin/google-chrome") - CHROME_DRIVER = config("CHROME_DRIVER", default="/app/.chromedriver/bin/chromedriver") + # CHROME_BIN = config("CHROME_BIN", "/app/.apt/usr/bin/google-chrome") + # CHROME_DRIVER = config("CHROME_DRIVER", default="/app/.chromedriver/bin/chromedriver") GENIUS_API_TOKEN = config("GENIUS_API", default=None) # AuDD_API = config("AuDD_API",default=None) RMBG_API = config("RMBG_API", default=None) @@ -82,5 +82,5 @@ class Development: TIME_ZONE = 'Asia/Kolkata' BDB_URI = "" WORKERS = 8 - CHROME_BIN = "/app/.apt/usr/bin/google-chrome" - CHROME_DRIVER = "/app/.chromedriver/bin/chromedriver" + # CHROME_BIN = "/app/.apt/usr/bin/google-chrome" + # CHROME_DRIVER = "/app/.chromedriver/bin/chromedriver" diff --git a/app.json b/app.json index f5d6ebf2..ea476941 100644 --- a/app.json +++ b/app.json @@ -104,16 +104,6 @@ "required": false, "value": "8" }, - "CHROME_DRIVER": { - "description": "Location of chrome driver", - "required": false, - "value": "/app/.chromedriver/bin/chromedriver" - }, - "CHROME_BIN" : { - "description": "Location of chrome bin", - "required": false, - "value": "/app/.apt/usr/bin/google-chrome" - }, "ENV": { "description": "Setting this to ANYTHING will enable environment variables. Leave it as it is", "required": true, diff --git a/requirements.txt b/requirements.txt index 7d596f00..86650c43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ aiofiles==23.2.1 -anyio==4.2.0 apscheduler==3.10.4 asyncio==3.4.3 beautifulsoup4==4.12.2 @@ -10,13 +9,14 @@ charset-normalizer==2.1.0 dnspython==2.2.1 google==3.0.0 gpytranslate==1.5.1 +httpx lyricsgenius==3.0.1 lxml==4.9.1 pillow == 10.1.0 prettyconf==2.2.1 pyaes==1.6.1 pymongo==4.6.1 -git+https://github.com/KurimuzonAkuma/pyrogram.git@v2.1.22 +git+https://github.com/KurimuzonAkuma/pyrogram.git@v2.1.30 pysocks==1.7.1 python-dateutil==2.8.2 pytube==15.0.0 @@ -27,16 +27,14 @@ regex==2023.12.25 requests==2.31.0 rfc3986==1.5.0 search-engine-parser==0.6.8 -selenium==4.18.1 six==1.16.0 sniffio==1.3.0 soupsieve==2.4 tgcrypto==1.2.5 tswift==0.7.0 -typing-extensions==4.5.0 +typing-extensions ujson==5.8.0 -urllib3==1.26.18 uvloop==0.19.0 wikipedia==1.4.0 youtube-search-python==1.6.6 -yt-dlp@git+https://github.com/HellBoy-OP/yt-dp-fork.git@af1fd12f675220df6793fc019dff320bc76e8080 +yt-dlp@git+https://github.com/HellBoy-OP/yt-dp-fork.git@af1fd12f675220df6793fc019dff320bc76e8080 \ No newline at end of file