async def tmute_usr(c: Alita, m: Message): if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Я не могу никого замьютить!") return try: user_id, user_first_name, _ = await extract_user(c, m) except Exception: return if not user_id: await m.reply_text("Cannot find user to mute !") return if user_id == Config.BOT_ID: await m.reply_text("Huh, why would I mute myself?") return 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(tlang(m, "admin.support_cannot_restrict")) return try: admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]} except KeyError: admins_group = await admin_cache_reload(m, "mute") if user_id in admins_group: await m.reply_text(tlang(m, "admin.mute.admin_cannot_mute")) return r_id = m.reply_to_message.message_id if m.reply_to_message else m.message_id if m.reply_to_message and len(m.text.split()) >= 2: reason = m.text.split(None, 2)[1] elif not m.reply_to_message and len(m.text.split()) >= 3: reason = m.text.split(None, 2)[2] else: await m.reply_text("Read /help !!") return if not reason: await m.reply_text( "You haven't specified a time to mute this user for!") return split_reason = reason.split(None, 1) time_val = split_reason[0].lower() reason = split_reason[1] if len(split_reason) > 1 else "" mutetime = await extract_time(m, time_val) if not mutetime: return try: await m.chat.restrict_member( user_id, ChatPermissions(), mutetime, ) LOGGER.info(f"{m.from_user.id} tmuted {user_id} in {m.chat.id}") txt = (tlang(m, "admin.mute.muted_user")).format( admin=(await mention_html(m.from_user.first_name, m.from_user.id)), muted=(await mention_html(user_first_name, user_id)), ) if reason: txt += f"\n<b>Reason</b>: {reason}" keyboard = InlineKeyboardMarkup([ [ InlineKeyboardButton( "Снять мут", callback_data=f"unmute_={user_id}", ), ], ], ) await m.reply_text(txt, reply_markup=keyboard, reply_to_message_id=r_id) except ChatAdminRequired: await m.reply_text(tlang(m, "admin.not_admin")) except RightForbidden: await m.reply_text(tlang(m, "admin.mute.bot_no_right")) except UserNotParticipant: await m.reply_text( "How can I mute a user who is not a part of this chat?") except RPCError as ef: await m.reply_text((tlang(m, "general.some_error")).format( SUPPORT_GROUP=SUPPORT_GROUP, ef=ef, ), ) LOGGER.error(ef) return
async def lock_perm(c: TelePyroBot, m: Message): msg = "" media = "" stickers = "" animations = "" games = "" inlinebots = "" webprev = "" polls = "" info = "" invite = "" pin = "" perm = "" lock_type = m.text.split(None, 1)[1] chat_id = m.chat.id if not lock_type: await m.edit_text("`I Can't Lock Nothing! (-‸ლ)`") await asyncio.sleep(5) await m.delete() return get_perm = await c.get_chat(chat_id) msg = get_perm.permissions.can_send_messages media = get_perm.permissions.can_send_media_messages stickers = get_perm.permissions.can_send_stickers animations = get_perm.permissions.can_send_animations games = get_perm.permissions.can_send_games inlinebots = get_perm.permissions.can_use_inline_bots webprev = get_perm.permissions.can_add_web_page_previews polls = get_perm.permissions.can_send_polls info = get_perm.permissions.can_change_info invite = get_perm.permissions.can_invite_users pin = get_perm.permissions.can_pin_messages if lock_type == "all": try: await c.set_chat_permissions(chat_id, ChatPermissions()) await m.edit_text( text="**🔒 Locked all permission from this Chat!**") await asyncio.sleep(5) await m.delete() await c.send_message( PRIVATE_GROUP_ID, "#LOCK\n\nCHAT: `{}` (`{}`)\nPERMISSIONS: `All Permissions`". format(get_perm.title, chat_id), ) except Exception as e_f: await m.edit_text( f"`I don't have permission to do that >︿<`\n\n**ERROR:** `{e_f}`" ) await asyncio.sleep(5) await m.delete() return if lock_type == "msg": msg = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type == "inlinebots": inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: await m.edit_text("`Invalid Lock Type! ¯\_(ツ)_/¯`") await asyncio.sleep(5) await m.delete() return try: await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=msg, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin, ), ) await m.edit_text(text=f"**🔒 Locked {perm} for this chat!**") await asyncio.sleep(5) await m.delete() await c.send_message( PRIVATE_GROUP_ID, "#LOCK\n\nCHAT: `{}` (`{}`)\nPERMISSIONS: `{} Permission`".format( get_perm.title, chat_id, perm), ) except Exception as e_f: await m.edit_text(text=r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`") await asyncio.sleep(5) await m.delete() return
async def lock_permission(client, message): """module that locks group permissions""" if message.chat.type in ["group", "supergroup"]: cmd = message.command is_admin = await admin_check(message) if not is_admin: await message.delete() return messages = "" media = "" stickers = "" animations = "" games = "" inlinebots = "" webprev = "" polls = "" info = "" invite = "" pin = "" perm = "" lock_type = " ".join(cmd[1:]) chat_id = message.chat.id if not lock_type: await message.delete() return get_perm = await client.get_chat(chat_id) messages = get_perm.permissions.can_send_messages media = get_perm.permissions.can_send_media_messages stickers = get_perm.permissions.can_send_stickers animations = get_perm.permissions.can_send_animations games = get_perm.permissions.can_send_games inlinebots = get_perm.permissions.can_use_inline_bots webprev = get_perm.permissions.can_add_web_page_previews polls = get_perm.permissions.can_send_polls info = get_perm.permissions.can_change_info invite = get_perm.permissions.can_invite_users pin = get_perm.permissions.can_pin_messages if lock_type == "all": try: await client.set_chat_permissions(chat_id, ChatPermissions()) await edrep(message, text=tld('lock_all')) await asyncio.sleep(5) await message.delete() except Exception as e: await edrep(message, text=tld('denied_permission')) return if lock_type == "messages": messages = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type == "inlinebots": inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: print(e) await message.delete() return try: await client.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=messages, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin, ), ) await edrep(message, text=tld('lock_chat').format(perm)) await asyncio.sleep(5) await message.delete() except Exception as e: print(e) await message.delete() return else: await message.delete()
async def bl(client, message): #log_id = chat_id = message.chat.id user_id = message.from_user.id mention = message.from_user.mention chat_title = message.chat.title admin_list = await adminlist(client, chat_id) text = (message.text).lower() data_list = [] mode_list = [] if (user_id not in admin_list) and (user_id not in OWNER): check = sql.blacklist_list(chat_id) if not check: return for trigger in check: if trigger.trigger in text: time_raw = trigger.time time = create_time(time_raw) if trigger.mode == 0: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) elif trigger.mode == 1: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) elif trigger.mode == 2: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) elif trigger.mode == 3: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) elif trigger.mode == 4: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) elif trigger.mode == 5: data_list.append({ 'trigger': trigger.trigger, 'mode': trigger.mode }) if trigger.mode not in mode_list: mode_list.append(trigger.mode) mode_list.sort() if len(mode_list) > 1: mode = mode_list[len(mode_list) - 1] for data in data_list: if data["mode"] == mode: trigger = data["trigger"] break elif len(mode_list) == 1: mode = mode_list[0] trigger = data_list[0]["trigger"] else: return if mode == 0: await message.delete() #await client.send_message(log_id,"#BLACKLIST_DELETE\n{}\nUser : {}\nAlasan : Mengatakan <code>{}</code>".format(chat_title,mention,trigger)) elif mode == 1: await message.delete() await client.restrict_chat_member(chat_id, user_id, ChatPermissions(), time) await message.reply_text( "Dibisukan untuk {}\nUser : {}\nAlasan : Mengatakan <code>{}</code>" .format(time_raw, mention, trigger), disable_web_page_preview=True) #await client.send_message(log_id,"#BLACKLIST_TMUTE\n{}\nUser : {}\nDurasi : {}\nAlasan : Mengatakan <code>{}</code>".format(chat_title,mention,time_raw,trigger)) elif mode == 2: await message.delete() await client.restrict_chat_member(chat_id, user_id, ChatPermissions()) await message.reply_text( "Dibisukan!\nUser : {}\nAlasan : Mengatakan <code>{}</code>". format(mention, trigger), disable_web_page_preview=True) #await client.send_message(log_id,"#BLACKLIST_MUTE\n{}\nUser : {}\nAlasan : Mengatakan <code>{}</code>".format(chat_title,mention,trigger)) elif mode == 3: await message.delete() await client.kick_chat_member(chat_id, user_id) await client.unban_chat_member(chat_id, user_id) await message.reply_sticker("https://t.me/CactusID_OOT/116113") await message.reply_text( "Ditendang! 😝\nUser : {}\nAlasan : Mengatakan <code>{}</code>". format(mention, trigger), disable_web_page_preview=True) #await client.send_message(log_id,"#BLACKLIST_KICK\n{}\nUser : {}\nAlasan : Mengatakan <code>{}</code>".format(chat_title,mention,trigger)) elif mode == 4: await message.delete() await client.kick_chat_member(chat_id, user_id, time) await message.reply_sticker("https://t.me/CactusID_OOT/116113") await message.reply_text( "Terbanned untuk {}! 😝\nUser : {}\nAlasan : Mengatakan <code>{}</code>" .format(time_raw, mention, trigger), disable_web_page_preview=True) #await client.send_message(log_id,"#BLACKLIST_TBAN\n{}\nUser : {}\nDurasi : {}\nAlasan : Mengatakan <code>{}</code>".format(chat_title,mention,time_raw,trigger)) elif mode == 5: await message.delete() await client.kick_chat_member(chat_id, user_id) await message.reply_sticker("https://t.me/CactusID_OOT/116113") await message.reply_text( "Terbanned! 😝\nUser : {}\nAlasan : Mengatakan <code>{}</code>". format(mention, trigger), disable_web_page_preview=True)
async def approve_user(c: Alita, m: Message): db = Approve(m.chat.id) chat_title = m.chat.title try: user_id, user_first_name, _ = await extract_user(c, m) except Exception: return if not user_id: await m.reply_text( "I don't know who you're talking about, you're going to need to specify a user!", ) return try: member = await m.chat.get_member(user_id) except UserNotParticipant: await m.reply_text("This user is not in this chat!") return except RPCError as ef: await m.reply_text( f"<b>Error</b>: <code>{ef}</code>\nReport it to @{SUPPORT_GROUP}", ) return if member.status in ("administrator", "creator"): await m.reply_text( "User is already admin - blacklists and locks already don't apply to them.", ) return already_approved = db.check_approve(user_id) if already_approved: await m.reply_text( f"{(await mention_html(user_first_name, user_id))} is already approved in {chat_title}", ) 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 await m.chat.restrict_member( user_id=user_id, 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, ), ) await m.reply_text(( f"{(await mention_html(user_first_name, user_id))} has been approved in {chat_title}!\n" "They will now be ignored by blacklists, locks and antiflood!"), ) return
async def welcome(_, message: Message): global answers_dicc """ Get cached answers from mongodb in case of bot's been restarted or crashed. """ answers_dicc = await get_captcha_cache() """Mute new member and send message with button""" if not await is_captcha_on(message.chat.id): return for member in message.new_chat_members: try: if member.id in SUDOERS: continue # ignore sudos if await is_gbanned_user(member.id): await message.chat.kick_member(member.id) await message.reply_text( f"{member.mention} was globally banned, and got removed," + " if you think this is a false gban, you can appeal" + " for this ban in support chat.") continue if member.is_bot: continue # ignore bots await message.chat.restrict_member(member.id, ChatPermissions()) text = ( f"{(member.mention())} Are you human?\n" f"Solve this captcha in {WELCOME_DELAY_KICK_SEC} seconds and 4 attempts or you'll be kicked." ) except ChatAdminRequired: return # Generate a captcha image, answers and some wrong answers captcha = generate_captcha() captcha_image = captcha[0] captcha_answer = captcha[1] wrong_answers = captcha[2] # This consists of 8 wrong answers correct_button = InlineKeyboardButton( f"{captcha_answer}", callback_data=f"pressed_button {captcha_answer} {member.id}", ) temp_keyboard_1 = [correct_button] # Button row 1 temp_keyboard_2 = [] # Botton row 2 temp_keyboard_3 = [] for i in range(2): temp_keyboard_1.append( InlineKeyboardButton( f"{wrong_answers[i]}", callback_data= f"pressed_button {wrong_answers[i]} {member.id}", )) for i in range(2, 5): temp_keyboard_2.append( InlineKeyboardButton( f"{wrong_answers[i]}", callback_data= f"pressed_button {wrong_answers[i]} {member.id}", )) for i in range(5, 8): temp_keyboard_3.append( InlineKeyboardButton( f"{wrong_answers[i]}", callback_data= f"pressed_button {wrong_answers[i]} {member.id}", )) shuffle(temp_keyboard_1) keyboard = [temp_keyboard_1, temp_keyboard_2, temp_keyboard_3] shuffle(keyboard) verification_data = { "chat_id": message.chat.id, "user_id": member.id, "answer": captcha_answer, "keyboard": keyboard, "attempts": 0, } keyboard = InlineKeyboardMarkup(keyboard) # Append user info, correct answer and answers_dicc.append(verification_data) # keyboard for later use with callback query button_message = await message.reply_photo( photo=captcha_image, caption=text, reply_markup=keyboard, quote=True, ) os.remove(captcha_image) """ Save captcha answers etc in mongodb in case bot gets crashed or restarted. """ await update_captcha_cache(answers_dicc) asyncio.create_task( kick_restricted_after_delay(WELCOME_DELAY_KICK_SEC, button_message, member)) await asyncio.sleep(0.5)
async def mute_usr(message: Message): """ mute user from tg group """ chat_id = message.chat.id flags = message.flags minutes = flags.get("-m", 0) hours = flags.get("-h", 0) days = flags.get("-d", 0) await message.edit("`Trying to Mute User.. Hang on!! ⏳`") user_id, reason = message.extract_user_and_text if not user_id: await message.edit( text="`no valid user_id or message specified,`" "`do .help mute for more info`", del_in=5, ) return if minutes: mute_period = int(minutes) * 60 _time = f"{int(minutes)}m" elif hours: mute_period = int(hours) * 3600 _time = f"{int(hours)}h" elif days: mute_period = int(days) * 86400 _time = f"{int(days)}d" if flags: try: get_mem = await message.client.get_chat_member(chat_id, user_id) await message.client.restrict_chat_member( chat_id, user_id, ChatPermissions(), int(time.time() + mute_period)) await message.edit( "#MUTE\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}`)\n" f"MUTE UNTIL: `{_time}`\n" f"REASON: `{reason}`", log=__name__, ) 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( "`something went wrong 🤔, do .help mute for more info`\n\n" f"**ERROR**: `{e_f}`", del_in=5, ) else: try: get_mem = await message.client.get_chat_member(chat_id, user_id) await message.client.restrict_chat_member(chat_id, user_id, ChatPermissions()) await message.edit( "#MUTE\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}`)\n" f"MUTE UNTIL: `forever`\n" f"REASON: `{reason}`", log=__name__, ) 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( "`something went wrong 🤔, do .help mute for more info`\n\n" f"**ERROR**: {e_f}", del_in=5, )
async def mute_command(client: Client, message: Message): cause = await text(client, message) if message.reply_to_message \ and message.chat.type not in ["private", "channel"]: mute_seconds: int = 0 for character in 'mhdw': match = re.search(rf'(\d+|(\d+\.\d+)){character}', message.text) if match: if character == 'm': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 60 // 1) if character == 'h': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 3600 // 1) if character == 'd': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 86400 // 1) if character == 'w': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 604800 // 1) if mute_seconds > 30: try: await client.restrict_chat_member( message.chat.id, message.reply_to_message.from_user.id, ChatPermissions(), int(time()) + mute_seconds) from_user = message.reply_to_message.from_user mute_time: Dict[str, int] = { 'days': mute_seconds // 86400, 'hours': mute_seconds % 86400 // 3600, 'minutes': mute_seconds % 86400 % 3600 // 60 } message_text = f"<b>{from_user.first_name}</b> <code> was muted for" \ f" {((str(mute_time['days']) + ' day') if mute_time['days'] > 0 else '') + ('s' if mute_time['days'] > 1 else '')}" \ f" {((str(mute_time['hours']) + ' hour') if mute_time['hours'] > 0 else '') + ('s' if mute_time['hours'] > 1 else '')}" \ f" {((str(mute_time['minutes']) + ' minute') if mute_time['minutes'] > 0 else '') + ('s' if mute_time['minutes'] > 1 else '')}</code>" \ + f"\n{'<b>Cause:</b> <i>' + cause.split(' ', maxsplit=2)[2] + '</i>' if len(cause.split()) > 2 else ''}" while ' ' in message_text: message_text = message_text.replace(' ', ' ') await message.edit(message_text) except UserAdminInvalid: await message.edit("<b>No rights</b>") except ChatAdminRequired: await message.edit("<b>No rights</b>") except Exception as e: print(e) await message.edit("<b>No rights</b>") else: try: await client.restrict_chat_member( message.chat.id, message.reply_to_message.from_user.id, ChatPermissions()) message_text = f"<b>{message.reply_to_message.from_user.first_name}</b> <code> was muted for never</code>" \ + f"\n{'<b>Cause:</b> <i>' + cause.split(' ', maxsplit=1)[1] + '</i>' if len(cause.split()) > 1 else ''}" await message.edit(message_text) except UserAdminInvalid: await message.edit("<b>No rights</b>") except ChatAdminRequired: await message.edit("<b>No rights</b>") except Exception as e: print(e) await message.edit("<b>No rights</b>") elif not message.reply_to_message \ and message.chat.type not in ["private", "channel"]: if len(cause.split()) > 1: try: user_to_unmute = await client.get_users(cause.split(" ")[1]) mute_seconds: int = 0 for character in 'mhdw': match = re.search(rf'(\d+|(\d+\.\d+)){character}', message.text) if match: if character == 'm': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 60 // 1) if character == 'h': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 3600 // 1) if character == 'd': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 86400 // 1) if character == 'w': mute_seconds += int( float(match.string[match.start():match.end() - 1]) * 604800 // 1) if mute_seconds > 30: try: await client.restrict_chat_member( message.chat.id, user_to_unmute.id, ChatPermissions(), int(time()) + mute_seconds) mute_time: Dict[str, int] = { 'days': mute_seconds // 86400, 'hours': mute_seconds % 86400 // 3600, 'minutes': mute_seconds % 86400 % 3600 // 60 } message_text = f"<b>{user_to_unmute.first_name}</b> <code> was muted for" \ f" {((str(mute_time['days']) + ' day') if mute_time['days'] > 0 else '') + ('s' if mute_time['days'] > 1 else '')}" \ f" {((str(mute_time['hours']) + ' hour') if mute_time['hours'] > 0 else '') + ('s' if mute_time['hours'] > 1 else '')}" \ f" {((str(mute_time['minutes']) + ' minute') if mute_time['minutes'] > 0 else '') + ('s' if mute_time['minutes'] > 1 else '')}</code>" \ + f"\n{'<b>Cause:</b> <i>' + cause.split(' ', maxsplit=3)[3] + '</i>' if len(cause.split()) > 3 else ''}" while ' ' in message_text: message_text = message_text.replace(' ', ' ') await message.edit(message_text) except UserAdminInvalid: await message.edit("<b>No rights</b>") except ChatAdminRequired: await message.edit("<b>No rights</b>") except Exception as e: print(e) await message.edit("<b>No rights</b>") else: try: await client.restrict_chat_member( message.chat.id, user_to_unmute.id, ChatPermissions()) message_text = f"<b>{user_to_unmute.first_name}</b> <code> was muted for never</code>" \ + f"\n{'<b>Cause:</b> <i>' + cause.split(' ', maxsplit=2)[2] + '</i>' if len(cause.split()) > 2 else ''}" await message.edit(message_text) except UserAdminInvalid: await message.edit("<b>No rights</b>") except ChatAdminRequired: await message.edit("<b>No rights</b>") except Exception as e: print(e) await message.edit("<b>No rights</b>") except PeerIdInvalid: await message.edit("<b>User is not found</b>") except UsernameInvalid: await message.edit("<b>User is not found</b>") except IndexError: await message.edit("<b>User is not found</b>") else: await message.edit("<b>user_id or username</b>") elif message.chat.type in ["private", "channel"]: await message.edit("<b>Unsupported</b>")
async def unlock_perm(message: Message): """ unlock chat permissions from tg group """ unlock_type = message.input_str chat_id = message.chat.id if not unlock_type: await message.edit(text=r"`I Can't Unlock Nothing! (-‸ლ)`", del_in=5) return umsg = message.chat.permissions.can_send_messages umedia = message.chat.permissions.can_send_media_messages ustickers = message.chat.permissions.can_send_stickers uanimations = message.chat.permissions.can_send_animations ugames = message.chat.permissions.can_send_games uinlinebots = message.chat.permissions.can_use_inline_bots uwebprev = message.chat.permissions.can_add_web_page_previews upolls = message.chat.permissions.can_send_polls uinfo = message.chat.permissions.can_change_info uinvite = message.chat.permissions.can_invite_users upin = message.chat.permissions.can_pin_messages if unlock_type == "all": try: await message.client.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True)) await message.edit("**🔓 Unlocked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `All Permissions`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5) return if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type == "inlinebots": uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await message.edit(text=r"`Invalid Unlock Type! ¯\_(ツ)_/¯`", del_in=5) return try: await message.client.set_chat_permissions( chat_id, ChatPermissions(can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin)) await message.edit(f"**🔓 Unlocked {uperm} for this chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `{uperm} Permission`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5)
async def lock_perm(message: Message): """ lock chat permissions from tg group """ lock_type = message.input_str chat_id = message.chat.id if not lock_type: await message.err(r"I Can't Lock Nothing! (-‸ლ)") return if lock_type == "all": try: await message.client.set_chat_permissions(chat_id, ChatPermissions()) await message.edit("**🔒 Locked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `All Permissions`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5, ) return if lock_type in _types: ( msg, media, stickers, animations, games, inlinebots, webprev, polls, info, invite, pin, perm, ) = _get_chat_lock(message, lock_type, True) else: await message.err(r"Invalid lock type! ¯\_(ツ)_/¯") return try: await message.client.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=msg, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin, ), ) await message.edit(f"**🔒 Locked {perm} for this chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `{perm} Permission`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5, )
def lock(client, message): text = (message.text or message.caption).replace(r'\s+', ' ').split(' ', 1) unlock = parse_cmd(text[0])[:2] == 'un' if len(text) < 2: edit(message, f"`{get_translation('wrongCommand')}`") return kilit = text[1].lower() msg = None media = None sticker = None gif = None gamee = None ainline = None webprev = None gpoll = None adduser = None cpin = None changeinfo = None if kilit == 'msg': msg = unlock kullanim = get_translation('lockMsg') elif kilit == 'media': media = unlock kullanim = get_translation('lockMedia') elif kilit == 'gif': gif = unlock sticker = gif kullanim = get_translation('lockGif') elif kilit == 'game': gamee = unlock kullanim = get_translation('lockGame') elif kilit == 'inline': ainline = unlock kullanim = get_translation('lockInline') elif kilit == 'web': webprev = unlock kullanim = get_translation('lockWeb') elif kilit == 'poll': gpoll = unlock kullanim = get_translation('lockPoll') elif kilit == 'invite': adduser = unlock kullanim = get_translation('lockInvite') elif kilit == 'pin': cpin = unlock kullanim = get_translation('lockPin') elif kilit == 'info': changeinfo = unlock kullanim = get_translation('lockInformation') elif kilit == 'all': msg = unlock media = unlock gif = unlock gamee = unlock ainline = unlock webprev = unlock gpoll = unlock adduser = unlock cpin = unlock changeinfo = unlock kullanim = get_translation('lockAll') else: if not kilit: edit( message, get_translation( 'locksUnlockNoArgs' if unlock else 'locksLockNoArgs')) return else: edit(message, get_translation('lockError', ['`', kilit])) return kilitle = client.get_chat(message.chat.id) msg = get_on_none(msg, kilitle.permissions.can_send_messages) media = get_on_none(media, kilitle.permissions.can_send_media_messages) sticker = get_on_none(sticker, kilitle.permissions.can_send_stickers) gif = get_on_none(gif, kilitle.permissions.can_send_animations) gamee = get_on_none(gamee, kilitle.permissions.can_send_games) ainline = get_on_none(ainline, kilitle.permissions.can_use_inline_bots) webprev = get_on_none(webprev, kilitle.permissions.can_add_web_page_previews) gpoll = get_on_none(gpoll, kilitle.permissions.can_send_polls) adduser = get_on_none(adduser, kilitle.permissions.can_invite_users) cpin = get_on_none(cpin, kilitle.permissions.can_pin_messages) changeinfo = get_on_none(changeinfo, kilitle.permissions.can_change_info) try: client.set_chat_permissions( message.chat.id, ChatPermissions(can_send_messages=msg, can_send_media_messages=media, can_send_stickers=sticker, can_send_animations=gif, can_send_games=gamee, can_use_inline_bots=ainline, can_add_web_page_previews=webprev, can_send_polls=gpoll, can_change_info=changeinfo, can_invite_users=adduser, can_pin_messages=cpin)) edit( message, get_translation( 'locksUnlockSuccess' if unlock else 'locksLockSuccess', ['`', kullanim])) except BaseException as e: edit(message, get_translation('lockPerm', ['`', '**', str(e)])) return
async def challenge_callback(client: Client, callback_query: CallbackQuery): query_data = str(callback_query.data) query_id = callback_query.id chat_id = callback_query.message.chat.id user_id = callback_query.from_user.id msg_id = callback_query.message.message_id chat_title = callback_query.message.chat.title user_name = callback_query.from_user.first_name group_config = _config.get(str(chat_id), _config["*"]) if query_data in ["+", "-"]: admins = await client.get_chat_members(chat_id, filter="administrators") if not any([ admin.user.id == user_id and (admin.status == "creator" or admin.can_restrict_members) for admin in admins ]): await client.answer_callback_query( query_id, group_config["msg_permission_denied"]) return ch_id = "{chat}|{msg}".format(chat=chat_id, msg=msg_id) _cch_lock.acquire() # target: int = None timeout_event: None challenge, target, timeout_event = _current_challenges.get( ch_id, (None, None, None)) if ch_id in _current_challenges: # 预防异常 del _current_challenges[ch_id] _cch_lock.release() timeout_event.stop() if query_data == "+": try: await client.restrict_chat_member( chat_id, target, permissions=ChatPermissions( can_send_stickers=True, can_send_messages=True, can_send_media_messages=True, can_send_polls=True)) except ChatAdminRequired: await client.answer_callback_query( query_id, group_config["msg_bot_no_permission"]) return await client.edit_message_text( chat_id, msg_id, group_config["msg_approved"].format(user=user_name), reply_markup=None, ) _me: User = await client.get_me() try: await client.send_message( int(_channel), _config["msg_passed_admin"].format( botid=str(_me.id), targetuser=str(target), groupid=str(chat_id), grouptitle=str(chat_title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) else: try: await client.kick_chat_member(chat_id, target) except ChatAdminRequired: await client.answer_callback_query( query_id, group_config["msg_bot_no_permission"]) return await client.edit_message_text( chat_id, msg_id, group_config["msg_refused"].format(user=user_name), reply_markup=None, ) _me: User = await client.get_me() try: await client.send_message( int(_channel), _config["msg_failed_admin"].format( botid=str(_me.id), targetuser=str(target), groupid=str(chat_id), grouptitle=str(chat_title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) await client.answer_callback_query(query_id) return ch_id = "{chat}|{msg}".format(chat=chat_id, msg=msg_id) _cch_lock.acquire() challenge, target, timeout_event = _current_challenges.get( ch_id, (None, None, None)) _cch_lock.release() if user_id != target: await client.answer_callback_query( query_id, group_config["msg_challenge_not_for_you"]) return None timeout_event.stop() try: await client.restrict_chat_member(chat_id, target, permissions=ChatPermissions( can_send_stickers=True, can_send_messages=True, can_send_media_messages=True, can_send_polls=True)) except ChatAdminRequired: pass correct = str(challenge.ans()) == query_data if correct: try: await client.edit_message_text( chat_id, msg_id, group_config["msg_challenge_passed"], reply_markup=None) _me: User = await client.get_me() except MessageNotModified as e: await client.send_message(int(_channel), 'Bot 运行时发生异常: `' + str(e) + "`") try: await client.send_message( int(_channel), _config["msg_passed_answer"].format( botid=str(_me.id), targetuser=str(target), groupid=str(chat_id), grouptitle=str(chat_title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) else: if not group_config["use_strict_mode"]: await client.edit_message_text( chat_id, msg_id, group_config["msg_challenge_mercy_passed"], reply_markup=None, ) _me: User = await client.get_me() try: await client.send_message( int(_channel), _config["msg_passed_mercy"].format( botid=str(_me.id), targetuser=str(target), groupid=str(chat_id), grouptitle=str(chat_title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) else: try: await client.edit_message_text( chat_id, msg_id, group_config["msg_challenge_failed"], reply_markup=None, ) # await client.restrict_chat_member(chat_id, target) _me: User = await client.get_me() try: await client.send_message( int(_channel), _config["msg_failed_answer"].format( botid=str(_me.id), targetuser=str(target), groupid=str(chat_id), grouptitle=str(chat_title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) except ChatAdminRequired: return if group_config["challenge_timeout_action"] == "ban": await client.kick_chat_member(chat_id, user_id) elif group_config["challenge_timeout_action"] == "kick": await client.kick_chat_member(chat_id, user_id) await client.unban_chat_member(chat_id, user_id) elif group_config["challenge_timeout_action"] == "mute": await client.restrict_chat_member( chat_id, user_id, permissions=ChatPermissions( can_send_other_messages=False, can_send_messages=False, can_send_media_messages=False, can_add_web_page_previews=False, can_send_polls=False)) else: pass if group_config["delete_failed_challenge"]: Timer( client.delete_messages(chat_id, msg_id), group_config["delete_failed_challenge_interval"], ) if group_config["delete_passed_challenge"]: Timer( client.delete_messages(chat_id, msg_id), group_config["delete_passed_challenge_interval"], )
async def challenge_user(client: Client, message: Message): target = message.new_chat_members[0] if message.from_user.id != target.id: if target.is_self: group_config = _config.get(str(message.chat.id), _config["*"]) try: await client.send_message( message.chat.id, group_config["msg_self_introduction"]) _me: User = await client.get_me() try: await client.send_message( int(_channel), _config["msg_into_group"].format( botid=str(_me.id), groupid=str(message.chat.id), grouptitle=str(message.chat.title), ), parse_mode="Markdown", ) except Exception as e: logging.error(str(e)) except ChannelPrivate: return return try: await client.restrict_chat_member( chat_id=message.chat.id, user_id=target.id, permissions=ChatPermissions(can_send_stickers=False, can_send_messages=False, can_send_media_messages=False, can_add_web_page_previews=False, can_send_polls=False, can_send_animations=False)) except ChatAdminRequired: return group_config = _config.get(str(message.chat.id), _config["*"]) challenge = Challenge() def generate_challenge_button(e): choices = [] answers = [] for c in e.choices(): answers.append( InlineKeyboardButton(str(c), callback_data=bytes( str(c), encoding="utf-8"))) choices.append(answers) return choices + [[ InlineKeyboardButton(group_config["msg_approve_manually"], callback_data=b"+"), InlineKeyboardButton(group_config["msg_refuse_manually"], callback_data=b"-"), ]] timeout = group_config["challenge_timeout"] reply_message = await client.send_message( message.chat.id, group_config["msg_challenge"].format(target=target.first_name, target_id=target.id, timeout=timeout, challenge=challenge.qus()), reply_to_message_id=message.message_id, reply_markup=InlineKeyboardMarkup( generate_challenge_button(challenge)), ) _me: User = await client.get_me() chat_id = message.chat.id chat_title = message.chat.title target = message.from_user.id timeout_event = Timer( challenge_timeout(client, message.chat.id, message.from_user.id, reply_message.message_id), timeout=group_config["challenge_timeout"], ) _cch_lock.acquire() _current_challenges["{chat}|{msg}".format( chat=message.chat.id, msg=reply_message.message_id)] = (challenge, message.from_user.id, timeout_event) _cch_lock.release()
async def dmute_usr(c: Alita, m: Message): if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Я не могу никого замьютить!") return if not m.reply_to_message: return await m.reply_text( "No replied message and user to delete and mute!") reason = None if m.reply_to_message: if len(m.text.split()) >= 2: reason = m.text.split(None, 1)[1] else: if len(m.text.split()) >= 3: reason = m.text.split(None, 2)[2] user_id = m.reply_to_message.from_user.id user_first_name = m.reply_to_message.from_user.first_name if not user_id: await m.reply_text("Cannot find user to mute") return if user_id == Config.BOT_ID: await m.reply_text("Huh, why would I mute myself?") return 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(tlang(m, "admin.support_cannot_restrict")) return try: admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]} except KeyError: admins_group = await admin_cache_reload(m, "mute") if user_id in admins_group: await m.reply_text(tlang(m, "admin.mute.admin_cannot_mute")) return try: await m.chat.restrict_member( user_id, ChatPermissions(), ) LOGGER.info(f"{m.from_user.id} dmuted {user_id} in {m.chat.id}") await m.reply_to_message.delete() txt = (tlang(m, "admin.mute.muted_user")).format( admin=(await mention_html(m.from_user.first_name, m.from_user.id)), muted=(await mention_html(user_first_name, user_id)), ) if reason: txt += f"\n<b>Reason</b>: {reason}" keyboard = InlineKeyboardMarkup([ [ InlineKeyboardButton( "Unmute", callback_data=f"unmute_={user_id}", ), ], ], ) await c.send_message(m.chat.id, txt, reply_markup=keyboard) except ChatAdminRequired: await m.reply_text(tlang(m, "admin.not_admin")) except RightForbidden: await m.reply_text(tlang(m, "admin.mute.bot_no_right")) except UserNotParticipant: await m.reply_text( "How can I mute a user who is not a part of this chat?") except RPCError as ef: await m.reply_text((tlang(m, "general.some_error")).format( SUPPORT_GROUP=SUPPORT_GROUP, ef=ef, ), ) LOGGER.error(ef) return
async def unlock_perm(c: Mizuhara, m: Message): res = await admin_check(c, m) if not res: return _ = GetLang(m).strs umsg = "" umedia = "" ustickers = "" uanimations = "" ugames = "" uinlinebots = "" uwebprev = "" upolls = "" uinfo = "" uinvite = "" upin = "" uperm = "" if not len(m.text.split()) >= 2: await m.reply_text("Please enter a permission to unlock!") return unlock_type = m.text.split(" ", 1)[1] chat_id = m.chat.id if not unlock_type: await m.reply_text(_("locks.unlocks_perm.sp_perm")) return get_uperm = await c.get_chat(chat_id) umsg = get_uperm.permissions.can_send_messages umedia = get_uperm.permissions.can_send_media_messages ustickers = get_uperm.permissions.can_send_stickers uanimations = get_uperm.permissions.can_send_animations ugames = get_uperm.permissions.can_send_games uinlinebots = get_uperm.permissions.can_use_inline_bots uwebprev = get_uperm.permissions.can_add_web_page_previews upolls = get_uperm.permissions.can_send_polls uinfo = get_uperm.permissions.can_change_info uinvite = get_uperm.permissions.can_invite_users upin = get_uperm.permissions.can_pin_messages if unlock_type == "all": try: await c.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True, ), ) await prevent_approved(c, m) # Don't lock permissions for approved users! await m.reply_text("🔓 " + _("locks.unlock_all")) except errors.ChatAdminRequired: await m.reply_text(_("general.no_perm_admin")) return if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type == "inlinebots": uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await m.reply_text(_("locks.invalid_lock")) return try: await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin, ), ) await prevent_approved(c, m) # Don't lock permissions for approved users! await m.reply_text("🔓 " + _("locks.unlocked_perm").format(uperm=uperm)) except errors.ChatAdminRequired: await m.reply_text(_("general.no_perm_admin")) return
async def lock_perm(message: Message): """ lock chat permissions from tg group """ lock_type = message.input_str chat_id = message.chat.id if not lock_type: await message.edit(text=r"`I Can't Lock Nothing! (-‸ლ)`", del_in=5) return msg = message.chat.permissions.can_send_messages media = message.chat.permissions.can_send_media_messages stickers = message.chat.permissions.can_send_stickers animations = message.chat.permissions.can_send_animations games = message.chat.permissions.can_send_games inlinebots = message.chat.permissions.can_use_inline_bots webprev = message.chat.permissions.can_add_web_page_previews polls = message.chat.permissions.can_send_polls info = message.chat.permissions.can_change_info invite = message.chat.permissions.can_invite_users pin = message.chat.permissions.can_pin_messages if lock_type == "all": try: await message.client.set_chat_permissions(chat_id, ChatPermissions()) await message.edit("**🔒 Locked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `All Permissions`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5) return if lock_type == "msg": msg = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type == "inlinebots": inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: await message.edit(text=r"`Invalid Lock Type! ¯\_(ツ)_/¯`", del_in=5) return try: await message.client.set_chat_permissions( chat_id, ChatPermissions(can_send_messages=msg, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin)) await message.edit(f"**🔒 Locked {perm} for this chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `{perm} Permission`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5)
async def lock_perm(c: Mizuhara, m: Message): res = await admin_check(c, m) if not res: return _ = GetLang(m).strs msg = "" media = "" stickers = "" animations = "" games = "" inlinebots = "" webprev = "" polls = "" info = "" invite = "" pin = "" perm = "" if not len(m.text.split()) >= 2: await m.reply_text("Please enter a permission to lock!") return lock_type = m.text.split(" ", 1)[1] chat_id = m.chat.id if not lock_type: await m.reply_text(_("locks.locks_perm.sp_perm")) return get_perm = await c.get_chat(chat_id) msg = get_perm.permissions.can_send_messages media = get_perm.permissions.can_send_media_messages stickers = get_perm.permissions.can_send_stickers animations = get_perm.permissions.can_send_animations games = get_perm.permissions.can_send_games inlinebots = get_perm.permissions.can_use_inline_bots webprev = get_perm.permissions.can_add_web_page_previews polls = get_perm.permissions.can_send_polls info = get_perm.permissions.can_change_info invite = get_perm.permissions.can_invite_users pin = get_perm.permissions.can_pin_messages if lock_type == "all": try: await c.set_chat_permissions(chat_id, ChatPermissions()) await prevent_approved(c, m) # Don't lock permissions for approved users! await m.reply_text("🔒 " + _("locks.lock_all")) except errors.ChatAdminRequired: await m.reply_text(_("general.no_perm_admin")) return if lock_type == "msg": msg = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type == "inlinebots": inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: await m.reply_text(_("locks.invalid_lock")) return try: await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=msg, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin, ), ) await prevent_approved(c, m) # Don't lock permissions for approved users! await m.reply_text("🔒 " + _("locks.locked_perm").format(perm=perm)) except errors.ChatAdminRequired: await m.reply_text(_("general.no_perm_admin")) return
await message.reply(f"__Banned {reply.from_user.mention} indefinitely__", quote=False, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( "Give grace", f"unban.{reply.from_user.id}") ]])) ################################ LOCKED = f"{emoji.LOCKED} Chat has been locked. Send #unlock to unlock." UNLOCKED = f"{emoji.UNLOCKED} Chat has been unlocked." PERMISSIONS = { -1001387666944: ChatPermissions(can_send_messages=True, can_send_media_messages=True) } # Inn PERMISSIONS.update( dict.fromkeys( # Using this to remove redundant code [-1001221450384, -1001355792138], # Lounge and Italian Group 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, ))) @Assistant.on_message(command("lock"))
async def unlock_perm(message: Message): """ unlock chat permissions from tg group """ unlock_type = message.input_str chat_id = message.chat.id if not unlock_type: await message.err(r"I Can't Unlock Nothing! (-‸ლ)") return if unlock_type == "all": try: await message.client.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True)) await message.edit("**🔓 Unlocked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `All Permissions`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5) return if unlock_type in _types: (umsg, umedia, ustickers, uanimations, ugames, uinlinebots, uwebprev, upolls, uinfo, uinvite, upin, uperm) = _get_chat_lock(message, unlock_type, False) else: await message.err(r"Invalid Unlock Type! ¯\_(ツ)_/¯") return try: await message.client.set_chat_permissions( chat_id, ChatPermissions(can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin)) await message.edit(f"**🔓 Unlocked {uperm} for this chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\nCHAT: `{message.chat.title}` (`{chat_id}`)\n" f"PERMISSIONS: `{uperm} Permission`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**ERROR:** `{e_f}`", del_in=5)
async def lock(bot: Assistant, message: Message): """Lock the Chat""" await bot.set_chat_permissions(message.chat.id, ChatPermissions(can_send_messages=False)) await reply_and_delete(message, LOCKED)
async def warn(c: Alita, m: Message): from alita import BOT_ID, BOT_USERNAME if m.reply_to_message: r_id = m.reply_to_message.message_id if len(m.text.split()) >= 2: reason = m.text.split(None, 1)[1] else: reason = None elif not m.reply_to_message: r_id = m.message_id if len(m.text.split()) >= 3: reason = m.text.split(None, 2)[2] else: reason = None else: reason = None if not len(m.command) > 1 and not m.reply_to_message: await m.reply_text( "I can't warn nothing! Tell me user whom I should warn") return user_id, user_first_name, _ = await extract_user(c, m) if user_id == BOT_ID: await m.reply_text("Huh, why would I warn myself?") return if user_id in SUPPORT_STAFF: await m.reply_text(tlang(m, "admin.support_cannot_restrict")) LOGGER.info( f"{m.from_user.id} trying to warn {user_id} (SUPPORT_STAFF) in {m.chat.id}", ) return try: admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]} except KeyError: admins_group = { i[0] for i in (await admin_cache_reload(m, "warn_user")) } if user_id in admins_group: await m.reply_text( "This user is admin in this chat, I can't warn them!") return warn_db = Warns(m.chat.id) warn_settings_db = WarnSettings(m.chat.id) _, num = warn_db.warn_user(user_id, reason) warn_settings = warn_settings_db.get_warnings_settings() if num >= warn_settings["warn_limit"]: if warn_settings["warn_mode"] == "kick": await m.chat.kick_member(user_id, until_date=int(time() + 45)) action = "kicked" elif warn_settings["warn_mode"] == "ban": await m.chat.kick_member(user_id) action = "banned" elif warn_settings["warn_mode"] == "mute": await m.chat.restrict_member(user_id, ChatPermissions()) action = "muted" await m.reply_text( (f"Warnings {num}/{warn_settings['warn_limit']}!" f"\n<b>Reason for last warn</b>:\n{reason}" if reason else "\n" f"{(await mention_html(user_first_name, user_id))} has been <b>{action}!</b>" ), reply_to_message_id=r_id, ) await m.stop_propagation() rules = Rules(m.chat.id).get_rules() if rules: kb = InlineKeyboardButton( "Rules 📋", url=f"https://t.me/{BOT_USERNAME}?start=rules_{m.chat.id}", ) else: kb = InlineKeyboardButton( "Kick ⚠️", callback_data=f"warn.kick.{user_id}", ) if m.text.split()[0] == "/swarn": await m.delete() await m.stop_propagation() if m.text.split()[0] == "/dwarn": if not m.reply_to_message: await m.reply_text( "Reply to a message to delete it and ban the user!") await m.stop_propagation() await m.reply_to_message.delete() txt = f"{(await mention_html(user_first_name, user_id))} has {num}/{warn_settings['warn_limit']} warnings!" txt += f"\n<b>Reason for last warn</b>:\n{reason}" if reason else "" await m.reply_text( txt, reply_markup=InlineKeyboardMarkup([ [ InlineKeyboardButton( "Remove Warn ❌", callback_data=f"warn.remove.{user_id}", ), ] + [kb], ], ), reply_to_message_id=r_id, ) await m.stop_propagation()
async def unlock_perm(message: Message): """ Devredışı grup izinlerini etkinleştirmek için kullan """ unlock_type = message.input_str chat_id = message.chat.id if not unlock_type: await message.edit(text=r"`Hiçbirini Etkinleştiremedim! (-‸ლ)`", del_in=5) return umsg = message.chat.permissions.can_send_messages umedia = message.chat.permissions.can_send_media_messages ustickers = message.chat.permissions.can_send_stickers uanimations = message.chat.permissions.can_send_animations ugames = message.chat.permissions.can_send_games uinlinebots = message.chat.permissions.can_use_inline_bots uwebprev = message.chat.permissions.can_add_web_page_previews upolls = message.chat.permissions.can_send_polls uinfo = message.chat.permissions.can_change_info uinvite = message.chat.permissions.can_invite_users upin = message.chat.permissions.can_pin_messages if unlock_type == "all": try: await message.client.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True)) await message.edit( "**🔓 Bu Sohbetin tüm yetkileri Etkinleştirildi!**", del_in=5) await CHANNEL.log( f"#ETKİNLEŞTİR\n\nGRUP: `{message.chat.title}` (`{chat_id}`)\n" f"YETKİ TÜRÜ: `Tüm Yekiler`") except Exception as e_f: await message.edit( r"`bunu yapma yetkim yok>︿<`\n\n" f"**HATA:** `{e_f}`", del_in=5) return if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type == "inlinebots": uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await message.edit(text=r"`Geçersiz Etkinleşirme Türü! ¯\_(ツ)_/¯`", del_in=5) return try: await message.client.set_chat_permissions( chat_id, ChatPermissions(can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin)) await message.edit(f"**🔓 {uperm} Bu sohbet için Etkinleştirildi!**", del_in=5) await CHANNEL.log( f"#ETKİNLEŞTİR\n\nGRUP: `{message.chat.title}` (`{chat_id}`)\n" f"YETKİ TÜRÜ: `{uperm} Yetkisi`") except Exception as e_f: await message.edit( r"`bunu yapma yetkim yok >︿<`\n\n" f"**HATA:** `{e_f}`", del_in=5)
async def _warn_user(_, msg: Message): global WARN_MODE, WARN_LIMIT # pylint: disable=global-statement replied = msg.reply_to_message if not replied: return chat_id = msg.chat.id user_id = replied.from_user.id mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})" if is_dev(user_id): await msg.reply("`He is My Master, Can't Warn him.`") return if await is_self(user_id): await sed_sticker(msg) return if is_admin(chat_id, user_id): await msg.reply("`User is Admin, Can't Warn him.`") return cmd = len(msg.text) if msg.text and cmd == 5: await msg.reply("`Give a reason to warn him.`") return _, args = msg.text.split(maxsplit=1) args += f"\n -By {msg.from_user.mention}" w_l = WARN_LIMIT w_m = WARN_MODE if not DATA.get(user_id): w_d = { 'limit': 1, 'reason': [args] } DATA[user_id] = w_d # warning data keyboard = InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Remove this Warn", callback_data=f"rm_warn({user_id} {msg.from_user.id})") ] ] ) reply_text = f"#Warned\n{mention} has 1/{w_l} warnings.\n" reply_text += f"**Reason:** {args}" await replied.reply_text(reply_text, reply_markup=keyboard) else: p_l = DATA[user_id]['limit'] # previous limit nw_l = p_l + 1 # new limit if nw_l >= w_l: if w_m == "ban": await bot.kick_chat_member(chat_id, user_id) exec_str = 'BANNED' elif w_m == "kick": await bot.kick_chat_member( chat_id, user_id, time.time() + 60) exec_str = 'KICKED' else: await bot.restrict_chat_member( chat_id, user_id, ChatPermissions()) exec_str = 'MUTED' reason = ('\n'.join(DATA[user_id]['reason']) + '\n' + str(args)) await msg.reply( f"#WARNED_{exec_str}\n" f"**{exec_str} User:** {mention}\n" f"**Warn Counts:** {w_l}/{w_l} Warnings\n" f"**Reason:** {reason}") DATA.pop(user_id) else: DATA[user_id]['limit'] = nw_l DATA[user_id]['reason'].append(args) keyboard = InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Remove this Warn", callback_data=f"rm_warn({user_id} {msg.from_user.id})") ] ] ) r_t = f"#Warned\n{mention} has {nw_l}/{w_l} warnings.\n" r_t += f"**Reason:** {args}" # r_t = reply text await replied.reply_text(r_t, reply_markup=keyboard)
async def lock_perm(message: Message): """ grubunuzdai sohbet yetkilerini Devredışı bırakmanızı sağlar """ lock_type = message.input_str chat_id = message.chat.id if not lock_type: await message.edit(text=r"`Hiçbirşeyi Devredışı bırakamam! (-‸ლ)`", del_in=5) return msg = message.chat.permissions.can_send_messages media = message.chat.permissions.can_send_media_messages stickers = message.chat.permissions.can_send_stickers animations = message.chat.permissions.can_send_animations games = message.chat.permissions.can_send_games inlinebots = message.chat.permissions.can_use_inline_bots webprev = message.chat.permissions.can_add_web_page_previews polls = message.chat.permissions.can_send_polls info = message.chat.permissions.can_change_info invite = message.chat.permissions.can_invite_users pin = message.chat.permissions.can_pin_messages if lock_type == "all": try: await message.client.set_chat_permissions(chat_id, ChatPermissions()) await message.edit( "**🔒 Bu Sohbetten gelen tüm yetkiler Devredışı bırakıldı!**", del_in=5) await CHANNEL.log( f"#DEVREDIŞI\n\n GRUP: `{message.chat.title}` (`{chat_id}`)\n" f"YETKİ TÜRÜ: `Tüm Yetkiler`") except Exception as e_f: await message.edit( r"`i don't have permission to do that >︿<`\n\n" f"**HATA:** `{e_f}`", del_in=5) return if lock_type == "msg": msg = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type == "inlinebots": inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: await message.edit(text=r"`Geçersiz Yetki Türü! ¯\_(ツ)_/¯`", del_in=5) return try: await message.client.set_chat_permissions( chat_id, ChatPermissions(can_send_messages=msg, can_send_media_messages=media, can_send_stickers=stickers, can_send_animations=animations, can_send_games=games, can_use_inline_bots=inlinebots, can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin)) await message.edit(f"**🔒 {perm} Bu sohbet için Devredışı!**", del_in=5) await CHANNEL.log( f"#DEVREDIŞI\n\nGRUP: `{message.chat.title}` (`{chat_id}`)\n" f"YETKİ TÜRÜ: `{perm}`") except Exception as e_f: await message.edit( r"`bunu yapma yetkim yok >︿<`\n\n" f"**HATA:** `{e_f}`", del_in=5)
async def unlock_perm(c: TelePyroBot, m: Message): umsg = "" umedia = "" ustickers = "" uanimations = "" ugames = "" uinlinebots = "" uwebprev = "" upolls = "" uinfo = "" uinvite = "" upin = "" uperm = "" unlock_type = m.text.split(None, 1)[1] chat_id = m.chat.id if not unlock_type: await m.edit_text(text=r"`I Can't Unlock Nothing! (-‸ლ)`") await asyncio.sleep(5) await m.delete() return get_uperm = await c.get_chat(chat_id) umsg = get_uperm.permissions.can_send_messages umedia = get_uperm.permissions.can_send_media_messages ustickers = get_uperm.permissions.can_send_stickers uanimations = get_uperm.permissions.can_send_animations ugames = get_uperm.permissions.can_send_games uinlinebots = get_uperm.permissions.can_use_inline_bots uwebprev = get_uperm.permissions.can_add_web_page_previews upolls = get_uperm.permissions.can_send_polls uinfo = get_uperm.permissions.can_change_info uinvite = get_uperm.permissions.can_invite_users upin = get_uperm.permissions.can_pin_messages if unlock_type == "all": try: await c.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True, ), ) await m.edit_text("**🔓 Unlocked all permission from this Chat!**") await asyncio.sleep(5) await m.delete() await c.send_message( PRIVATE_GROUP_ID, "#UNLOCK\n\nCHAT: `{}` (`{}`)\nPERMISSIONS: `All Permissions`". format(m.chat.title, m.chat.id), ) except Exception as e_f: await m.edit_text( f"`I don't have permission to do that >︿<`\n\n**ERROR:** `{e_f}`" ) await asyncio.sleep(5) await m.delete() return if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type == "inlinebots": uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await m.edit_text("`Invalid Unlock Type! ¯\_(ツ)_/¯`") await asyncio.sleep(5) await m.delete() return try: await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin, ), ) await m.edit_text(f"**🔓 Unlocked {uperm} for this chat!**") await asyncio.sleep(5) await m.delete() await c.send_message( PRIVATE_GROUP_ID, "#UNLOCK\n\nCHAT: `{}` (`{}`)\nPERMISSION: `{} Permission`".format( m.chat.title, m.chat.id, uperm), ) except Exception as e_f: await m.edit_text( f"`I don't have permission to do that >︿<`\n\n**ERROR:** `{e_f}`") return
async def unlock_perm(c: Alita, m: Message): if len(m.text.split()) < 2: await m.reply_text("Please enter a permission to unlock!") return unlock_type = m.text.split(None, 1)[1] chat_id = m.chat.id if not unlock_type: await m.reply_text(tlang(m, "locks.unlocks_perm_sp")) return if unlock_type == "all": try: await c.set_chat_permissions( chat_id, 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, ), ) LOGGER.info( f"{m.from_user.id} unlocked all permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: await m.reply_text(tlang(m, "general.no_perm_admin")) await m.reply_text("🔓 " + (tlang(m, "locks.unlock_all"))) await prevent_approved(m) return get_uperm = m.chat.permissions umsg = get_uperm.can_send_messages umedia = get_uperm.can_send_media_messages uwebprev = get_uperm.can_add_web_page_previews upolls = get_uperm.can_send_polls uinfo = get_uperm.can_change_info uinvite = get_uperm.can_invite_users upin = get_uperm.can_pin_messages ustickers = uanimations = ugames = uinlinebots = None if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type in ("inlinebots", "inline"): uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await m.reply_text(tlang(m, "locks.invalid_lock")) return try: LOGGER.info( f"{m.from_user.id} unlocked selected permissions in {m.chat.id}") await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=umsg, can_send_media_messages=umedia, can_send_other_messages=any( [ustickers, uanimations, ugames, uinlinebots], ), can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin, ), ) except ChatNotModified: pass except ChatAdminRequired: await m.reply_text(tlang(m, "general.no_perm_admin")) await m.reply_text( "🔓 " + (tlang(m, "locks.unlocked_perm").format(uperm=uperm)), ) await prevent_approved(m) return
Reply a message to pin in the Group __Supported pin types__: `alert`, `notify`, `loud` ──「 **Deleted Account** 」── -> `delacc` or `delacc clean` Checks Group for deleted accounts & clean them """ # Mute permissions mute_permission = ChatPermissions( can_send_messages=False, can_send_media_messages=False, can_send_stickers=False, can_send_animations=False, can_send_games=False, can_use_inline_bots=False, can_add_web_page_previews=False, can_send_polls=False, can_change_info=False, can_invite_users=True, can_pin_messages=False, ) # Unmute permissions unmute_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,
async def lock_perm(c: Alita, m: Message): if len(m.text.split()) < 2: await m.reply_text("Please enter a permission to lock!") return lock_type = m.text.split(None, 1)[1] chat_id = m.chat.id if not lock_type: await m.reply_text(tlang(m, "locks.locks_perm_sp")) return get_perm = m.chat.permissions msg = get_perm.can_send_messages media = get_perm.can_send_media_messages webprev = get_perm.can_add_web_page_previews polls = get_perm.can_send_polls info = get_perm.can_change_info invite = get_perm.can_invite_users pin = get_perm.can_pin_messages stickers = animations = games = inlinebots = None if lock_type == "all": try: await c.set_chat_permissions(chat_id, ChatPermissions()) LOGGER.info( f"{m.from_user.id} locked all permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: await m.reply_text(tlang(m, "general.no_perm_admin")) await m.reply_text("🔒 " + (tlang(m, "locks.lock_all"))) await prevent_approved(m) return if lock_type == "msg": msg = False perm = "messages" elif lock_type == "media": media = False perm = "audios, documents, photos, videos, video notes, voice notes" elif lock_type == "stickers": stickers = False perm = "stickers" elif lock_type == "animations": animations = False perm = "animations" elif lock_type == "games": games = False perm = "games" elif lock_type in ("inlinebots", "inline"): inlinebots = False perm = "inline bots" elif lock_type == "webprev": webprev = False perm = "web page previews" elif lock_type == "polls": polls = False perm = "polls" elif lock_type == "info": info = False perm = "info" elif lock_type == "invite": invite = False perm = "invite" elif lock_type == "pin": pin = False perm = "pin" else: await m.reply_text(tlang(m, "locks.invalid_lock")) return try: await c.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=msg, can_send_media_messages=media, can_send_other_messages=any( [stickers, animations, games, inlinebots]), can_add_web_page_previews=webprev, can_send_polls=polls, can_change_info=info, can_invite_users=invite, can_pin_messages=pin, ), ) LOGGER.info( f"{m.from_user.id} locked selected permissions in {m.chat.id}") except ChatNotModified: pass except ChatAdminRequired: await m.reply_text(tlang(m, "general.no_perm_admin")) await m.reply_text( "🔒 " + (tlang(m, "locks.locked_perm").format(perm=perm)), ) await prevent_approved(m) return
async def unlock_permission(client, message): """this module unlocks group permission for admins""" if message.chat.type in ["group", "supergroup"]: cmd = message.command is_admin = await admin_check(message) if not is_admin: await message.delete() return umsg = "" umedia = "" ustickers = "" uanimations = "" ugames = "" uinlinebots = "" uwebprev = "" upolls = "" uinfo = "" uinvite = "" upin = "" uperm = "" # pylint:disable=E0602 unlock_type = " ".join(cmd[1:]) chat_id = message.chat.id if not unlock_type: await message.delete() return get_uperm = await client.get_chat(chat_id) umsg = get_uperm.permissions.can_send_messages umedia = get_uperm.permissions.can_send_media_messages ustickers = get_uperm.permissions.can_send_stickers uanimations = get_uperm.permissions.can_send_animations ugames = get_uperm.permissions.can_send_games uinlinebots = get_uperm.permissions.can_use_inline_bots uwebprev = get_uperm.permissions.can_add_web_page_previews upolls = get_uperm.permissions.can_send_polls uinfo = get_uperm.permissions.can_change_info uinvite = get_uperm.permissions.can_invite_users upin = get_uperm.permissions.can_pin_messages if unlock_type == "all": try: await client.set_chat_permissions( chat_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_send_polls=True, can_change_info=True, can_invite_users=True, can_pin_messages=True, can_add_web_page_previews=True, ), ) await edrep(message, text=tld('unlock_all')) await asyncio.sleep(5) await message.delete() except Exception as e: print(e) await edrep(message, text=tld('denied_permission')) return if unlock_type == "msg": umsg = True uperm = "messages" elif unlock_type == "media": umedia = True uperm = "audios, documents, photos, videos, video notes, voice notes" elif unlock_type == "stickers": ustickers = True uperm = "stickers" elif unlock_type == "animations": uanimations = True uperm = "animations" elif unlock_type == "games": ugames = True uperm = "games" elif unlock_type == "inlinebots": uinlinebots = True uperm = "inline bots" elif unlock_type == "webprev": uwebprev = True uperm = "web page previews" elif unlock_type == "polls": upolls = True uperm = "polls" elif unlock_type == "info": uinfo = True uperm = "info" elif unlock_type == "invite": uinvite = True uperm = "invite" elif unlock_type == "pin": upin = True uperm = "pin" else: await edrep(message, text=tld('unlock_invalid')) await asyncio.sleep(5) await message.delete() return try: await client.set_chat_permissions( chat_id, ChatPermissions( can_send_messages=umsg, can_send_media_messages=umedia, can_send_stickers=ustickers, can_send_animations=uanimations, can_send_games=ugames, can_use_inline_bots=uinlinebots, can_add_web_page_previews=uwebprev, can_send_polls=upolls, can_change_info=uinfo, can_invite_users=uinvite, can_pin_messages=upin, ), ) await edrep(message, text=tld('unlock_chat').format(uperm)) await asyncio.sleep(5) await message.delete() except Exception as e: await edrep(message, text="`Error!`\n" f"**Log:** `{e}`") else: await message.delete()
async def stmute_usr(c: Alita, m: Message): if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Я не могу никого замьютить!") return try: user_id, _, _ = await extract_user(c, m) except Exception: return if not user_id: await m.reply_text("Cannot find user to mute !") return if user_id == Config.BOT_ID: await m.reply_text("Huh, why would I mute myself?") return 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(tlang(m, "admin.support_cannot_restrict")) return try: admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]} except KeyError: admins_group = await admin_cache_reload(m, "mute") if user_id in admins_group: await m.reply_text(tlang(m, "admin.mute.admin_cannot_mute")) return if m.reply_to_message and len(m.text.split()) >= 2: reason = m.text.split(None, 2)[1] elif not m.reply_to_message and len(m.text.split()) >= 3: reason = m.text.split(None, 2)[2] else: await m.reply_text("Read /help !!") return if not reason: await m.reply_text( "You haven't specified a time to mute this user for!") return split_reason = reason.split(None, 1) time_val = split_reason[0].lower() reason = split_reason[1] if len(split_reason) > 1 else "" mutetime = await extract_time(m, time_val) if not mutetime: return try: await m.chat.restrict_member( user_id, 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() except ChatAdminRequired: await m.reply_text(tlang(m, "admin.not_admin")) except RightForbidden: await m.reply_text(tlang(m, "admin.mute.bot_no_right")) except UserNotParticipant: await m.reply_text( "How can I mute a user who is not a part of this chat?") except RPCError as ef: await m.reply_text((tlang(m, "general.some_error")).format( SUPPORT_GROUP=SUPPORT_GROUP, ef=ef, ), ) LOGGER.error(ef) return