async def del_tag(message: Message): """delete user in the chat's tag list""" if "-all" in message.flags: await CHAT_TAG.drop() await CHANNEL.log("`Cleared whole tag list.`") return await message.edit("`Cleared whole tag list.`", del_in=5) user = message.input_str reply_ = message.reply_to_message if not user: if reply_: user = reply_.from_user.id else: return await message.edit( "`Give username or reply to user to add in tag list...`", del_in=5) try: user_ = await userge.get_users(user) user_id = user_.id except Exception as e: return await message.edit(f"<b>ERROR:</b> {e}", del_in=5) chat_ = message.chat.id user_.mention full_name(user_) data = [] found = await CHAT_TAG.find_one({"chat_id": chat_}) if found: if "-chat" in message.flags: chat_ = await userge.get_chat(chat_) await CHAT_TAG.delete_one(found) await message.edit("`Cleared this chat's tag list.`", del_in=5) return await CHANNEL.log( f"Cleared <b>{chat_.title}</b>'s tag list.") for one in found["data"]: if one["user_id"] != user_id: data.append(one) await CHAT_TAG.update_one({found}, {"$set": { "data": data }}, upsert=True) await message.edit( f"Deleted user <b>{user_.first_name}</b> from tag list of chat <b>{message.chat.title}</b>...", del_in=5, ) await CHANNEL.log( f"Deleted user <b>{user_.first_name}</b> from tag list of chat <b>{message.chat.title}</b>..." ) return else: await message.edit( f"User <b>{user_.first_name}</b> doesn't exist in tag list of chat <b>{message.chat.title}</b>...", del_in=5, )
async def add_post(message: Message): """add chat to list for posting""" chat_ = message.input_str if not chat_: chat_ = message.chat.id try: chat_ = await userge.get_chat(chat_) except BaseException: await message.edit(f"`Provided input ({chat_}) is not a chat...`", del_in=5) return chat_type = chat_.type if chat_type == "private": chat_name = full_name(chat_) else: chat_name = chat_.title chat_id = chat_.id found = await POST_LIST.find_one({"chat_id": chat_id}) if found: await message.edit(f"Chat <b>{chat_name}</b> is already in list.", del_in=5) return await POST_LIST.insert_one({ "chat_name": chat_name, "chat_id": chat_id, "chat_type": chat_type }) msg_ = f"Successfully added <b>{chat_name}</b> (`{chat_id}`) in POST LIST." await message.edit(msg_) await CHANNEL.log(msg_)
async def bl_action(_, message: Message): try: found = await BLOCKED.find_one({"chat_id": message.chat.id}) if not found: return if not found["block_tog"]: return if found["blocked"][msg_type(message)]: user_ = message.from_user.id full_name(await userge.get_users(user_)) chat_id = message.chat.id await message.delete() msg = await take_action(chat_id, user_) if found["block_mode"] == "None": return await userge.bot.send_message(message.chat.id, msg) except FloodWait as e: await asyncio.sleep(e.x + 3)
async def chat_users_(message: Message): """find chat users""" input_ = message.input_str if not input_: limit_ = 100 chat_ = message.chat.id else: if len(input_.split()) > 1: chat_ = input_.split()[1:] limit_ = input_.split()[0] try: await userge.get_chat(chat_) except BaseException: await message.edit( f"Chat <code>{chat_}</code> is not a valid chat...") return else: chat_ = input_ try: await userge.get_chat(chat_) limit_ = 100 except BaseException: chat_ = message.chat.id limit_ = input_ if int(limit_) > 10000: await message.edit( f"Current limit(<code>{limit_}</code>) can't be more than 10000..." ) return title = (await userge.get_chat(chat_)).title await message.edit( f"Getting <b>{limit_}</b> members of chat <b>{title}</b>...") list_ = "List of <b>{}</b> members" + f"in chat <b>{title}</b>:\n\n" sr_n = 1 lim = 0 async for mem in userge.iter_chat_members(chat_): try: check = await userge.get_users(mem.user.id) user = full_name(check) except BaseException: user = "******" list_ += ( f"• [{sr_n}] {user} - @{mem.user.username}\n" if mem.user.username else f"• [{sr_n}] <a href='tg://user?id={mem.user.id}'>{user}</a>\n") sr_n += 1 lim += 1 if len(list_) > 4040: await message.reply(list_.format(sr_n)) list_ = "" if int(limit_) != 10000: if lim == limit_: break if len(list_) != 0: await message.reply(list_.format(sr_n - 1)) await message.delete()
async def uninvitedPmHandler(message: Message): """pm message handler""" me = await userge.get_me() owner = " ".join([me.first_name, me.last_name or ""]) user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update({"chat": message.chat.title or owner or "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] # await message.reply(blocked_message) report_img_ = await reported_user_image(message.from_user.first_name) await userge.send_photo( message.chat.id, report_img_, caption=blocked_message ) await message.from_user.block() user_ = await userge.get_users(message.chat.id) full_name(user_) await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait until you get approved to pm !", del_in=5, ) else: pmCounter.update({message.from_user.id: 1}) PMPERMIT_MSG[message.from_user.id] = ( await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + "\n<i>- Protected by paimon</i>" ) ).message_id await asyncio.sleep(1) await CHANNEL.log(f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def add_tag(message: Message): """add user in the chat's tag list""" user = message.input_str reply_ = message.reply_to_message if not user: if reply_: user = reply_.from_user.id else: return await message.edit( "`Give username or reply to user to add in tag list...`", del_in=5) try: user_ = await userge.get_users(user) user_id = user_.id except Exception as e: return await message.edit(f"<b>ERROR:</b> {e}", del_in=5) chat_ = message.chat.id mention = user_.mention name_ = full_name(user_) data = [] found = await CHAT_TAG.find_one({"chat_id": chat_}) if found: for one in found["data"]: if one["user_id"] == user_id: return await message.edit( f"User {user_id} already in CHAT_TAG list for this chat.", del_in=5) data = found["data"] data.append({"user_id": user_id, "name": name_, "mention": mention}) await CHAT_TAG.update_one({"chat_id": chat_}, {"$set": { "data": data }}, upsert=True) await message.edit( f"Added user <b>{user_.first_name}</b> to tag list of chat <b>{message.chat.title}</b>...", del_in=5, ) await CHANNEL.log( f"Added user <b>{user_.first_name}</b> to tag list of chat <b>{message.chat.title}</b>..." )
async def f_stat(message: Message): """Fstat of user""" reply = message.reply_to_message user_ = message.input_str if not reply else reply.from_user.id if not user_: user_ = message.from_user.id try: get_u = await userge.get_users(user_) user_name = full_name(get_u) user_id = get_u.id await message.edit( f"Fetching fstat of user <a href='tg://user?id={user_id}'><b>{user_name}</b></a>..." ) except BaseException: await message.edit( f"Fetching fstat of user <b>{user_}</b>...\nWARNING: User not found in your database, checking Rose's database." ) user_name = user_ user_id = user_ bot_ = "MissRose_bot" try: async with userge.conversation(bot_) as conv: await conv.send_message(f"!fstat {user_id}") response = await conv.get_response(mark_read=True, filters=filters.edited) except YouBlockedUser: await message.err("Unblock @missrose_bot first...", del_in=5) return except Exception as e: return await message.edit(f"<b>ERROR:</b> `{e}`") fail = "Could not find a user" resp = response.text.html resp = resp.replace("/fbanstat", f"`{Config.CMD_TRIGGER}fbanstat`") if fail in resp: await message.edit( f"User <b>{user_name}</b> (<code>{user_id}</code>) could not be found in @MissRose_bot's database." ) else: await message.edit(resp, parse_mode="html")
async def post_(message: Message): await message.edit("`Processing...`") reply_ = message.reply_to_message flags = message.flags if not reply_: return await message.edit("`Reply to a message...`") no_go = forbidden_sudo(message, reply_.text) if no_go: await message.delete() return await CHANNEL.log( f"User {message.from_user.mention} tried to use sudo command <b>in forbidden way</b>!!!" ) if ("-all" or "-grp" or "-pvt") not in flags: target = message.input_str if target.isdigit(): target = int(target) try: chat_ = await userge.get_chat(target) except BaseException: await message.edit( f"Given target <b>{target}</b> is not valid, see `{Config.CMD_TRIGGER}help post` for help...", del_in=5, ) return if BROAD_TAGGING: broad = await userge.send_message(chat_.id, "#BROADCAST") broad_id = broad.message_id else: broad_id = None await userge.copy_message(chat_.id, message.chat.id, reply_.message_id, reply_to_message_id=broad_id) if chat_.type in ["private", "bot"]: chat_name = full_name(chat_) else: chat_name = chat_.title await message.edit( f"Broadcasted a message to <b>{chat_name}</b> successfully.") await CHANNEL.log( f"#BROADCAST_SUCCESSFUL\n\nBroadcasted a message to <b>{chat_name}</b> (`{chat_.id}`) successfully." ) return total = 0 try: async for chats_ in POST_LIST.find(): if "-all" in flags: if BROAD_TAGGING: broad = await userge.send_message(chats_["chat_id"], "#BROADCAST") broad_id = broad.message_id else: broad_id = None await userge.copy_message( chats_["chat_id"], message.chat.id, reply_.message_id, reply_to_message_id=broad_id, ) total += 1 elif "-grp" in flags: if chats_["chat_type"] in ["group", "supergroup"]: if BROAD_TAGGING: broad = await userge.send_message( chats_["chat_id"], "#BROADCAST") broad_id = broad.message_id else: broad_id = None await userge.copy_message( chats_["chat_id"], message.chat.id, reply_.message_id, reply_to_message_id=broad_id, ) total += 1 elif "-pvt" in flags: if chats_["chat_type"] == "private": if BROAD_TAGGING: broad = await userge.send_message( chats_["chat_id"], "#BROADCAST") broad_id = broad.message_id else: broad_id = None await userge.copy_message( chats_["chat_id"], message.chat.id, reply_.message_id, reply_to_message_id=broad_id, ) total += 1 except FloodWait as e: await asyncio.sleep(e.x + 3) except Exception as e: await CHANNEL.log( f"`Something unexpected happened...`\n\n<b>ERROR:</b> `{e}`") return if "-all" in flags: to_ = "all chats" elif "-grp" in flags: to_ = "all groups" elif "-pvt" in flags: to_ = "all private chats" out_ = f"Broadcasted given message to <b>{to_} ({total})</b> in list successfully." await message.edit(out_) out_ = f"#BROADCAST_SUCCESSFUL\n\n{out_}" await CHANNEL.log(out_)
async def gban_new(message: Message): """gban in all groups and channels""" input_ = message.input_str reply_ = message.reply_to_message if not input_ and not reply_: return await message.edit("`Input not found.`", del_in=5) input_ = (input_).split(" ", 1) if len(input_) == 2: user_ = input_[0] try: user_ = await userge.get_users(user_) user_id = user_.id user_n = full_name(user_) reason_ = input_[1] except BaseException: if not reply_: return await message.edit("`Provided user is not valid.`", del_in=5) user_id = reply_.from_user.id user_n = " ".join( [reply_.from_user.first_name, reply_.from_user.last_name or ""] ) reason_ = message.input_str elif len(input_) == 1: user_ = input_[0] try: user_ = await userge.get_users(user_) user_id = user_.id user_n = full_name(user_) reason_ = "Not specified" except BaseException: if not reply_: return await message.edit("`Provided user is not valid.`", del_in=5) user_id = reply_.from_user.id user_n = " ".join( [reply_.from_user.first_name, reply_.from_user.last_name or ""] ) reason_ = message.input_str await message.edit(f"GBanning user {mention_html(user_id, user_n)}...") me_ = await userge.get_me() found = await GBAN_USER_BASE.find_one({"user_id": user_id}) if found: gbanned_chats = found["chat_ids"] else: gbanned_chats = [] failed = "" async for dia_ in userge.iter_dialogs(): try: chat_ = dia_.chat try: me_status = (await userge.get_chat_member(chat_.id, me_.id)).status user_status = (await userge.get_chat_member(chat_.id, user_id)).status except BaseException: continue status_ = ["administrator", "creator"] if me_status not in status_ or user_status in status_: continue try: await userge.kick_chat_member(chat_.id, user_id) gbanned_chats.append[chat_.id] except BaseException: failed += f"• {chat_.title} - {chat_.type}\n" except BaseException: failed += f"• {chat_.title} - {chat_.type}\n" if found: await GBAN_USER_BASE.update_one( {"user_id": user_id}, {"$set": {"chat_ids": gbanned_chats}}, upsert=True ) else: await GBAN_USER_BASE.insert_one( { "firstname": user_n, "user_id": user_id, "reason": reason_, "chat_ids": gbanned_chats, } ) out_ = ( "#GBANNED_USER\n\n" f"<b>User:</b> {mention_html(user_id, user_n)}\n" f"<b>User_ID:</b> `{user_id}` <b>Reason:</b> {reason_}\n" f"<b>GBanned in:</b> {len(gbanned_chats)}\n" ) if failed: out_ += f"<b>Failed in:</b>\n{failed}" await message.edit(out_) await CHANNEL.log( r"\\**#Antispam_Log**//" f"\n**User:** {mention_html(user_id, firstname)}\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}" )