async def rem_snip(message: Message) -> None: """remove a snip""" if '-all' in message.flags: await asyncio.gather(SNIPS.drop(), message.edit("`Cleared All SNIPS !`", del_in=5)) return snip_name = message.input_str if not snip_name: return await message.err("`Wrong syntax`\nNo arguements", del_in=5) found = await SNIPS.find_one_and_delete({'snip_name': snip_name}) if found: await message.edit( f"Snip <b>${found['snip_name']}</b> deleted successfully !", del_in=5, log=__name__) else: await message.err( f"Snip <b>${snip_name}<b> doesn\'t exist ! task failed successfully !", del_in=5)
async def active_afk(message: Message) -> None: """turn on or off afk mode""" global REASON, IS_AFK, TIME # pylint: disable=global-statement IS_AFK = True TIME = time.time() REASON = message.input_str await asyncio.gather( CHANNEL.log(f"You went AFK! : `{REASON}`"), message.edit("`You went AFK!`", del_in=1), AFK_COLLECTION.drop(), SAVED_SETTINGS.update_one( {"_id": "AFK"}, {"$set": { "on": True, "data": REASON, "time": TIME }}, upsert=True, ), )
async def add_sudo(message: Message): """ add sudo user """ 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 message.client.get_user_dict(user_id) except (PeerIdInvalid, IndexError) as p_e: await message.err(str(p_e)) return if user["id"] in Config.SUDO_USERS: await message.edit(f"user : `{user['id']}` already in **SUDO**!", del_in=5) else: if user["id"] in Config.OWNER_ID or user["id"] == (await userge.get_me()).id: await message.edit( f"user : `{user['id']}` is in `OWNER_ID` so no need to add in sudo", del_in=5, ) return if user["id"] in Config.TG_IDS: await message.err("Not Permitted due to security reasons", del_in=7) return Config.SUDO_USERS.add(user["id"]) await asyncio.gather( SUDO_USERS_COLLECTION.insert_one({ "_id": user["id"], "men": user["mention"] }), message.edit(f"user : `{user['id']}` added to **SUDO**!", del_in=5, log=__name__), )
async def ungban_user(message: Message): """ unban a user globally """ await message.edit("`UnGBanning...`") if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: user_id = message.input_str if not user_id: await message.err("user-id not found") return get_mem = await message.client.get_user_dict(user_id) firstname = get_mem['fname'] user_id = get_mem['id'] found = await GBAN_USER_BASE.find_one({'user_id': user_id}) if not found: await message.err("User Not Found in My Gban List") return await asyncio.gather( GBAN_USER_BASE.delete_one({ 'firstname': firstname, 'user_id': user_id }), message.edit( r"\\**#UnGbanned_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`")) if not message.client.is_bot: for chat in await message.client.get_common_chats(user_id): try: await chat.unban_member(user_id) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n" f"**Chat:** {chat.title}\n" f"**Chat ID:** `{chat.id}`\n\n$UNGBAN #id{user_id}") except (ChatAdminRequired, UserAdminInvalid): pass LOG.info("UnGbanned %s", str(user_id))
async def add_sudo(message: Message): """ add sudo user """ 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 message.client.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']}), message.edit(f"user : `{user['id']}` added to **SUDO**!", del_in=5, log=__name__))
async def ungmute_user(msg: Message): """ unmute a user globally """ await msg.edit("`UnGMuting this User...`") user_id, _ = msg.extract_user_and_text if not user_id: await msg.err("user-id not found") return get_mem = await msg.client.get_user_dict(user_id) firstname = get_mem['fname'] user_id = get_mem['id'] found = await GMUTE_USER_BASE.find_one({'user_id': user_id}) if not found: await msg.edit("`User Not Found in My GMute List`", del_in=5) return await asyncio.gather( GMUTE_USER_BASE.delete_one({ 'firstname': firstname, 'user_id': user_id }), msg.edit(r"\\**#UnGMuted_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`")) chats = [ msg.chat ] if msg.client.is_bot else await msg.client.get_common_chats(user_id) for chat in chats: try: await chat.unban_member(user_id) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n" f"**Chat:** {chat.title}\n" f"**Chat ID:** `{chat.id}`\n\n$UNGMUTED #id{user_id}") except (ChatAdminRequired, UserAdminInvalid): pass LOG.info("UnGMuted %s", str(user_id))
async def ungban_user(message: Message): """ unban a user from Bot's PM""" await message.edit("`UN-BOT Banning ...`") user_id = int(message.input_str) if not user_id: await message.err("user-id not found") return try: get_mem = await message.client.get_user_dict(user_id) firstname = get_mem["fname"] user_id = get_mem["id"] except BaseException: await message.edit("`userid Invalid`", del_in=7) return found = await BOT_BAN.find_one({"user_id": user_id}) if not found: await message.err("User Not Found in My Bot Ban List") return await asyncio.gather( BOT_BAN.delete_one(found), message.edit(r"\\**#UnBotbanned_User**//" f"\n\n**First Name:** {mention_html(user_id, firstname)}" f"**User ID:** `{user_id}`"), )
async def ungban_user(message: Message): """ unban a user from Bot's PM""" await message.edit("`UN-BOT Banning ...`") user_id = int(message.input_str) if not user_id: await message.err("user-id not found") return try: get_mem = await message.client.get_user_dict(user_id) firstname = get_mem['fname'] user_id = get_mem['id'] except: await message.edit("`userid Invalid`", del_in=7) return found = await BOT_BAN.find_one({'user_id': user_id}) if not found: await message.err("User Not Found in My Bot Ban List") return await asyncio.gather( BOT_BAN.delete_one({'firstname': firstname, 'user_id': user_id}), message.edit( r"\\**#UnBotbanned_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`"))
async def gban_user(message: Message): """ ban a user globally """ await message.edit("`GBanning...`") if message.reply_to_message: user_id = message.reply_to_message.from_user.id reason = message.input_str else: args = message.input_str.split(maxsplit=1) if len(args) == 2: user_id, reason = args else: await message.edit( "`no valid user_id or message specified,`" "`don't do .help gban for more info. " "Coz no one's gonna help ya`(。ŏ_ŏ) ⚠", del_in=0) return get_mem = await message.client.get_user_dict(user_id) firstname = get_mem['fname'] if not reason: await message.edit( f"**#Aborted**\n\n**Gbanning** of [{firstname}](tg://user?id={user_id}) " "Aborted coz No reason of gban provided by banner", del_in=5) return user_id = get_mem['id'] if user_id == (await message.client.get_me()).id: await message.edit(r"LoL. Why would I GBan myself ¯\(°_o)/¯") return if user_id in Config.SUDO_USERS: await message.edit( "That user is in my Sudo List, Hence I can't ban him.\n\n" "**Tip:** Remove them from Sudo List and try again. (¬_¬)", del_in=5) return found = await GBAN_USER_BASE.find_one({'user_id': user_id}) if found: await message.edit( "**#Already_GBanned**\n\nUser Already Exists in My Gban List.\n" f"**Reason For GBan:** `{found['reason']}`", del_in=5) return await asyncio.gather( GBAN_USER_BASE.insert_one({ 'firstname': firstname, 'user_id': user_id, 'reason': reason }), message.edit( r"\\**#GBanned_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n**Reason:** `{reason}`")) # TODO: can we add something like "GBanned by {any_sudo_user_fname}" for chat in await message.client.get_common_chats(user_id): try: await chat.kick_member(user_id) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n" f"**Chat:** {chat.title}\n" f"**Chat ID:** `{chat.id}`\n" f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}") except ChatAdminRequired: pass LOG.info("G-Banned %s", str(user_id)) try: if message.reply_to_message: await CHANNEL.fwd_msg(message.reply_to_message) await CHANNEL.log(f'$GBAN #prid{user_id} ⬆️') await message.reply_to_message.delete() except Exception: await message.reply( "`I dont have message nuking rights! But still he got gbanned!`")
async def yts(message: Message): qual = None max_limit = 5 input_ = message.input_or_reply_str get_limit = re.compile(r"-l\d*[0-9]") get_quality = re.compile(r"-q\d*[PpDd]") _movie = re.sub(r"-\w*", "", input_).strip() if get_limit.search(input_) is None and get_quality.search(input_) is None: pass elif (get_quality.search(input_) is not None and get_limit.search(input_) is not None): qual = get_quality.search(input_).group().strip("-q") max_limit = int(get_limit.search(input_).group().strip("-l")) elif get_quality.search(input_): qual = get_quality.search(input_).group().strip("-q") elif get_limit.search(input_): max_limit = int(get_limit.search(input_).group().strip("-l")) if len(input_) == 0: await message.edit("No Input Found!, check .help yts", del_in=5) return URL = "https://yts.mx/api/v2/list_movies.json?query_term={query}&limit={limit}" await message.edit("Fetching....") resp = requests.get(URL.format(query=_movie, limit=max_limit)) datas = resp.json() if datas["status"] != "ok": await message.edit("WRONG STATUS") return if datas["data"]["movie_count"] == 0 or len(datas["data"]) == 3: await message.edit(f"{_movie} Not Found!", del_in=5) return _matches = datas["data"]["movie_count"] await message.edit( f"{_matches} Matches Found!, Sending {len(datas['data']['movies'])}.") for data in datas["data"]["movies"]: _title = data["title_long"] _rating = data["rating"] _language = data["language"] _torrents = data["torrents"] def_quality = "720p" _qualities = [i["quality"] for i in _torrents] if qual in _qualities: def_quality = qual qualsize = [f"{j['quality']}: {j['size']}" for j in _torrents] capts = f""" Title: {_title} Rating: {_rating} Language: {_language} Size: {_torrents[_qualities.index(def_quality)]['size']} Type: {_torrents[_qualities.index(def_quality)]['type']} Seeds: {_torrents[_qualities.index(def_quality)]['seeds']} Date Uploaded: {_torrents[_qualities.index(def_quality)]['date_uploaded']} Available in: {qualsize}""" if def_quality in _qualities: files = ( f"{_title}{_torrents[_qualities.index(def_quality)]['quality']}.torrent" ) files = files.replace("/", "\\") with open(files, "wb") as f: f.write( requests.get(_torrents[_qualities.index(def_quality)] ["url"]).content) await message.client.send_document( chat_id=message.chat.id, document=files, caption=capts, disable_notification=True, ) os.remove(files) else: message.edit("NOT FOUND", del_in=5) return return
async def add_sudo_cmd(message: Message): """add sudo cmd""" blocked_cmd = [ "exec", "term", "eval", "addscmd", "delscmd", "load", "unload", "addsudo", "delsudo", "sudo", "vsudo", "freeze", "defreeze", "tb", "addf", "delf", "fban", "fbanp", "fbanm", "unfban", ] if "-all" in message.flags: await SUDO_CMDS_COLLECTION.drop() Config.ALLOWED_COMMANDS.clear() tmp_ = [] for c_d in list(userge.manager.enabled_commands): t_c = c_d.lstrip(Config.CMD_TRIGGER) if "-all" in message.flags: mode_ = "all" if not (t_c in blocked_cmd): tmp_.append({"_id": t_c}) Config.ALLOWED_COMMANDS.add(t_c) await asyncio.gather( SUDO_CMDS_COLLECTION.insert_many(tmp_), message.edit( f"**Added** {mode_} (`{len(tmp_)}`) commands to **SUDO** cmds!", del_in=5, log=__name__, ), ) return cmd = message.input_str if not cmd: await message.err("input not found!") return cmd = cmd.lstrip(Config.CMD_TRIGGER) if cmd in blocked_cmd: return await message.err( f"Command {cmd} is dangerous, so can't be added for normal sudo users!", del_in=5, ) 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(userge.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}), message.edit(f"cmd : `{cmd}` added to **SUDO**!", del_in=5, log=__name__), )
async def yts(message: Message): qual = None max_limit = 5 input_ = message.input_or_reply_str get_limit = re.compile(r'-l\d*[0-9]') get_quality = re.compile(r'-q\d*[PpDd]') _movie = re.sub(r'-\w*', "", input_).strip() if get_limit.search(input_) is None and get_quality.search(input_) is None: pass elif get_quality.search(input_) is not None and get_limit.search(input_) is not None: qual = get_quality.search(input_).group().strip('-q') max_limit = int(get_limit.search(input_).group().strip('-l')) elif get_quality.search(input_): qual = get_quality.search(input_).group().strip('-q') elif get_limit.search(input_): max_limit = int(get_limit.search(input_).group().strip('-l')) if len(input_) == 0: await message.edit("No Input Found!, check .help yts", del_in=5) return URL = "https://yts.mx/api/v2/list_movies.json?query_term={query}&limit={limit}" await message.edit("Fetching....") resp = requests.get(URL.format(query=_movie, limit=max_limit)) datas = resp.json() if datas['status'] != "ok": await message.edit("WRONG STATUS") return if datas['data']['movie_count'] == 0 or len(datas['data']) == 3: await message.edit(f"{_movie} Not Found!", del_in=5) return _matches = datas['data']['movie_count'] await message.edit(f"{_matches} Matches Found!, Sending {len(datas['data']['movies'])}.") for data in datas['data']['movies']: _title = data['title_long'] _rating = data['rating'] _language = data['language'] _torrents = data['torrents'] def_quality = "720p" _qualities = [] for i in _torrents: _qualities.append(i['quality']) if qual in _qualities: def_quality = qual qualsize = [f"{j['quality']}: {j['size']}" for j in _torrents] capts = f''' Title: {_title} Rating: {_rating} Language: {_language} Size: {_torrents[_qualities.index(def_quality)]['size']} Type: {_torrents[_qualities.index(def_quality)]['type']} Seeds: {_torrents[_qualities.index(def_quality)]['seeds']} Date Uploaded: {_torrents[_qualities.index(def_quality)]['date_uploaded']} Available in: {qualsize}''' if def_quality in _qualities: files = f"{_title}{_torrents[_qualities.index(def_quality)]['quality']}.torrent" files = files.replace('/', '\\') with open(files, 'wb') as f: f.write(requests.get(_torrents[_qualities.index(def_quality)]['url']).content) await userge.send_document(chat_id=message.chat.id, document=files, caption=capts, disable_notification=True) os.remove(files) else: message.edit("NOT FOUND", del_in=5) return return
async def gmute_user(msg: Message): """ Mute a user globally """ await msg.edit("`Globally Muting this User...`") if msg.reply_to_message: user_id = msg.reply_to_message.from_user.id reason = msg.input_str else: args = msg.input_str.split(maxsplit=1) if len(args) == 2: user_id, reason = args else: await msg.edit("`no valid user_id or message specified,`" "`don't do .help gmute for more info. " "Coz no one's gonna help ya`(。ŏ_ŏ) ⚠") return get_mem = await msg.client.get_user_dict(user_id) firstname = get_mem['fname'] if not reason: await msg.edit( f"**#Aborted**\n\n**GMuting** of [{firstname}](tg://user?id={user_id}) " "`Aborted coz No reason of GMute provided by User`", del_in=5) return user_id = get_mem['id'] if user_id == msg.from_user.id: await msg.err(r"LoL. Why would I GMuting myself ¯\(°_o)/¯") return if user_id in Config.SUDO_USERS: await msg.edit( "`That user is in my Sudo List, Hence I can't GMute him.`\n\n" "**Tip:** `Remove them from Sudo List and try again. (¬_¬)`", del_in=5) return found = await GMUTE_USER_BASE.find_one({'user_id': user_id}) if found: await msg.edit( "**#Already_GMuted**\n\n`This User Already Exists in My GMute List.`\n" f"**Reason For GMute:** `{found['reason']}`") return await asyncio.gather( GMUTE_USER_BASE.insert_one({ 'firstname': firstname, 'user_id': user_id, 'reason': reason }), msg.edit(r"\\**#GMuted_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n**Reason:** `{reason}`")) if not msg.client.is_bot: for chat in await msg.client.get_common_chats(user_id): try: await chat.restrict_member(user_id, ChatPermissions()) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n" f"**Chat:** {chat.title}\n" f"**Chat ID:** `{chat.id}`\n" f"**Reason:** `{reason}`\n\n$GMUTE #id{user_id}") except (ChatAdminRequired, UserAdminInvalid): pass LOG.info("G-Muted %s", str(user_id)) try: if msg.reply_to_message: await CHANNEL.fwd_msg(msg.reply_to_message) await CHANNEL.log(f'$GMUTE #prid{user_id} ⬆️') await msg.reply_to_message.delete() except Exception: await msg.reply( "`I dont have message deletation rights! But still he got GMuted!`" )
async def gmute_user(msg: Message): """ Mute a user globally """ await msg.edit("`Globally Muting this User...`") user_id, reason = msg.extract_user_and_text if not user_id: await msg.edit("`no valid user_id or message specified,`" "`don't do .help gmute for more info. " "Coz no one's gonna help ya`(。ŏ_ŏ) ⚠") return get_mem = await msg.client.get_user_dict(user_id) firstname = get_mem["fname"] if not reason: await msg.edit( f"**#Aborted**\n\n**GMuting** of [{firstname}](tg://user?id={user_id}) " "`Aborted coz No reason of GMute provided by User`", del_in=5, ) return user_id = get_mem["id"] if user_id == msg.from_user.id: await msg.err(r"LoL. Why would I GMuting myself ¯\(°_o)/¯") return if user_id in Config.SUDO_USERS: await msg.edit( "`That user is in my Sudo List, Hence I can't GMute him.`\n\n" "**Tip:** `Remove them from Sudo List and try again. (¬_¬)`", del_in=5, ) return found = await GMUTE_USER_BASE.find_one({"user_id": user_id}) if found: await msg.edit( "**#Already_GMuted**\n\n`This User Already Exists in My GMute List.`\n" f"**Reason For GMute:** `{found['reason']}`") return await asyncio.gather( GMUTE_USER_BASE.insert_one({ "firstname": firstname, "user_id": user_id, "reason": reason }), msg.edit(r"\\**#GMuted_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n**Reason:** `{reason}`"), ) chats = await userge.get_common_chats(user_id) for chat in chats: try: await chat.restrict_member(user_id, ChatPermissions()) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**User ID:** `{user_id}`\n" f"**Chat:** {chat.title}\n" f"**Chat ID:** `{chat.id}`\n" f"**Reason:** `{reason}`\n\n$GMUTE #id{user_id}") except (ChatAdminRequired, UserAdminInvalid): pass if msg.reply_to_message: await CHANNEL.fwd_msg(msg.reply_to_message) await CHANNEL.log(f"$GMUTE #prid{user_id} ⬆️") LOG.info("G-Muted %s", str(user_id))
async def yts(message: Message): max_limit = 10 input_ = message.input_or_reply_str if input_.find('-') == -1: qual = None else: qual = input_[input_.find('-')+1:] input_ = input_[:input_.find('-')-1] if len(input_) == 0: await message.edit("No Input Found!, check .help yts", del_in=5) return else: URL = "https://yts.mx/api/v2/list_movies.json?query_term={0}" await message.edit("Fetching....") resp = requests.get(URL.format(input_)) datas = resp.json() if datas['status'] != "ok": await message.edit("WRONG STATUS") return elif datas['data']['movie_count'] == 0: await message.edit(f"{input_} Not Found!") return else: await message.edit(f"{datas['data']['movie_count']} Matches Found!") _limit = 1 for data in datas['data']['movies']: if _limit <= max_limit: _title = data['title_long'] _rating = data['rating'] _language = data['language'] _torrents = data['torrents'] def_quality = "720p" _qualities = [] for i in _torrents: _qualities.append(i['quality']) if qual in _qualities: def_quality = qual capts = f''' Title: {_title} Rating: {_rating} Language: {_language} Size: {_torrents[_qualities.index(def_quality)]['size']} Type: {_torrents[_qualities.index(def_quality)]['type']} Seeds: {_torrents[_qualities.index(def_quality)]['seeds']} Date Uploaded: {_torrents[_qualities.index(def_quality)]['date_uploaded']} Available in: {_qualities}''' if def_quality in _qualities: files = f"{_title}{_torrents[_qualities.index(def_quality)]['quality']}.torrent" files = files.replace('/', '\\') with open(files, 'wb') as f: f.write(requests.get(_torrents[_qualities.index(def_quality)]['url']).content) await userge.send_document(chat_id=message.chat.id, document=files, caption=capts, disable_notification=True) os.remove(files) _limit += 1 else: message.edit("NOT FOUND") return return