def rest_handler(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] for restriction, filter in RESTRICTION_TYPES.items(): if filter(msg) and sql.is_restr_locked( chat.id, restriction) and can_delete(chat, bot.id): try: msg.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in restrictions") break
def del_message(bot: Bot, update: Update) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return if update.effective_message.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): update.effective_message.reply_to_message.delete() update.effective_message.delete() return "<b>{}:</b>" \ "\n#DEL" \ "\n<b>Admin:</b> {}" \ "\nMessage deleted.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: send_message(update.effective_message, tl(update.effective_message, "Apa yang ingin di hapus?")) return ""
def purge(bot: Bot, update: Update, args: List[str]) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return msg = update.effective_message # type: Optional[Message] if msg.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): message_id = msg.reply_to_message.message_id if args and args[0].isdigit(): delete_to = message_id + int(args[0]) else: delete_to = msg.message_id - 1 for m_id in range(delete_to, message_id - 1, -1): # Reverse iteration over message ids try: bot.deleteMessage(chat.id, m_id) except BadRequest as err: if err.message == "Message can't be deleted": send_message( update.effective_message, tl( update.effective_message, "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin " "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup." )) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") try: msg.delete() except BadRequest as err: if err.message == "Message can't be deleted": send_message( update.effective_message, tl( update.effective_message, "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin " "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup." )) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") send_message(update.effective_message, tl(update.effective_message, "Pembersihan selesai.")) return "<b>{}:</b>" \ "\n#PURGE" \ "\n<b>Admin:</b> {}" \ "\nPurged <code>{}</code> messages.".format(html.escape(chat.title), mention_html(user.id, user.first_name), delete_to - message_id) else: send_message( update.effective_message, tl(update.effective_message, "Balas pesan untuk memilih tempat mulai membersihkan.")) return ""
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 lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete(chat, 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") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim 'Teks RTL' yang sedang di kunci saat ini" ), message, update.effective_user, conn=False) 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") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim 'Teks RTL' yang sedang di kunci saat ini" ), message, update.effective_user, conn=False) break 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): send_message( update.effective_message, tl( update.effective_message, "Saya melihat bot, dan saya diberitahu untuk menghentikan mereka bergabung... " "tapi saya bukan admin!")) return chat.kick_member(new_mem.id) send_message( update.effective_message, tl( update.effective_message, "Hanya admin yang diizinkan menambahkan bot ke obrolan ini! Keluar dari sini!" )) getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Memasukan 'Bot' yang sedang di kunci saat ini" ), message, update.effective_user, conn=False) else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn(update.effective_user, chat, tl(update.effective_message, "Mengirim '{}' yang sedang di kunci saat ini"). format(lockable), message, update.effective_user, conn=False) break
def lock(bot: Bot, update: Update, args: List[str]) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] if can_delete(chat, bot.id) or update.effective_message.chat.type == "private": if len(args) >= 1: if args[0] in LOCK_TYPES: # Connection check conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Terkunci *{}* pesan untuk semua non-admin pada *{}*!" ).format(args[0], chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl( update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM" )) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl( update.effective_message, "Terkunci *{}* pesan untuk semua non-admin!").format( args[0]) sql.update_lock(chat.id, args[0], locked=True) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: # Connection check conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Terkunci *{}* pesan untuk semua non-admin pada *{}*!" ).format(args[0], chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl( update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM" )) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl( update.effective_message, "Terkunci *{}* pesan untuk semua non-admin!").format( args[0]) sql.update_restriction(chat.id, args[0], locked=True) if args[0] == "previews": members = users_sql.get_chat_members(str(chat.id)) restr_members(bot, chat.id, members, messages=True, media=True, other=True) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: send_message( update.effective_message, tl( update.effective_message, "Apa yang Anda coba untuk kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci" )) else: send_message( update.effective_message, tl(update.effective_message, "Apa yang Anda ingin kunci...?")) else: send_message( update.effective_message, tl(update.effective_message, "Saya bukan admin, atau tidak punya hak menghapus.")) return ""