def remove_warn_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return to_remove = extracted[0] chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: msg.reply_text("ഗ്രൂപ്പിൽ ഇപ്പോൾ warning filters ഒന്നും ഇല്ല!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("ശരി, അതിന് ഇനി warn ചെയ്യില്ല!") raise DispatcherHandlerStop msg.reply_text( "That's not a current warning filter - run /warnlist for all active warning filters." )
def remove_warn_filter(bot: Bot, update: Update): chat = update.effective_chat msg = update.effective_message args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return to_remove = extracted[0] chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: msg.reply_text(tld(chat.id, 'warns_filters_list_empty')) return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text(tld(chat.id, 'warns_filters_remove_success')) raise DispatcherHandlerStop msg.reply_text(tld(chat.id, 'warns_filter_doesnt_exist'))
def list_warn_filters(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat = dispatcher.bot.getChat(conn) chat_name = dispatcher.bot.getChat(conn).title 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_name = update.effective_message.chat.title all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: if conn: text = tl( update.effective_message, "Tidak ada filter peringatan aktif di *{}*!").format(chat_name) else: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di sini!") send_message(update.effective_message, text, parse_mode="markdown") return filter_list = tl(update.effective_message, "CURRENT_WARNING_FILTER_STRING") if conn: filter_list = filter_list.replace( tl(update.effective_message, 'obrolan ini'), tl(update.effective_message, 'obrolan *{}*').format(chat_name)) for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message(update.effective_message, filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == tl(update.effective_message, "CURRENT_WARNING_FILTER_STRING"): send_message(update.effective_message, filter_list, parse_mode=ParseMode.HTML)
def reply_filter(bot: Bot, update: Update) -> str: chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] chat_warn_filters = sql.get_chat_warn_triggers(chat.id) to_match = extract_text(message) if not to_match: return "" for keyword in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user # type: Optional[User] warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def list_warn_filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text( "ഗ്രൂപ്പിൽ ഇപ്പോൾ warning filters ഒന്നും ഇല്ല!") return filter_list = CURRENT_WARNING_FILTER_STRING for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == CURRENT_WARNING_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def reply_filter(bot: Bot, update: Update) -> str: chat = update.effective_chat message = update.effective_message user = update.effective_user if not user: #Ignore channel return "" if user.id == 777000: return "" chat_warn_filters = sql.get_chat_warn_triggers(chat.id) to_match = extract_text(message) if not to_match: return "" for keyword in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def list_warn_filters(bot: Bot, update: Update): chat = update.effective_chat all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text( tld(chat.id, 'warns_filters_list_empty')) return filter_list = tld(chat.id, 'warns_filters_list') for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == tld(chat.id, 'warns_filters_list'): update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def remove_warn_filter(update, context): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_name = dispatcher.bot.getChat(conn).title 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_name = update.effective_message.chat.title args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: if conn: text = tl( update.effective_message, "Tidak ada filter peringatan aktif di *{}*!").format(chat_name) else: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di sini!") send_message(update.effective_message, text) return nowarn = 0 inwarn = 0 success = "" fail = "" teks = args[1].split(" ") for x in range(len(teks)): to_remove = teks[x] if to_remove not in chat_filters: fail += "`{}` ".format(to_remove) nowarn += 1 for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) success += "`{}` ".format(to_remove) inwarn += 1 if nowarn == 0: if conn: text = tl( update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {} pada *{}*." ).format(success, chat_name) else: text = tl( update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}." ).format(success) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop elif inwarn == 0: if conn: text = tl( update.effective_message, "Gagal menghapus filter warn untuk {} pada *{}*.").format( fail, chat_name) else: text = tl(update.effective_message, "Gagal menghapus filter warn untuk {}.").format(fail) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop else: if conn: text = tl( update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}.\nPada *{}*" ).format(success, fail, chat_name) else: text = tl( update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}." ).format(success, fail) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop """ if not chat_filters: send_message(update.effective_message, "Tidak ada filter peringatan aktif di sini!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) send_message(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.".format(to_remove)) raise DispatcherHandlerStop """ if conn: text = tl( update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif pada *{}*." ) else: text = tl( update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif." ) send_message(update.effective_message, text, parse_mode="markdown")