def del_lockables(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[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( "Bir bot görüyorum ve onları durdurma talimatı aldım " "Gel gör ki yönetici değilim, nasıl olacak!") return chat.kick_member(new_mem.id) message.reply_text( "Bu sohbete yalnızca yöneticiler bot ekleyebilir! Üzgünüm kardeş." ) 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(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[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( tld( chat.id, "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( tld( chat.id, "Only admins are allowed to add bots to this chat! Get outta here." )) 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(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[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! Get outta here." ) else: message.delete() break
def remove_bot(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] if sql.is_locked(chat.id, "bots") and is_bot_admin(chat, bot.id): new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: chat.kick_member(new_mem.id) update.effective_message.reply_text("Only admins are allowed to add bots to this chat! Get outta here.")
def del_lockables(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] _can_delete = can_delete(chat, bot.id) for lockable, filter in LOCK_TYPES.items(): if filter(message) and sql.is_locked(chat.id, lockable) and _can_delete: 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!" ) else: # allow whitelisted URLs if lockable == 'url': entities = set(url for url in message.parse_entities( MessageEntity.URL).values()) # MessageEntity.TEXT_LINK could be added in the filter above, but would return the text, not the # url, so add all entities that have a 'url' field instead entities = entities | set(entity.url for entity in message.entities if entity.url) # if all URLs are any of the whitelisted ones, accept the message if all( any( regexp.search(text) for regexp in sql.get_whitelist(chat.id).values()) for text in entities): continue else: # forward me the message for review so I can add the sender to a scammer repository message.forward(Config.OWNER_ID, disable_notification=True) 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: Update, context: CallbackContext): bot = context.bot chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user if int(user.id) in ( 777000, 1087968824, ): # 777000 is the telegram notification service bot ID. return # Group channel notifications are sent via this bot. This adds exception to this userid for lockable, filter in LOCK_TYPES.items(): if (filter(update) 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! Get outta here." ) 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_gif(bot, update): chat = update.effective_chat if sql.is_locked(chat.id, "gif") and can_delete(chat, bot.id): update.effective_message.delete()
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, "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 del_url(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] if sql.is_locked(chat.id, "url") and can_delete(chat, bot.id): update.effective_message.delete()
def del_lockables(update: Update): 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") 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 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): 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! Get outta here." ) else: chat_id = chat.id whitelist = get_whitelisted_urls(chat_id) for i in whitelist: if i.__eq__(message.text): return try: message.delete() lock_message = context.bot.send_message( chat.id, "Message deleted because it contained a locked item: {}." .format(lockable)) time.sleep(2) lock_message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables bots") break