async def del_sudo(message: Message): user_id = message.filtered_input_str if message.reply_to_message: user_id = message.reply_to_message.from_user.id if '-all' in message.flags: Config.SUDO_USERS.clear() await asyncio.gather(SUDO_USERS_COLLECTION.drop(), message.edit("**SUDO** users cleared!", del_in=5)) return if not user_id: await message.err(f'user: `{user_id}` not found!') return if isinstance(user_id, str) and user_id.isdigit(): user_id = int(user_id) if not isinstance(user_id, int): await message.err('invalid type!') return if user_id not in Config.SUDO_USERS: await message.edit(f"user : `{user_id}` not in **SUDO**!", del_in=5) else: Config.SUDO_USERS.remove(user_id) await asyncio.gather( SUDO_USERS_COLLECTION.delete_one({'_id': user_id}), CHANNEL.log(f"user : `{user_id}` removed from **SUDO**!"), message.edit(f"user : `{user_id}` removed from **SUDO**!", del_in=5))
async def raw_say(message: Message, name, collection): user = message.new_chat_members[0] if name == "Welcome" \ else message.left_chat_member user_dict = await userbot.get_user_dict(user.id) user_dict.update({'chat': message.chat.title if message.chat.title else "this group"}) found = await collection.find_one({'_id': message.chat.id}, {'media': 0, 'name': 0}) caption = found['data'] file_type = found['type'] if 'type' in found else '' file_id = found['fid'] if 'fid' in found else '' file_ref = found['fref'] if 'fref' in found else '' if caption: caption = caption.format_map(SafeDict(**user_dict)) if file_id: try: await send_proper_type(message, caption, file_type, file_id, file_ref) except (FileIdInvalid, FileReferenceEmpty, BadRequest): found = await collection.find_one({'_id': message.chat.id}, {'media': 1, 'name': 1}) file_name = found['name'] media = found['media'] tmp_media_path = os.path.join(Config.DOWN_PATH, file_name) async with aiofiles.open(tmp_media_path, "wb") as media_file: await media_file.write(base64.b64decode(media)) file_id, file_ref = await send_proper_type(message, caption, file_type, tmp_media_path) await collection.update_one({'_id': message.chat.id}, {"$set": {'fid': file_id, 'fref': file_ref}}, upsert=True) os.remove(tmp_media_path) else: await message.reply(caption, del_in=Config.WELCOME_DELETE_TIMEOUT) message.stop_propagation()
async def quotecmd(message: Message): """quotecmd""" asyncio.get_event_loop().create_task(message.delete()) args = message.input_str replied = message.reply_to_message async with userbot.conversation('QuotLyBot') as conv: try: if replied and not args: await conv.forward_message(replied) else: if not args: await message.err('input not found!') return await conv.send_message(args) except YouBlockedUser: await message.edit('first **unblock** @QuotLyBot') return quote = await conv.get_response(mark_read=True) if not quote.sticker: await message.err('something went wrong!') else: message_id = replied.message_id if replied else None await userbot.send_sticker(chat_id=message.chat.id, sticker=quote.sticker.file_id, file_ref=quote.sticker.file_ref, reply_to_message_id=message_id)
async def add_sudo(message: Message): user_id = message.input_str if message.reply_to_message: user_id = message.reply_to_message.from_user.id if not user_id: await message.err(f'user: `{user_id}` not found!') return if isinstance(user_id, str) and user_id.isdigit(): user_id = int(user_id) try: user = await userbot.get_user_dict(user_id) except PeerIdInvalid as p_e: await message.err(p_e) return if user['id'] in Config.SUDO_USERS: await message.edit(f"user : `{user['id']}` already in **SUDO**!", del_in=5) else: Config.SUDO_USERS.add(user['id']) await asyncio.gather( SUDO_USERS_COLLECTION.insert_one({ '_id': user['id'], 'men': user['mention'] }), CHANNEL.log(f"user : `{user['id']}` added to **SUDO**!"), message.edit(f"user : `{user['id']}` added to **SUDO**!", del_in=5))
async def del_sudo_cmd(message: Message): cmd = message.filtered_input_str if '-all' in message.flags: Config.ALLOWED_COMMANDS.clear() await asyncio.gather(SUDO_CMDS_COLLECTION.drop(), message.edit("**SUDO** cmds cleared!", del_in=5)) return if not cmd: await message.err('input not found!') return if cmd not in Config.ALLOWED_COMMANDS: await message.edit(f"cmd : `{cmd}` not in **SUDO**!", del_in=5) else: Config.ALLOWED_COMMANDS.remove(cmd) await asyncio.gather( SUDO_CMDS_COLLECTION.delete_one({'_id': cmd}), CHANNEL.log(f"cmd : `{cmd}` removed from **SUDO**!"), message.edit(f"cmd : `{cmd}` removed from **SUDO**!", del_in=5))
async def webss(message: Message): if Config.GOOGLE_CHROME_BIN is None: await message.err("need to install Google Chrome. Module Stopping") return link_match = match(r'\bhttps?://.*\.\S+', message.input_str) if not link_match: await message.err("`I need a valid link to take screenshots from.`") return link = link_match.group() await message.edit("`Processing ...`") chrome_options = webdriver.ChromeOptions() chrome_options.binary_location = Config.GOOGLE_CHROME_BIN chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument("--test-type") chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument("--no-sandbox") chrome_options.add_argument('--disable-gpu') driver = webdriver.Chrome(chrome_options=chrome_options) driver.get(link) height = driver.execute_script( "return Math.max(document.body.scrollHeight, document.body.offsetHeight, " "document.documentElement.clientHeight, document.documentElement.scrollHeight, " "document.documentElement.offsetHeight);") width = driver.execute_script( "return Math.max(document.body.scrollWidth, document.body.offsetWidth, " "document.documentElement.clientWidth, document.documentElement.scrollWidth, " "document.documentElement.offsetWidth);") driver.set_window_size(width + 125, height + 125) wait_for = height / 1000 await message.edit(f"`Generating screenshot of the page...`" f"\n`Height of page = {height}px`" f"\n`Width of page = {width}px`" f"\n`Waiting ({int(wait_for)}s) for the page to load.`") await asyncio.sleep(int(wait_for)) im_png = driver.get_screenshot_as_png() driver.close() message_id = message.message_id if message.reply_to_message: message_id = message.reply_to_message.message_id file_path = os.path.join(Config.DOWN_PATH, "webss.png") async with aiofiles.open(file_path, 'wb') as out_file: await out_file.write(im_png) await asyncio.gather( message.delete(), userbot.send_document(chat_id=message.chat.id, document=file_path, caption=link, reply_to_message_id=message_id)) os.remove(file_path) driver.quit()
async def add_sudo_cmd(message: Message): cmd = message.input_str if not cmd: await message.err('input not found!') return cmd = cmd.lstrip(Config.CMD_TRIGGER) if cmd in Config.ALLOWED_COMMANDS: await message.edit(f"cmd : `{cmd}` already in **SUDO**!", del_in=5) elif cmd not in (c_d.lstrip(Config.CMD_TRIGGER) for c_d in list(userbot.manager.enabled_commands)): await message.edit(f"cmd : `{cmd}` 🤔, is that a command ?", del_in=5) else: Config.ALLOWED_COMMANDS.add(cmd) await asyncio.gather( SUDO_CMDS_COLLECTION.insert_one({'_id': cmd}), CHANNEL.log(f"cmd : `{cmd}` added to **SUDO**!"), message.edit(f"cmd : `{cmd}` added to **SUDO**!", del_in=5))
async def gban_at_entry(message: Message): try: if message.service: if message.new_chat_members: chat_id = message.chat.id user_id = message.new_chat_members[0].id firstname = message.new_chat_members[0].first_name except Exception: return # Nu use to continue if u can't get id of user from message 🤔 async for w in WHITELIST.find({}): if w['user_id'] == user_id: return try: async for c in GBAN_USER_BASE.find({}): if c['user_id'] == user_id: reason = c['reason'] try: if await guadmin_check(chat_id, user_id): await userbot.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userbot_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {reason}\n**Quick Action:** " "Banned in {message.chat.title}") except Exception: break except Exception: pass if Config.ANTISPAM_SENTRY: try: if Config.SPAM_WATCH_API is not None: SENTRY = spamwatch.Client(Config.SPAM_WATCH_API) intruder = SENTRY.get_ban(user_id) if intruder and await guadmin_check(chat_id, user_id): await userbot.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userbot_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" "**Quick Action:** Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") except Exception: pass try: res = requests.get(f'https://combot.org/api/cas/check?user_id={user_id}') res_dict = json.loads(res.text) if res_dict['ok'] and await guadmin_check(chat_id, user_id): try: reason = res_dict['result']['offenses'] await userbot.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userbot_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" " Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") except Exception: pass except Exception: pass message.continue_propagation()
async def check_and_send(message: Message, *args, **kwargs): replied = message.reply_to_message if replied: await asyncio.gather(message.delete(), replied.reply(*args, **kwargs)) else: await message.edit(*args, **kwargs)