def del_lockables(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message for lockable, filter in LOCK_TYPES.items(): if filter(message) and sql.is_locked(chat.id, lockable) and can_delete( chat, bot.id): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, bot.id): message.reply_text( "I see a bot, and I've been told to stop them joining... " "but I'm not admin!") return chat.kick_member(new_mem.id) message.reply_text( "Only admins are allowed to add bots to this chat! Behave or I'll punch you." ) else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
def del_lockables(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) target_user = mention_html(user.id, user.first_name) if target_user in approve_list: return for lockable, filter in LOCK_TYPES.items(): if lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.caption: check = ad.detect_alphabet(u"{}".format(message.caption)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break if message.text: check = ad.detect_alphabet(u"{}".format(message.text)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "button": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.reply_markup and message.reply_markup.inline_keyboard: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "inline": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message and message.via_bot: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if (filter(update) and sql.is_locked(chat.id, lockable) and can_delete(chat, context.bot.id)): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, context.bot.id): send_message( update.effective_message, "I see a bot and I've been told to stop them from joining..." "but I'm not admin!", ) return chat.kick_member(new_mem.id) send_message( update.effective_message, "Only admins are allowed to add bots in this chat! Get outta here.", ) break else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
def runmute(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "I can't unrestrict people there! Make sure I'm admin and can unban users." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user there") return else: raise if is_user_in_chat(chat, user_id): if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text( "This user already has the right to speak in that chat.") return if user_id == bot.id: message.reply_text("I'm not gonna UNMUTE myself, I'm an admin there!") return try: bot.restrict_chat_member(chat.id, int(user_id), permissions=ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True)) message.reply_text("Yep, this user can talk in that chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Unmuted!', quote=False) elif excp.message in RUNMUTE_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't unmute that user.")
def rban(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "I can't restrict people there! Make sure I'm admin and can ban users." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text("I really wish I could ban admins...") return if user_id == bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy?") return try: chat.kick_member(user_id) message.reply_text("Banned from chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Banned!', quote=False) elif excp.message in RBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't ban that user.")
def runban(bot: Bot, update: Update, args: List[str]): message = update.effective_message if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "I can't unrestrict people there! Make sure I'm admin and can unban users." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user there") return else: raise if is_user_in_chat(chat, user_id): message.reply_text( "Why are you trying to remotely unban someone that's already in that chat?" ) return if user_id == bot.id: message.reply_text("I'm not gonna UNBAN myself, I'm an admin there!") return try: chat.unban_member(user_id) message.reply_text("Yep, this user can join that chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Unbanned!', quote=False) elif excp.message in RUNBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unbanning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't unban that user.")
def del_lockables(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] for lockable, filter in LOCK_TYPES.items(): if lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.caption: check = ad.detect_alphabet(u"{}".format(message.caption)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break if message.text: check = ad.detect_alphabet(u"{}".format(message.text)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "button": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.reply_markup and message.reply_markup.inline_keyboard: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "inline": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message and message.via_bot: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if (filter(update) and sql.is_locked(chat.id, lockable) and can_delete(chat, context.bot.id)): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, context.bot.id): send_message( update.effective_message, "Qrupa bot gəldiyini gördüm amma admin olmadığıma görə onu qrupdan ata bilmədim!", ) return chat.kick_member(new_mem.id) send_message( update.effective_message, "Yalnız adminlər bu qrupa bot əlavə edə bilər! Rədd ol.", ) break else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
def rban(bot: Bot, update: Update, args: List[str]): message = update.effective_message if not args: message.reply_text("Bir sohbete / kullanıcıya atıfta bulunmuyorsunuz.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "Bir kullanıcıya atıfta bulunmuyorsunuz veya belirtilen kimlik yanlış.." ) return elif not chat_id: message.reply_text("Bir sohbete atıfta bulunmuyorsunuz.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "sohbet bulunamadı": message.reply_text( "Sohbet bulunamadı! Geçerli bir sohbet kimliği girdiğinizden ve bu sohbetin bir parçası olduğumdan emin olun." ) return else: raise if chat.type == 'private': message.reply_text("Üzgünüm, ama bu özel bir sohbet!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "Oradaki insanları kısıtlayamıyorum! Yönetici olduğumdan ve kullanıcıları yasaklayabildiğimden emin olun." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Kullanıcı Bulunamadı": message.reply_text("Bu kullanıcıyı bulamıyorum") return else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text("Keşke yöneticileri yasaklayabilseydim...") return if user_id == bot.id: message.reply_text("Kendimi BAN yapmayacağım, deli misin?") return try: chat.kick_member(user_id) message.reply_text("Sohbet yasaklandı!") except BadRequest as excp: if excp.message == "Yanıt mesajı bulunamadı": # Do not reply message.reply_text('Banlandı!', quote=False) elif excp.message in RBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR yasaklayan kullanıcı %s sohbette %s (%s) Nedeniyle %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Kahretsin, bu kullanıcıyı yasaklayamam.")
def runmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message if not args: message.reply_text("Bir sohbete / kullanıcıya atıfta bulunmuyorsunuz.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "Bir kullanıcıya atıfta bulunmuyorsunuz veya belirtilen kimlik yanlış.." ) return elif not chat_id: message.reply_text("Bir sohbete atıfta bulunmuyorsunuz.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Sohbet Bulunamadı": message.reply_text( "Sohbet bulunamadı! Geçerli bir sohbet kimliği girdiğinizden ve bu sohbetin bir parçası olduğumdan emin olun." ) return else: raise if chat.type == 'private': message.reply_text("Üzgünüm, ama bu özel bir sohbet!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "Oradaki insanları sınırlayamam! Yönetici olduğumdan ve kullanıcıların yasağını kaldırabildiğimden emin olun." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Kullanıcı Bulunamadı": message.reply_text("Bu kullanıcıyı orada bulamıyorum") return else: raise if is_user_in_chat(chat, user_id): if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text( "Bu kullanıcının zaten o sohbette konuşma hakkı var.") return if user_id == bot.id: message.reply_text("Kendimi açmayacağım, orada bir yöneticiyim!") return try: bot.restrict_chat_member(chat.id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) message.reply_text("Evet, bu kullanıcı bu sohbette konuşabilir!") except BadRequest as excp: if excp.message == "Yanıt mesajı bulunamadı": # Do not reply message.reply_text('Unmuted!', quote=False) elif excp.message in RUNMUTE_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "HATA açma susturulmuş kullanıcı %s sohbette %s (%s) nedeniyle %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Kahretsin, bu kullanıcının sesini açamıyorum.")
def runban(bot: Bot, update: Update, args: List[str]): message = update.effective_message if not args: message.reply_text("Bir sohbete / kullanıcıya atıfta bulunmuyorsunuz.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "Bir kullanıcıya atıfta bulunmuyorsunuz veya belirtilen kimlik yanlış.." ) return elif not chat_id: message.reply_text("Bir sohbete atıfta bulunmuyorsunuz.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Sohbet Bulunamıyor": message.reply_text( "Sohbet bulunamadı! Geçerli bir sohbet kimliği girdiğinizden ve bu sohbetin bir parçası olduğumdan emin olun." ) return else: raise if chat.type == 'private': message.reply_text("Üzgünüm, ama bu özel bir sohbet!") return if not is_bot_admin(chat, bot.id) or not chat.get_member( bot.id).can_restrict_members: message.reply_text( "Oradaki insanları sınırlayamam! Yönetici olduğumdan ve kullanıcıların yasağını kaldırabildiğimden emin olun." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Kullanıcı Bulunamadı": message.reply_text("Bu kullanıcıyı orada bulamıyorum") return else: raise if is_user_in_chat(chat, user_id): message.reply_text( "Neden o sohbette olan birinin uzaktan yasağını kaldırmaya çalışıyorsunuz?" ) return if user_id == bot.id: message.reply_text( "Kendimi UNBAN yapmayacağım, orada bir yöneticiyim!") return try: chat.unban_member(user_id) message.reply_text("Evet, bu kullanıcı sohbete katılabilir!") except BadRequest as excp: if excp.message == "Yanıt mesajı bulunamadı": # Do not reply message.reply_text('Ban Kalktı!', quote=False) elif excp.message in RUNBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR yasağı kaldırılmış kullanıcı %s sohbette %s (%s) nedeniyle %s", user_id, chat.title, chat.id, excp.message) message.reply_text( "Kahretsin, bu kullanıcının yasağını kaldıramıyorum.")