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_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) msg = update.effective_message if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])" try: match = re.search(pattern, to_match, flags=re.IGNORECASE) except Exception: sql.rm_from_blacklist(chat.id, trigger) msg.reply_text( f'Removed {trigger} from blacklist because of broken regex') return if match: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
def reply_filter(update: Update, context: CallbackContext) -> str: chat: Optional[Chat] = update.effective_chat message: Optional[Message] = update.effective_message user: Optional[User] = update.effective_user if not user: # Ignore channel return if user.id == 777000: return if is_approved(chat.id, user.id): 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: Optional[User] = update.effective_user warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(context.bot, user, chat, warn_filter.reply, message) return ""
def del_blacklist(update: Update, context: CallbackContext): bot = context.bot chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) user = update.effective_user # type: Optional[User] if not user.id or int(user.id) == 777000 or int(user.id) == 1087968824: return "" if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger).replace( "\*", "(.*)").replace("\\(.*)", "*") + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) if not to_match: return user = update.effective_user if is_approved(chat.id, user.id): return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
def save_replied(bot: Bot, update: Update): chat_id = update.effective_chat.id text = update.effective_message.text args = text.split(None, 3) # use python's maxsplit to separate Cmd, note_name, and data if len(args) == 3 and args[1] == "from": notename = args[2] elif len(args) >= 2: notename = args[1] else: update.effective_message.reply_text("You need to give me a notename to save this message!") return msg = update.effective_message.reply_to_message # type: Optional[Message] if msg.from_user.is_bot: text = extract_text(msg) if text: sql.add_note_to_db(chat_id, notename, markdown_parser(text), is_reply=False) update.effective_message.reply_text("Seems like you're trying to save a message from a bot. Unfortunately, " "bots can't forward bot messages, so I can't save the exact message. " "\nI'll save all the text I can, but if you want more, you'll have to " "forward the message yourself, and then save it.") else: update.effective_message.reply_text("Bots are kinda handicapped by telegram, making it hard for bots to " "interract with other bots, so I can't save this message " "like I usually would - do you mind forwarding it and " "then saving that new message? Thanks!") return if MESSAGE_DUMP: msg = bot.forward_message(chat_id=MESSAGE_DUMP, from_chat_id=chat_id, message_id=msg.message_id) sql.add_note_to_db(chat_id, notename, msg.message_id, is_reply=True) update.effective_message.reply_text("Yas! Added replied message {}".format(notename))
def reply_filter(update: Update, context: CallbackContext): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "URL 프로토콜이 지원되지 않아요.": message.reply_text( "지원되지 않는 URL 프로토콜을 사용하시는 것 같네요. tg:// " "와 같은 일부 프로토콜은 텔레그램에서 버튼을 지원하지 않아요. 다시 " "시도해보시거나, @MarieSupport 에 도움을 요청하세요.") elif excp.message == "Reply message not found": context.bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text( "이 노트는 형식이 달라서 보낼 수 없어요. 이유를 알 수 없으면 " "@MarieSupport 에 물어보세요!") LOGGER.warning("Message %s could not be parsed", str(filt.reply)) LOGGER.exception( "Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text( "You seem to be trying to use an unsupported url protocol. Telegram " "doesn't support buttons for some protocols, such as tg://. Please try " "again, or ask in @MarieSupport for help.") elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text( "This note could not be sent, as it is incorrectly formatted. Ask in " "@MarieSupport if you can't figure out why!") LOGGER.warning("Message %s could not be parsed", str(filt.reply)) LOGGER.exception( "Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text( "Desteklenmeyen bir url protokolü kullanmaya çalışıyorsunuz. Telegram " "bazı protokoller için sağlanmış özel karakterleri desteklemiyor, örneğin:// gibi. " "Lütfen tekrar deneyin.") elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text( "Bu not yanlış biçimlendirildiği için gönderilemedi. " "İşleminizi kontrol edin!") LOGGER.warning("Message %s could not be parsed", str(filt.reply)) LOGGER.exception( "Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(update, context) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] 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 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 reply_filter(bot, update): chat = update.effective_chat message = update.effective_message chat_filters = sql.get_chat_filters(chat.id) to_match = extract_text(message) if not to_match: return for filt in chat_filters: pattern = r"( |^|[^\w])" + re.escape(filt.keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = [[InlineKeyboardButton(btn.name, url=btn.url)] for btn in buttons] keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text( "You seem to be trying to use an unsupported url protocol. Telegram " "doesn't support buttons for some protocols, such as tg://. Please try " "again, or ask @{} for help.".format( OWNER_USERNAME)) elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text( "This note is not formatted correctly. Could not send. Contact @{}" " if you can't figure out why!".format( OWNER_USERNAME)) raise Exception("Could not parse message.\n{}".format( filt.reply)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) threshold = 7 for trigger in chat_filters: if (trigger == "only_roman"): count = 0 if not only_roman_chars(to_match): for i in to_match: retval = only_roman_chars(i) if not retval: count += 1 if count >= threshold: break if (count == threshold): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error while deleting blacklist message.") break else: if ((count != 0) and ((len(to_match) / 2) <= int(count))): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error while deleting blacklist message.") break else: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error while deleting blacklist message.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): message.delete()
def ping(update: Update, context: CallbackContext): bot = context.bot message = update.effective_message parsing = extract_text(message).split(' ') if (len(parsing) < 2): message.reply_text("Give me an address to ping!") return elif (len(parsing) > 2): message.reply_text("Too many arguments!") return dns = (parsing)[1] out = "" under = False if os.name == 'nt': try: output = subprocess.check_output("ping -n 1 " + dns + " | findstr time*", shell=True).decode() except: message.reply_text("There was a problem parsing the IP/Hostname") return outS = output.splitlines() out = outS[0] else: try: out = subprocess.check_output("ping -c 1 " + dns + " | grep time=", shell=True).decode() except: message.reply_text("There was a problem parsing the IP/Hostname") return splitOut = out.split(' ') stringtocut = "" for line in splitOut: if (line.startswith('time=') or line.startswith('time<')): stringtocut = line break newstra = stringtocut.split('=') if len(newstra) == 1: under = True newstra = stringtocut.split('<') newstr = "" if os.name == 'nt': newstr = newstra[1].split('ms') else: newstr = newstra[1].split( ' ') #redundant split, but to try and not break windows ping ping_time = float(newstr[0]) if os.name == 'nt' and under: update.effective_message.reply_text(" Ping speed of " + dns + " is <{}ms".format(ping_time)) else: update.effective_message.reply_text(" Ping speed of " + dns + ": {}ms".format(ping_time))
def reply_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text("بنظر میاد سعی داری یه لینکی استفاده کنی که من اجازه نگه داریشو ندارم " "تلگرام همچین اجازه ایی به امثال من نمیده عزیزم" "اگه میخوای بدونی چیکار باید کنی با @colonel294 ارتباط برقرار کن.") elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text("این پیامی که میخوای بفرستی از دیتا بیسم پاک شده ! دوباره تعریف کن " "یا پیام بده به @colonel294 اگه مشکلت رفع نشد!") LOGGER.warning("Message %s could not be parsed", str(filt.reply)) LOGGER.exception("Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(bot, update): chat_warn_filters = sql.get_chat_warn_filters(update.effective_chat.id) message = update.effective_message to_match = extract_text(message) if not to_match: return for warn_filter in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(warn_filter.keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user_id = update.effective_user.id chat = update.effective_chat warn(user_id, chat, warn_filter.reply, bot, message)
def reply_filter(bot: Bot, update: Update) -> str: chat_warn_filters = sql.get_chat_warn_filters(update.effective_chat.id) message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return "" for warn_filter in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(warn_filter.keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] return warn(user, chat, warn_filter.reply, message) return ""
def reply_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text(get_string("filters", "ERR_BAD_URL", lang.get_lang(update.effective_chat.id))) # ERR_BAD_URL elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text(get_string("filters", "ERR_NO_REPLY", lang.get_lang(update.effective_chat.id))) # ERR_NO_REPLY LOGGER.warning(get_string("filters", "ERR_COULDNT_PARSE", DEFAULT_LANG), str(filt.reply)) # ERR_COULDNT_PARSE LOGGER.exception(get_string("filters", "ERR_COULDNT_PARSE_FILTER", DEFAULT_LANG), str(filt.keyword), str(chat.id)) # ERR_COULDNT_PARSE_FILTER else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(bot: Bot, update: Update) -> str: chat: Optional[Chat] = update.effective_chat message: Optional[Message] = update.effective_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: Optional[User] = update.effective_user warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def reply_filter(update: Update, context: CallbackContext) -> 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 save_replied(bot: Bot, update: Update): chat_id = update.effective_chat.id text = update.effective_message.text args = text.split( None, 3) # use python's maxsplit to separate Cmd, note_name, and data if len(args) == 3 and args[1] == "from": notename = args[2] elif len(args) >= 2: notename = args[1] else: update.effective_message.reply_text( "Bu mesajı kaydetmek için bana bir isim vermelisin.!") return msg = update.effective_message.reply_to_message # type: Optional[Message] if msg.from_user.is_bot: text = extract_text(msg) if text: sql.add_note_to_db(chat_id, notename, markdown_parser(text), is_reply=False) update.effective_message.reply_text( "Bir bottan mesaj kaydetmeye çalışıyor gibisin. " "Botlar, bot mesajlarını iletemez, dolayısıyla tam mesajı kaydedemiyorum. " "\nYapabileceğim tüm metni kaydedeceğim, ama daha fazlasını istiyorsanız, " "iletiyi kendiniz iletmeniz ve sonra kaydetmeniz gerekir..") else: update.effective_message.reply_text( "Bots are kinda handicapped by telegram, making it hard for bots to " "Botlar, telegram tarafından engelleniyor ve robotların diğer botlarla etkileşime " "girmesini zorlaştırıyor, bu yüzden bu mesajı kaydedemiyorum " "iletiyi kendiniz iletmeniz ve sonra kaydetmeniz gerekir") return if MESSAGE_DUMP: msg = bot.forward_message(chat_id=MESSAGE_DUMP, from_chat_id=chat_id, message_id=msg.message_id) sql.add_note_to_db(chat_id, notename, msg.message_id, is_reply=True) update.effective_message.reply_text( "Evet! {} İçin yanıtlama mesajı eklendi".format(notename))
def del_blacklist(update, context) -> str: chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] to_match = extract_text(msg) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: msg.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Blacklist 메시지 삭제 중 오류 발생!") break
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: if keyword.startswith('/') and keyword.endswith('/'): pattern = keyword[1:-1] else: 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 del_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Pesan untuk dihapus tidak ditemukan": pass else: LOGGER.exception("Kesalahan saat menghapus pesan daftar hitam.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Nie znaleziono wiadomości do usunięcia": pass else: LOGGER.exception( "Błąd podczas usuwania wiadomości z czarnej listy.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Silmək üçün mesaj tapılmadı": pass else: LOGGER.exception( "Qara siyahıdakı mesaj silinərkən xəta baş verdi.") break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( get_string( "blacklist", "ERR_CONSOLE_CANT_DELETE_MESSAGE", DEFAULT_LANG)) # ERR_CONSOLE_CANT_DELETE_MESSAGE break
def reply_filter(bot: Bot, update: Update) -> str: delete_expired(bot, update) 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 "" threshold = 7 for keyword in chat_warn_filters: if (keyword == "only_roman"): count = 0 if not only_roman_chars(to_match): for i in to_match: retval = only_roman_chars(i) if not retval: count += 1 if count >= threshold: break if (count == threshold): user = update.effective_user # type: Optional[User] reason = "Nicht romanische Zeichen" return warn(user, chat, reason, message) else: if ((count != 0) and ((len(to_match) / 2) <= int(count))): user = update.effective_user # type: Optional[User] reason = "Nicht romanische Zeichen" return warn(user, chat, reason, message) else: 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 del_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) msg = update.effective_message if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])" match = r_helper.regex_searcher(pattern, to_match) if not match: #Skip to next item in blacklist continue if match: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break