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: try: if can_delete(chat, bot.id): send_lock_msg(bot, update) 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] 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") 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: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
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: if can_delete(chat, bot.id): msg.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in restrictions") break
def lock(bot: Bot, update: Update, args: List[str]) -> str: 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): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text("Bloccati i messaggi che contengono {} per tutti i non admin!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nBloccato <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: 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) message.reply_text("Bloccati i {} per tutti i non admin!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nBloccato <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("Cosa stai cercando ti bloccare...? Usa /locktypes per la lista degli elementi bloccabili.") else: message.reply_text("Non sono un amministratore oppure non ho i permessi di cancellazione.") 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 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("Mən bir bot gördüm, və mənə buyurdular ki, qoşulmağı dayandırım... " "amma mən admin deyiləm!") return chat.kick_member(new_mem.id) message.reply_text("Sadəcə adminlər qrupa bot əlavə edə bilər! Yəni rədd ol!") 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( "Ben bir bot görmek ve onları katılmadan durdurmak için söylendi ... " "ama ben yönetici değilim.!") return chat.kick_member(new_mem.id) message.reply_text( "Sadece yöneticiler bu sohbet e botlar eklemek için izin verilir! Buradan çık.." ) 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( "أرى بوت، وقيل لي أن أوقفهم عن الانضمام ... " "لكنني لست المسؤول!") return chat.kick_member(new_mem.id) message.reply_text( "يسمح للمحادثات فقط بإضافة روبوتات إلى هذه الدردشة! الحصول على outta هنا" ) 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( "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_message(bot: Bot, update: Update) -> str: if update.effective_message.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] admin = chat.get_member(int(user.id)) if (admin.status != 'creator') and (not admin.can_delete_messages) and (not int( user.id) in SUDO_USERS): update.effective_message.reply_text( "You don't have sufficient permissions to delete messages!") return "" 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: update.effective_message.reply_text("Whadya want to delete?") 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 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("Vedo un bot, mi è stato detto di non permettergli di unirsi... " "ma non sono un admin!") return chat.kick_member(new_mem.id) message.reply_text("Solo gli admin sono autorizzati ad aggiungere bot a questo gruppo! Fuori di qui.") 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( "मुझे एक बॉट दिखाई देता है, और मुझे उनसे जुड़ने से रोकने के लिए कहा गया है ... लेकिन मैं एडमिन नहीं हूँ!" ) return chat.kick_member(new_mem.id) message.reply_text( "इस चैट में केवल एडमिन को बॉट्स जोड़ने की अनुमति है।" ) else: try: message.delete() except BadRequest as excp: if excp.message == "हटाने के लिए मैसेज नहीं मिला": pass else: LOGGER.exception("ERROR in lockables") break
def delete_join(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] join = update.effective_message.new_chat_members if can_delete(chat, bot.id): del_join = sql.get_del_pref(chat.id) if del_join: update.message.delete()
def rest_previews(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if sql.is_restr_locked(chat.id, "previews") \ and can_delete(chat, bot.id) \ and not is_user_admin(chat, msg.from_user.id): pass
def del_lockables(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user if int(user.id) == 777000 or int(user.id) == 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(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: 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("Widzę bota i powiedzieli mi żebym zapobiegał ich dołączeniu... " "ale nie jestem administratorem!") return chat.kick_member(new_mem.id) message.reply_text("Tylko administracja jest uprawniona do dodawania botów do tego czatu! Wypad stąd.") else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("BŁĄD w blokadach") break
def purge(bot: Bot, update: Update, args: List[str]) -> str: 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 delete_to = msg.message_id - 1 if args and args[0].isdigit(): new_del = message_id + int(args[0]) # No point deleting messages which haven't been written yet. if new_del < delete_to: delete_to = new_del 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": bot.send_message( chat.id, "Non posso cancellare tutti i messaggi. I messaggi potrebbero essere troppo vecchi, oppure " "non sono amministratore, o questo non è un supergruppo.", ) elif err.message != "Message to delete not found": LOGGER.exception( "Errore durante l'eliminazione dei messaggi.") try: msg.delete() except BadRequest as err: if err.message == "Message can't be deleted": bot.send_message( chat.id, "Non posso cancellare tutti i messaggi. I messaggi potrebbero essere troppo vecchi, potrei " "non essere amministratore, o questo potrebbe non essere un supergruppo.", ) elif err.message != "Message to delete not found": LOGGER.exception( "Errore durante l'eliminazione dei messaggi.") bot.send_message(chat.id, "Purge completo.") 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: msg.reply_text( "Rispondi a un messaggio per selezionare da dove iniziare l'eliminazione dei messaggi." ) 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 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("da chekka ivide njan und.😡 ene pole oru kidilan bot vere undo..? 😌. nee konduvanna ee botinem kondu vanna vazhiye pokkonam. 😠 allenkil nine cherth ividunnu chavitty porathakkum kettodaa pattii.. 🤬 ") 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 toggle_ilikes(bot: Bot, update: Update, args: List[str]): delete_expired(bot, update) chat = update.effective_chat chat_id = chat.id msg = update.effective_message retval = sql.toggle_ilikes(chat_id) if (retval == True): msgtext = "Automatische iLikes wurden für Standorte aktiviert" else: msgtext = "Automatische iLikes wurden für Standorte wieder de-aktiviert" try: if can_delete(chat, bot.id): msg.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in toggle ilikes") # send_reply(update, msgtext, []) send(bot, update, msgtext, [])
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 == "ربات": 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("اگه کسی رباتی بیاره من اجازه ادد کردن بهش نمیدم ولی " "هنوز ادمین نیستم!") return chat.kick_member(new_mem.id) 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 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( "Saya melihat bot, dan saya telah diberitahu untuk menghentikan mereka bergabung... " "tapi saya bukan admin!" ) return chat.kick_member(new_mem.id) message.reply_text( "Hanya admin yang diizinkan untuk menambahkan bot ke obrolan ini! Berperilaku atau aku akan memukulmu." ) else: try: message.delete() except BadRequest as excp: if excp.message == "Pesan untuk dihapus tidak ditemukan": pass else: LOGGER.exception("ERROR in lockables") break
def purge(bot: Bot, update: Update, args: List[str]) -> str: msg = update.effective_message user = update.effective_user chat = update.effective_chat if can_delete(chat, bot.id): if msg.reply_to_message: message_id = msg.reply_to_message.message_id start_message_id = message_id - 1 delete_to = msg.message_id - 1 if args and args[0].isdigit(): new_del = message_id + int(args[0]) # No point deleting messages which haven't been written yet. if new_del < delete_to: delete_to = new_del else: if args and args[0].isdigit(): messages_to_delete = int(args[0]) if messages_to_delete < 1: msg.reply_text("Can't purge less than 1 message.") return "" delete_to = msg.message_id - 1 start_message_id = delete_to - messages_to_delete for m_id in range(delete_to, start_message_id, -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": bot.send_message(chat.id, "Cannot delete all messages. The messages may be too old, I might " "not have delete rights, or this might not be a supergroup.") 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": bot.send_message(chat.id, "Cannot delete all messages. The messages may be too old, I might " "not have delete rights, or this might not be a supergroup.") elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") bot.send_message(chat.id, f"Purge <code>{delete_to - start_message_id}</code> messages.", parse_mode=ParseMode.HTML) return (f"<b>{html.escape(chat.title)}:</b>\n" f"#PURGE\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Purged <code>{delete_to - start_message_id}</code> messages.") 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 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ürəm adminlərə onu dayandırmalı olduğumu deməliyəm " "amma admin deyiləm!") return chat.kick_member(new_mem.id) message.reply_text( "Bu qrupa bot atmaq olmaz... Çıx get burdan!!!") else: try: message.delete() except BadRequest as excp: if excp.message == "Silinəcək mesaj tapılmadı": pass else: LOGGER.exception("ERROR in lockables") break
def del_lockables(update: Update, context: CallbackContext): 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, 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( "다른 봇이 들어오려고 하네요... 들어오지 말라고 하고 싶지만... " "전 관리자가 아니에요!") return chat.kick_member(new_mem.id) message.reply_text("관리자만 이 채팅에서 봇을 추가할 수 있어요. 나가세요!") else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("잠금 모듈의 오류") break
def antiarabic(update: Update, context: CallbackContext): bot = context.bot chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): msg = update.effective_message # type: Optional[Message] to_match = extract_text(msg) user = update.effective_user # type: Optional[User] if not sql.chat_antiarabic(chat.id): return "" if not user.id or int(user.id) == 777000 or int(user.id) == 1087968824: return "" if not to_match: return if chat.type != chat.PRIVATE: for c in to_match: if ('\u0600' <= c <= '\u06FF' or '\u0750' <= c <= '\u077F' or '\u08A0' <= c <= '\u08FF' or '\uFB50' <= c <= '\uFDFF' or '\uFE70' <= c <= '\uFEFF' or '\U00010E60' <= c <= '\U00010E7F' or '\U0001EE00' <= c <= '\U0001EEFF'): update.effective_message.delete() 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 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("මට බොට් එකක් පෙනේ, ඔවුන් මට සම්බන්ධ වීම නවත්වන ලෙස මට පවසා ඇත ... " "නමුත් මම පරිපාලක නොවේ!") return chat.kick_member(new_mem.id) message.reply_text("මෙම කතාබහට බොට්ස් එක් කිරීමට පරිපාලකයින්ට පමණක් අවසර ඇත! මෙතනින් යන්න.") else: try: message.delete() except BadRequest as excp: if excp.message == "මැකීමට පණිවිඩය හමු නොවීය": pass else: LOGGER.exception("අගුළු දැමීමේ දෝෂයකි") break
def purge(bot: Bot, update: Update, args: List[str]) -> str: 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 delete_to = msg.message_id - 1 if args and args[0].isdigit(): new_del = message_id + int(args[0]) # No point deleting messages which haven't been written yet. if new_del < delete_to: delete_to = new_del 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": bot.send_message( chat.id, "Cannot delete all messages. The messages may be too old, I might " "not have delete rights, or this might not be a supergroup.", ) 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": bot.send_message( chat.id, "Cannot delete all messages. The messages may be too old, I might " "not have delete rights, or this might not be a supergroup.", ) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") bot.send_message(chat.id, "Purge complete.") 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: msg.reply_text("Reply to a message to select where to start purging from.") return ""
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): msg.delete() break
def purge(bot: Bot, update: Update, args: List[str]) -> str: 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 delete_to = msg.message_id - 1 if args and args[0].isdigit(): new_del = message_id + int(args[0]) # No point deleting messages which haven't been written yet. if new_del < delete_to: delete_to = new_del 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": bot.send_message( chat.id, "Tüm mesajları silemezsiniz. Mesajlar çok eski olabilir, " "silme hakkım olmayabilir veya bu bir üst grup olmayabilir." ) 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": bot.send_message( chat.id, "Tüm mesajları silemezsiniz. Mesajlar çok eski olabilir, " "silme hakkım olmayabilir veya bu bir üst grup olmayabilir." ) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") bot.send_message(chat.id, "Temizleme tamamlandı.") return "<b>{}:</b>" \ "\n#PURGE" \ "\n<b>Yönetici:</b> {}" \ "\nmesajları temizledi <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), delete_to - message_id) else: msg.reply_text( "Temizlemeye nereden başlayacağınızı seçmek için bir mesajı yanıtlayın." ) return ""
def rest_msg(bot, update): msg = update.effective_message chat = update.effective_chat if sql.is_restr_locked(chat.id, "messages") \ and can_delete(chat, bot.id) \ and not is_user_admin(chat, msg.from_user.id): msg.delete() bot.restrict_chat_member(chat.id, msg.from_user.id, can_send_messages=False)
def lock(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat user = update.effective_user message = update.effective_message if can_delete(chat, bot.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text( "Pesan {} terkunci untuk semua non-admin!".format(args[0]) ) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#LOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Terkunci <code>{args[0]}</code>." ) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=True) """ if args[0] == "messages": chat.set_permissions(can_send_messages=False) elif args[0] == "media": chat.set_permissions(can_send_media_messages=False) elif args[0] == "other": chat.set_permissions(can_send_other_messages=False) elif args[0] == "previews": chat.set_permissions(can_add_web_page_previews=False) elif args[0] == "all": chat.set_permissions(can_send_messages=False) """ message.reply_text("Locked {} for all non-admins!".format(args[0])) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#LOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Locked <code>{args[0]}</code>." ) else: message.reply_text( "Apa yang kamu coba kunci ...? Coba /locktypes untuk daftar yang dapat dikunci" ) else: message.reply_text("Saya bukan administrator, atau tidak punya hak hapus.") return ""