def privileges_control(self, client: Client, msg: Message): bot_name = re.match( r'^\/(setwelcome|clear|status|setflag)(@[a-zA-Z_]*bot)?\s?', msg.text).group(2) if bot_name is not None and bot_name[1:] != self.bot_name: return group_info = self.groups[msg.chat.id] if group_info.admins is None: admins = client.get_chat_members(msg.chat.id, filter='administrators') group_info.admins = [x.user.id for x in admins] self.groups.update_group(msg.chat.id, group_info) logger.info('Updated administrator list in %d, new list is => %s', msg.chat.id, group_info.admins) if msg.from_user.id in group_info.admins: raise ContinuePropagation else: if not group_info.ignore_err and self.error_message != '': msg.reply(self.error_message) try: client.restrict_chat_member( msg.chat.id, msg.from_user.id, ChatPermissions(can_send_messages=False), msg.date + 60) except: pass
async def restrict_usr(client, message): await message.edit("`Trying to Mute user...`") is_admin = await admin_check(message) chat_id = message.chat.id if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) try: await message.chat.restrict_member(user_id=user_id, permisssions=ChatPermissions()) if str(user_id).lower().startswith("@"): await message.edit(f"**Muted** {user_first_name}") await client.send_message( PRIVATE_GROUP_ID, f"#MUTE\nMuted {user_first_name} in chat {message.chat.title}") else: await message.edit("**Muted** {}".format( mention_markdown(user_first_name, user_id))) await client.send_message( PRIVATE_GROUP_ID, "#MUTE\nMuted {} in chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
def SendMsg(client, message): cws = sql.fs_settings(message.chat.id) if not cws: return user_id = message.from_user.id first_name = message.from_user.first_name CHANNEL_USERNAME = cws.channel try: client.get_chat_member(CHANNEL_USERNAME, user_id) return except pyrogram.errors.exceptions.bad_request_400.UserNotParticipant: if client.get_chat_member(message.chat.id, user_id).status in ("administrator", "creator"): return message.reply_text( "[{}](tg://user?id={}), you are **not subscribed** to my [channel](https://t.me/{}) yet. Please [join](https://t.me/{}) and **press the button below** to unmute yourself." .format(first_name, user_id, CHANNEL_USERNAME, CHANNEL_USERNAME), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("UnMute Me", callback_data="onButtonPress") ]])) client.restrict_chat_member(message.chat.id, user_id, ChatPermissions(can_send_messages=False)) except pyrogram.errors.exceptions.bad_request_400.ChatAdminRequired: client.send_message(message.chat.id, text=f"I am not an admin in @{CHANNEL_USERNAME}") except ValueError: client.send_message(message.chat.id, text=f"I am not an admin in @{CHANNEL_USERNAME}")
async def unban(bot: Assistant, query: CallbackQuery): action, user_id = query.data.split(".") user_id = int(user_id) text = query.message.text if action == "unban": if query.from_user.id != Assistant.CREATOR_ID: await query.answer("Only Dan can pardon banned users", show_alert=True) return await bot.restrict_chat_member( query.message.chat.id, user_id, ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_stickers=True, can_send_animations=True, can_send_games=True, can_use_inline_bots=True, can_add_web_page_previews=True, can_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True ) ) await query.edit_message_text(f"~~{text.markdown}~~\n\nPardoned")
async def temp_mute_user(_, message): is_admin = await admin_check(message) if not is_admin: return if not len(message.command) > 1: return user_id, user_first_name = extract_user(message) until_date_val = extract_time(message.command[1]) if until_date_val is None: await message.reply_text( "അസാധുവായ സമയ തരം വ്യക്തമാക്കി. പ്രതീക്ഷിച്ചതു m, h, or d, കിട്ടിയത്: {}" .format(message.command[1][-1])) return try: await message.chat.restrict_member(user_id=user_id, permissions=ChatPermissions(), until_date=until_date_val) except Exception as error: await message.reply_text(str(error)) else: if str(user_id).lower().startswith("@"): await message.reply_text("കുറച്ചുനേരം മിണ്ടാതിരിക്ക്! 😠" f"{user_first_name}" f" muted for {message.command[1]}!") else: await message.reply_text("കുറച്ചുനേരം മിണ്ടാതിരിക്ക്! 😠" f"<a href='tg://user?id={user_id}'>" "ലവന്റെ" "</a>" " വായ " f" muted for {message.command[1]}!")
def unrestrict_user(client: Client, gid: int, uid: Union[int, str], lock: bool = False) -> bool: # Unrestrict a user result = False lock and glovar.locks["ban"].acquire() try: permissions = ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_stickers=True, can_send_animations=True, can_send_games=True, can_use_inline_bots=True, can_add_web_page_previews=True, can_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True) result = restrict_chat_member(client, gid, uid, permissions) except Exception as e: logger.warning(f"Unrestrict user error: {e}", exc_info=True) finally: lock and glovar.locks["ban"].release() return result
def unmute(bot: ShModBot, message: Message): """Removes a users mute. Parameters: bot (ShModBot): The bot itself message (Message): The message triggering the handler """ message.delete() try: bot.restrict_chat_member( chat_id=message.chat.id, user_id=message.reply_to_message.from_user.id, permissions=ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, ), ) except Exception as err: bot.send_message(ShModBot.ADMIN_GROUP_ID, f"`{err}`")
async def restrict_usr(client, message): await message.edit("`Trying to Mute user...`") is_admin = await admin_check(message) chat_id = message.chat.id if not is_admin: return if len(message.command) == 2: user_id = message.command[1] try: from_user = await client.get_users(user_id) except Exception: await message.edit("`no valid user_id or message specified`") return elif message.reply_to_message: from_user = await client.get_users( message.reply_to_message.from_user.id) else: await message.edit("`no valid user_id or message specified`") return try: get_mem = await client.get_chat_member(chat_id, from_user) await client.restrict_chat_member(chat_id, user_id, ChatPermissions()) await message.edit(f"`Muted {get_mem.first_name} `") except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
def handlerJoin(client, message): if message.chat.id == -1001128902578 or message.chat.id == -1001244432522: # speck and memes or debug if message.new_chat_members is not None: new_chat_members = message.new_chat_members elif message.reply_to_message is not None and bot.admin(message.from_user.id): message.delete() new_chat_members = [message.reply_to_message.from_user] else: message.delete() new_chat_members = [message.from_user] for user in new_chat_members: if not user.is_self: if not bot.admin(user.id): try: message.chat.restrict_member(user.id, ChatPermissions(can_send_messages=False)) uuid_generated = uuid_gen(user, message.chat.id) msg = message.reply(bot.settings['welcome'].format(message.chat.title, user.first_name, user.id) if 'welcome' in bot.settings else 'Welcome', reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton( text="Click Me", url=f"https://t.me/{bot.settings['my_username']}?start={uuid_generated}" )]])) update_msg_id(uuid_generated, msg.message_id) timer_set(f"{user.id}_{message.chat.id}", ban_log, args=[client, uuid_generated, user.id]) timer_set(f"{message.message_id}_{message.chat.id}", message.delete, args=[]) except Exception as e: print(e) else: message.reply( f"Un amministratore è entrato nel gruppo. Salutate [{message.from_user.first_name}](tg://user?id={message.from_user.id})!")
def SendMsg(client, message): cws = sql.fs_settings(message.chat.id) if cws: user_id = message.from_user.id if not client.get_chat_member(message.chat.id, user_id).status in ( "administrator", "creator") and not user_id in Config.SUDO_USERS: first_name = message.from_user.first_name channel = cws.channel try: client.get_chat_member(channel, user_id) except UserNotParticipant: try: sent_message = message.reply_text( "ℹ [{}](tg://user?id={}), You Are **Not Subscribed** To My [Channel](https://t.me/{}) Yet. Please 👉 [Join](https://t.me/{}) And **Press The Button Below** [👇](https://telegra.ph/file/e058c8f4a2a8355ccf4fa.jpg) To Unmute Yourself." .format(first_name, user_id, channel, channel), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("🔔 UnMute Me 🔕", callback_data="onButtonPress") ]])) client.restrict_chat_member( message.chat.id, user_id, ChatPermissions(can_send_messages=False)) except ChatAdminRequired: sent_message.edit( "❗ **I'm Not An Admin In Here.**\nMake Me Admin With Ban User Permission Or Turn Off ForceSubscribe." ) except ChatAdminRequired: client.send_message( message.chat.id, text= f"❗ **I'm Not An Admin In @{channel}**\nMake Me Admin In The Channel Or Turn Of ForceSubscribe." )
async def ungmute_user(msg: Message): """ unmute a user globally """ await msg.edit("`UnGMuting this User...`") if msg.reply_to_message: user_id = msg.reply_to_message.from_user.id else: user_id = msg.input_str 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.err("User Not Found in My GMute List") 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}`")) 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( can_send_messages=chat.permissions.can_send_messages, can_send_media_messages=chat.permissions. can_send_media_messages, can_send_stickers=chat.permissions.can_send_stickers, can_send_animations=chat.permissions. can_send_animations, can_send_games=chat.permissions.can_send_games, can_use_inline_bots=chat.permissions. can_use_inline_bots, can_add_web_page_previews=chat.permissions. can_add_web_page_previews, can_send_polls=chat.permissions.can_send_polls, can_change_info=chat.permissions.can_change_info, can_invite_users=chat.permissions.can_invite_users, can_pin_messages=chat.permissions.can_pin_messages)) 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 unmute_usr(message: Message): """ unmute user from tg group """ chat_id = message.chat.id await message.edit("`Trying to Unmute User.. Hang on!! ⏳`") if message.input_str: user_id = message.input_str elif message.reply_to_message: user_id = message.reply_to_message.from_user.id else: await message.edit(text="`no valid user_id or message specified,`" "`do .help unmute for more info`", del_in=5) return try: get_mem = await message.client.get_chat_member(chat_id, user_id) await message.client.restrict_chat_member( chat_id, user_id, ChatPermissions( can_send_messages=message.chat.permissions.can_send_messages, can_send_media_messages=message.chat.permissions. can_send_media_messages, can_send_stickers=message.chat.permissions.can_send_stickers, can_send_animations=message.chat.permissions. can_send_animations, can_send_games=message.chat.permissions.can_send_games, can_use_inline_bots=message.chat.permissions. can_use_inline_bots, can_add_web_page_previews=message.chat.permissions. can_add_web_page_previews, can_send_polls=message.chat.permissions.can_send_polls, can_change_info=message.chat.permissions.can_change_info, can_invite_users=message.chat.permissions.can_invite_users, can_pin_messages=message.chat.permissions.can_pin_messages)) await message.edit("`🛡 Successfully Unmuted..`", del_in=5) await CHANNEL.log( f"#UNMUTE\n\n" f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " f"(`{get_mem.user.id}`)\n" f"CHAT: `{message.chat.title}` (`{chat_id}`)") except UsernameInvalid: await message.edit("`invalid username, try again with valid info ⚠`", del_in=5) except PeerIdInvalid: await message.edit( "`invalid username or userid, try again with valid info ⚠`", del_in=5) except UserIdInvalid: await message.edit("`invalid userid, try again with valid info ⚠`", del_in=5) except Exception as e_f: await message.edit(f"`something went wrong!` 🤔\n\n**ERROR:** `{e_f}`", del_in=5)
def restrict_user(client: Client, gid: int, uid: Union[int, str]) -> bool: # Restrict a user try: if uid in glovar.bad_ids["users"]: return True thread(restrict_chat_member, (client, gid, uid, ChatPermissions())) return True except Exception as e: logger.warning(f"Restrict user error: {e}", exc_info=True) return False
def ban_user(client: Client, gid: int, uid: Union[int, str]) -> bool: # Ban a user try: if glovar.configs[gid].get("restrict"): thread(restrict_chat_member, (client, gid, uid, ChatPermissions())) else: thread(kick_chat_member, (client, gid, uid)) return True except Exception as e: logger.warning(f"Ban user error: {e}", exc_info=True) return False
def restrict_user(client: Client, gid: int, uid: Union[int, str]) -> bool: # Restrict a user result = False try: if uid in glovar.bad_ids["users"] and gid not in glovar.ignore_ids[ "user"]: return True result = restrict_chat_member(client, gid, uid, ChatPermissions()) except Exception as e: logger.warning(f"Restrict user error: {e}", exc_info=True) return result
async def unrestrict_usr(client, message): await message.edit("`Trying to Unmute user...`") is_admin = await admin_check(message) get_group = await client.get_chat(chat_id) chat_id = message.chat.id amsg = get_group.permissions.can_send_messages amedia = get_group.permissions.can_send_media_messages astickers = get_group.permissions.can_send_stickers aanimations = get_group.permissions.can_send_animations agames = get_group.permissions.can_send_games ainlinebots = get_group.permissions.can_use_inline_bots awebprev = get_group.permissions.can_add_web_page_previews apolls = get_group.permissions.can_send_polls ainfo = get_group.permissions.can_change_info ainvite = get_group.permissions.can_invite_users apin = get_group.permissions.can_pin_messages if not is_admin: return if len(message.command) == 2: user_id = message.command[1] try: from_user = await client.get_users(user_id) except Exception: await message.edit("`no valid user_id or message specified`") return elif message.reply_to_message: from_user = await client.get_users( message.reply_to_message.from_user.id) else: await message.edit("`no valid user_id or message specified`") return try: get_mem = await client.get_chat_member(chat_id, from_user) await client.restrict_chat_member( chat_id, user_id, ChatPermissions(can_send_messages=amsg, can_send_media_messages=amedia, can_send_stickers=astickers, can_send_animations=aanimations, can_send_games=agames, can_use_inline_bots=ainlinebots, can_add_web_page_previews=awebprev, can_send_polls=apolls, can_change_info=ainfo, can_invite_users=ainvite, can_pin_messages=apin)) await message.edit(f"`Unmuted {get_mem.first_name} `") except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
def SendMsg(client, message): user_id = message.from_user.id first_name = message.from_user.first_name chat_id = message.chat.id try: client.get_chat_member(channel_username, user_id) return except pyrogram.errors.exceptions.bad_request_400.UserNotParticipant: message.reply_text( "[{}](tg://user?id={}), you are **not subscribed** to my [channel](https://t.me/{}) yet. Please [join](https://t.me/{}) and **press the button below** to unmute yourself.".format(first_name, user_id, channel_username, channel_username), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("UnMute Me", callback_data="onButtonPress")]] ) ) client.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=False))
def mute(bot: ShModBot, message: Message): """Mutes a group member. Parameters: bot (ShModBot): The bot itself message (Message): The message triggering the handler """ message.delete() try: bot.restrict_chat_member( chat_id=message.chat.id, user_id=message.reply_to_message.from_user.id, permissions=ChatPermissions(), until_date=timer(message), ) except Exception as err: bot.send_message(ShModBot.ADMIN_GROUP_ID, f"`{err}`")
async def check_flood(client, message): """ check all messages """ if DB_URI is None: return # if not CHAT_FLOOD: return if not str(message.chat.id) in CHAT_FLOOD: return is_admin = await admin_check(message) if is_admin: return should_ban = sql.update_flood(message.chat.id, message.from_user.id) if not should_ban: return try: await message.chat.restrict_member( user_id=message.from_user.id, permissions=ChatPermissions( ) ) except Exception as e: # pylint:disable=C0103,W0703 no_admin_privilege_message = await message.reply_text( text="""<b>Automatic AntiFlooder</b> @admin <a href='tg://user?id={}'>{}</a> is flooding this chat. `{}`""".format(message.from_user.id, message.from_user.first_name, str(e)) ) await asyncio.sleep(10) await no_admin_privilege_message.edit_text( text="https://t.me/c/1092696260/724970", disable_web_page_preview=True ) else: await client.send_message( chat_id=message.chat.id, text="""<b>Automatic AntiFlooder</b> <a href='tg://user?id={}'>{}</a> has been automatically restricted because he reached the defined flood limit. #FLOOD""".format( message.from_user.id, message.from_user.first_name ), reply_to_message_id=message.message_id )
def unrestrict_user(client: Client, gid: int, uid: Union[int, str]) -> bool: # Unrestrict a user try: permissions = ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True) thread(restrict_chat_member, (client, gid, uid, permissions)) return True except Exception as e: logger.warning(f"Unrestrict user error: {e}", exc_info=True) return False
def adminfuncs(app, chat_id, user_id, nyanpasu_id, katsu_id, mmbr_id, msgs, message): user = app.get_chat_member(chat_id, user_id) if (user.status is 'administrator' or user.status is 'creator' or mmbr_id == katsu_id or mmbr_id == nyanpasu_id): nyanpasu = app.get_chat_member(chat_id, nyanpasu_id) if (nyanpasu.status is 'administrator' or nyanpasu.status is 'creator'): print('admin funcs at ' + str(chat_id) + ' - ' + str(message.message_id)) if len(msgs) == 3: if 'd' in msgs[2]: mult = 86400 elif 'h' in msgs[2]: mult = 3600 elif 'm' in msgs[2]: mult = 60 elif 's' in msgs[2]: mult = 1 time = int(msgs[1]) * mult elif len(msgs) == 2: time = int(msgs[1]) elif len(msgs) == 1: time = 120 time = int(clock.time() + time) try: if msgs[0] in '!kick': app.kick_chat_member(chat_id, user_id, time) txt = '**' + message.reply_to_message.from_user.first_name + '** кикнут из чата.' elif msgs[0] in '!mute': app.restrict_chat_member( chat_id, user_id, ChatPermissions(can_send_messages=False), time) txt = '**' + message.reply_to_message.from_user.first_name + '** отправлен в Р/О.' except Exception as e: if 'USER_ADMIN_INVALID' in str(e): txt = 'Невозможно забанить администратора.' else: txt = str(e) else: txt = service['nyan_admin_err'] else: txt = service['perm_err'] app.send_message(chat_id, txt, reply_to_message_id=message.message_id)
async def cb_query(bot: Assistant, query: CallbackQuery): action, user_id = query.data.split(".") user_id = int(user_id) text = query.message.text if action == "unban": if query.from_user.id != Assistant.CREATOR_ID: await query.answer("Only Dan can pardon banned users", show_alert=True) return await bot.restrict_chat_member( query.message.chat.id, user_id, ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_stickers=True, can_send_animations=True, can_send_games=True, can_use_inline_bots=True, can_add_web_page_previews=True, can_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True ) ) await query.edit_message_text(f"~~{text.markdown}~~\n\nPardoned") if action == "remove": # Dummy Message object to check if the user is admin. # Re: https://t.me/pyrogramlounge/324583 dummy = Message( message_id=0, from_user=query.from_user, chat=query.message.chat ) if query.from_user.id != user_id and not bot.is_admin(dummy): await query.answer("Only Admins can remove the help messages.") await query.message.delete()
async def swear_jar_resp(c: Client, m: Message): global swear_jar_counter chat_admins = await c.get_chat_members(chat_id=m.chat.id, filter='administrators') chat_admins_list = [x['user']['id'] for x in chat_admins] if m.from_user.id not in chat_admins_list and not m.service: mention = f"<a href='tg://user?id={m.from_user.id}'>{m.from_user.first_name}</a>" try: if profanity.contains_profanity( m.text.encode('ascii', 'ignore').decode('ascii')): swear_jar_counter.append(m.from_user.id) swear_count = swear_jar_counter.count(m.from_user.id) if 3 <= swear_count < 6: owe_value = swear_count * 10 await m.reply( text= f"Hey {mention}! I guess you need to consider that you are at <b>a public chat</b> i.e. " f"talk with some respect! \nYou owe {Emoji.MONEY_WITH_WINGS} <i>${owe_value}</i> " f"{Emoji.MONEY_WITH_WINGS} to SwearJar now. \n<i>Once you reach <b>$60</b> you will be " f"restricted for a day from sending messages within this chat.</i>", parse_mode="html") elif swear_count == 6: swear_jar_counter = [ x for x in swear_jar_counter if x != m.from_user.id ] await c.restrict_chat_member( chat_id=m.chat.id, user_id=m.from_user.id, permissions=ChatPermissions(can_send_messages=False), until_date=int(time.time() + 86400)) await m.reply_text( text= f"{Emoji.EXPLODING_HEAD} Ok that is enough {mention}! Now be restricted for " f"the next {Emoji.ALARM_CLOCK} 24HRS.") except Exception as e: logging.error(str(e))
async def mute(bot, update): user = update.from_user.id u = await bot.get_chat_member(update.chat.id, user) if u.status == "administrator" or u.status == "creator": if update.reply_to_message is None: command, user = update.text.split(" ", 2) #user_id = int(user) if user.isdigit() == True: user_id = int(user) else: user_id = str(user) try: b = await bot.get_chat_member(update.chat.id, user_id) except RPCError: await bot.send_message(chat_id=update.chat.id, text="An unknown error while banning", reply_to_message_id=update.message_id) return mute_text = "<a href='tg://user?id={}'>{}</a> Muted <a href='tg://user?id={}'>{}</a>!".format( update.from_user.id, update.from_user.first_name, b.user.id, b.user.first_name) else: user_id = update.reply_to_message.from_user.id mute_text = "<a href='tg://user?id={}'>{}</a> Muted <a href='tg://user?id={}'>{}</a>!".format( update.from_user.id, update.from_user.first_name, update.reply_to_message.from_user.id, update.reply_to_message.from_user.first_name) await bot.restrict_chat_member( chat_id=update.chat.id, user_id=user_id, permissions=ChatPermissions(can_invite_users=True)) await bot.send_message(chat_id=update.chat.id, text=mute_text, reply_to_message_id=update.message_id) else: await bot.send_message(chat_id=update.chat.id, text="Who are you Non-Admin to command me?", reply_to_message_id=update.message_id)
def clear_user(client, hex, id_user, accept): if hex in bot.pending: if not accept: client.get_chat(bot.pending[hex]["chat_id"]).kick_member(id_user) else: client.get_chat(bot.pending[hex]["chat_id"]).restrict_member( id_user, ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_stickers=True, can_send_animations=True, can_send_games=True, can_use_inline_bots=True, can_add_web_page_previews=True, can_invite_users=True, can_change_info=True, can_send_polls=True, can_pin_messages=True, ), ) try: bot.scheduler.remove_job( f"{id_user}_{bot.pending[hex]['chat_id']}") except Exception as e: print(e) try: user = client.get_chat_member(bot.pending[hex]["chat_id"], bot.pending[hex]["user_id"]).user client.edit_message_text( bot.pending[hex]["chat_id"], bot.pending[hex]["message_id"], f"L'utente [{user.first_name}](tg://user?id={user.id})" f"\n{'non ' if not accept else ''}ha accettato il disclaimer.\n{'È stato rimosso dal gruppo.' if not accept else ''}", ) except Exception as e: print(e) del bot.pending[hex]
def SendMsg(client, message): cws = sql.fs_settings(message.chat.id) if cws: user_id = message.from_user.id if not client.get_chat_member(message.chat.id, user_id).status in ("administrator", "creator") and not user_id in Config.SUDO_USERS: first_name = message.from_user.first_name channel = cws.channel try: client.get_chat_member(channel, user_id) except UserNotParticipant: try: sent_message = message.reply_text( "[{}](tg://user?id={}), you are **not subscribed** to my [channel](https://t.me/{}) yet. Please [join](https://t.me/{}) and **press the button below** to unmute yourself.".format(first_name, user_id, channel, channel), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("UnMute Me", callback_data="onButtonPress")]] ) ) client.restrict_chat_member(message.chat.id, user_id, ChatPermissions(can_send_messages=False)) except ChatAdminRequired: sent_message.edit("❗ **I am not an admin in here.**\n__Make me admin with ban user permission or turn off ForceSubscribe.__") except ChatAdminRequired: client.send_message(message.chat.id, text=f"❗ **I am not an admin in @{channel}**\n__Make me admin in the channel or turn of ForceSubscribe.__")
async def mute_user(_, message): is_admin = await admin_check(message) if not is_admin: return user_id, user_first_name = extract_user(message) try: await message.chat.restrict_member(user_id=user_id, permissions=ChatPermissions()) except Exception as error: await message.reply_text(str(error)) else: if str(user_id).lower().startswith("@"): await message.reply_text("👍🏻 " f"{user_first_name}" " ലവന്റെ വായടച്ചിട്ടുണ്ട്! 🤐") else: await message.reply_text("👍🏻 " f"<a href='tg://user?id={user_id}'>" "ലവന്റെ" "</a>" " വായടച്ചിട്ടുണ്ട്! 🤐")
async def ban(bot: Assistant, message: Message): """Ban a user in chat""" reply = message.reply_to_message if not reply: return # Don't ban admins if bot.is_admin(reply): m = await message.reply("Sorry, I don't ban administrators") await asyncio.sleep(5) await m.delete() return await bot.restrict_chat_member(message.chat.id, reply.from_user.id, ChatPermissions()) await message.reply( f"__Banned {reply.from_user:mention} indefinitely__", quote=False, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("Give grace", f"unban.{reply.from_user.id}") ]]) )
async def restrict_usr_tmp(client, message): await message.edit("`Trying to Temporarily Mute user...`") is_admin = await admin_check(message) chat_id = message.chat.id if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) until_date_val = extract_time(message.command[1]) try: await message.chat.restrict_member(user_id=user_id, permisssions=ChatPermissions(), until_date=until_date_val) if str(user_id).lower().startswith("@"): await message.edit(f"**T Muted** {user_first_name} till {until_date_val}") await client.send_message(PRIVATE_GROUP_ID, f"#TEMPMUTE\nTemp. Muted {user_first_name} in chat {message.chat.title} till {until_date_val}") else: await message.edit("**T Muted** {} till {}".format(mention_markdown(user_first_name, user_id), until_date_val)) await client.send_message(PRIVATE_GROUP_ID, "#TEMPMUTE\nTemp. Muted {} in chat {}".format(mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def gmute_at_entry(msg: Message): """ handle gmute """ chat_id = msg.chat.id for user in msg.new_chat_members: user_id = user.id first_name = user.first_name gmuted = await GMUTE_USER_BASE.find_one({'user_id': user_id}) if gmuted: await asyncio.gather( msg.client.restrict_chat_member(chat_id, user_id, ChatPermissions()), msg.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Muted User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gmuted['reason']}`\n\n" "**Quick Action:** Muted"), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GMuted User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gmuted['reason']}\n**Quick Action:** " f"Muted in {msg.chat.title}")) msg.continue_propagation()