def add_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) >= 2: # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() content = extracted[1] else: return # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, WARN_HANDLER_GROUP) sql.add_warn_filter(chat.id, keyword, content) update.effective_message.reply_text( "Warn handler added for '{}'!".format(keyword)) raise DispatcherHandlerStop
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("Nenhum filtro de warn ativo aqui!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Vou parar de dar warn por isso.") raise DispatcherHandlerStop msg.reply_text( "Isso não é um filtro de warn atual - digite /warnlist para todos os filtros de warn." )
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("මෙහි කිසිදු අනතුරු ඇඟවීමේ පෙරහන් සක්රීය නොවේ!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("ඔව්, මම ඒ සඳහා මිනිසුන්ට අනතුරු ඇඟවීම නවත්වමි.") raise DispatcherHandlerStop msg.reply_text( "එය වත්මන් අනතුරු ඇඟවීමේ පෙරණයක් නොවේ - ධාවනය කරන්න /warnlist සියලුම ක්රියාකාරී අනතුරු ඇඟවීමේ පෙරහන් සඳහා." )
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("Brak aktywnych filtrów ostrzeżeniowych!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Tak, przestanę dawać futrzakom otrzeżenia za to.") raise DispatcherHandlerStop msg.reply_text("To nie jest obecnie filtr ostrzeżeniowy - Użyj /warnlist żeby zobaczyć listę obecnych filtrów otrzeżeniowych.")
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("هنوز کلمه/جمله ممنوعه برام ثبت نشده") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "چشم قربان ،من دیگه مردم رو برای این موضوع دستگیر نمیکنم👮🏻♂️") raise DispatcherHandlerStop msg.reply_text( "میبخشید داخل پرونده ها این کلمه/جمله رو نمیبینم /warnlist رو چک کن👮🏻♂️" )
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("Aktif uyarı filtresi yok!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Evet, bunun için insanları uyarmayı bırakacağım.") raise DispatcherHandlerStop msg.reply_text( "Mevcut uyarı filtresi yok - /uyarilistesi komutu ile kontrol edin.")
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("لا توجد مرشحات تحذير نشطة هنا!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("نعم، سوف أتوقف عن تحذير الناس لذلك.") raise DispatcherHandlerStop msg.reply_text( "هذا ليس مرشح تحذير الحالي - تشغيل / حذر لجميع مرشحات التحذير النشطة.")
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("Nessun filtro di ammonimento attivo!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Filtro disattivato per questo termine.") raise DispatcherHandlerStop msg.reply_text( "Questo attualmente non è un filtro di ammonimento - esegui /warnlist per la lista di tutti i filtri attivi." )
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("No warning filters are active here!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Yep, I'll stop warning people for that.") 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 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("Burada heç bir xəbərdarlıq filtri aktiv deyil!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Yep, I'll stop warning people for that.") raise DispatcherHandlerStop msg.reply_text("Bu cari bir xəbərdarlıq filtri deyil - bütün aktiv xəbərdarlıq filtrləri üçün /warnlist yazın.")
def remove_warn_filter(bot: Bot, update: Update): chat: Optional[Chat] = update.effective_chat msg: Optional[Message] = 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("Tidak ada filter peringatan yang aktif di sini!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "Oke, saya akan berhenti memperingatkan orang untuk itu.") raise DispatcherHandlerStop msg.reply_text( "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif." )
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("ഇവിടെ AUTO-WARN വാക്കുകൾ ഒന്നും ലഭ്യമല്ല!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("ഞാൻ ഇനി ആ വാക്കിന് താക്കീതുകൾ നൽകുന്നതല്ല") raise DispatcherHandlerStop msg.reply_text("അതൊരു AUTO-WARN വാക്കല്ല /warnlist കൊടുത്ത് ഇപ്പോൾ ലഭ്യമായിട്ടുള്ള AUTO-WARN വാക്കുകൾ നോക്കാവുന്നതാണ്.")
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("اومم فیلتر خاصی برای اخطار تعیین نشده برام!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "باوش من دیگه بخاطر این به ملت اخطار نمیدم ، قول !.") raise DispatcherHandlerStop msg.reply_text( "اومم این یه دستور اخطار درست نیست عزیزم دستور /warnlist رو بزن تا همه رو ببینی!." )
def remove_warn_filter(update: Update, context: CallbackContext): 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("여기에는 활성 상태의 경고 필터가 없어요!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("네, 그런 경고는 그만할게요.") raise DispatcherHandlerStop msg.reply_text("현재 경고 필터가 아니에요. 모든 활성 경고 필터를 위해 /warnlist 을(를) 입력해보세요.")
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("कोई चेतावनी फ़िल्टर यहां सक्रिय नहीं हैं !") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( " हां, मैं लोगों को इसके लिए चेतावनी देना बंद कर दूंगा") 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 # 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("Burada Aktif Uyarı Filtresi Yok!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Evet, Bunun İçin İnsanları Uyarmayı Bırakacağım.") raise DispatcherHandlerStop msg.reply_text("Bu Geçerli Bir Uyarı Filtresi Değil -Tüm Aktif Uyarı Filtreleri İçin /warnlist Yaz")
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("Burada xəbərdarlıq filtrləri yoxdur!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "Yep, Artıq buna görə insanlara xəbərdarlıq verməyəcəm.") raise DispatcherHandlerStop msg.reply_text( "Bu aktiv xəbərdarlıq filtri deyil - /warnlist yazaraq aktiv xəbərdarlıq filtrlərinə baxa bilərsən." )
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 filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" else: chat_name = chat.title if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "tidak note tersimpan disini - tidak bisa jika hanya tombol, harus disertakan dengan pesan juga!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: offset = len(msg.reply_to_message.caption) ignore_underscore_case, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text("You didn't specify what to reply with!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) msg.reply_text("Handler '{}' added in *{}*!".format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop
def filters(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 # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "There is no note message - You can't JUST have buttons, you need a message to go with it!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text("You didn't specify what to reply with!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat.id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) msg.reply_text("Handler '{}' added!".format(keyword)) raise DispatcherHandlerStop
def filters(bot: Bot, update: Update): chat = update.effective_chat msg = update.effective_message args = msg.text.split(None, 1) if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text ) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset ) content = content.strip() if not content: msg.reply_text( "Tidak ada pesan catatan - Anda tidak bisa HANYA memiliki tombol, Anda perlu pesan untuk menyertainya!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: content = msg.reply_to_message.photo[-1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text("Anda tidak menentukan harus membalas dengan apa!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter( chat.id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons, ) msg.reply_text("Handler '{}' added!".format(keyword)) raise DispatcherHandlerStop
def filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" else: chat_name = chat.title if len(args) < 2: return # check irfst if BMERNU_SCUT_SRELFTI: total_fs = sql.num_filters_per_chat(chat_id) if total_fs >= BMERNU_SCUT_SRELFTI: msg.reply_text( f"You currently have {total_fs} filters. " f"The maximum number of filters allowed is {BMERNU_SCUT_SRELFTI}. " "You need to delete some filters " "before being allowed to add more " "or use @kochufilterbot for unlimited filters.") return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False media_caption = None has_caption = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "There is no note message - You can't JUST have buttons, you need a message to go with it!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True # stickers don't have caption in BOT API -_- elif msg.reply_to_message and msg.reply_to_message.document: offset = len(msg.reply_to_message.caption) media_caption, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.document.file_id is_document = True has_caption = True elif msg.reply_to_message and msg.reply_to_message.photo: offset = len(msg.reply_to_message.caption) media_caption, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True has_caption = True elif msg.reply_to_message and msg.reply_to_message.audio: offset = len(msg.reply_to_message.caption) media_caption, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.audio.file_id is_audio = True has_caption = True elif msg.reply_to_message and msg.reply_to_message.voice: offset = len(msg.reply_to_message.caption) media_caption, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.voice.file_id is_voice = True has_caption = True elif msg.reply_to_message and msg.reply_to_message.video: offset = len(msg.reply_to_message.caption) media_caption, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.video.file_id is_video = True has_caption = True else: msg.reply_text("You didn't specify what to reply with!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons, media_caption, has_caption) msg.reply_text("Handler `{}` added in *{}*!".format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop
def filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "yerli filtrlər" else: chat_name = chat.title if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "Qeyd mesajı yoxdur - İndi button əlavə edə bilmərsən, bununla biryerdə mesaj verməlisən!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: offset = len(msg.reply_to_message.caption) ignore_underscore_case, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text("Nə cavab verəcəyinizi müəyyən etməmisiniz!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) msg.reply_text("`{}` filtri *{}* qrupunda əlavə edildi !".format( keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop
def filters(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(context.bot, update, chat, user.id) if not conn is False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" else: chat_name = chat.title if not msg.reply_to_message and len(args) < 2: send_message( update.effective_message, "Please provide keyboard keyword for this filter to reply with!", ) return if msg.reply_to_message: if len(args) < 2: send_message( update.effective_message, "Please provide keyword for this filter to reply with!", ) return else: keyword = args[1] else: extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat_id): dispatcher.remove_handler(handler, HANDLER_GROUP) text, file_type, file_id = get_filter_type(msg) if not msg.reply_to_message and len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename text, buttons = button_markdown_parser(extracted[1], entities=msg.parse_entities(), offset=offset) text = text.strip() if not text: send_message( update.effective_message, "There is no note message - You can't JUST have buttons, you need a message to go with it!", ) return elif msg.reply_to_message and len(args) >= 2: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing ) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() elif not text and not file_type: send_message( update.effective_message, "Please provide keyword for this filter reply with!", ) return elif msg.reply_to_message: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing ) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() if (msg.reply_to_message.text or msg.reply_to_message.caption) and not text: send_message( update.effective_message, "There is no note message - You can't JUST have buttons, you need a message to go with it!", ) return else: send_message(update.effective_message, "Invalid filter!") return add = addnew_filter(update, chat_id, keyword, text, file_type, file_id, buttons) # This is an old method # sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) if add is True: send_message( update.effective_message, "Saved filter '{}' in *{}*!".format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) raise DispatcherHandlerStop
def filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" else: chat_name = chat.title if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "कोई नोट मैसेज नहीं है - आपके पास बस बटन नहीं हो सकते हैं, आपको इसके साथ जाने के लिए मैसेज की आवश्यकता है!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: offset = len(msg.reply_to_message.caption) ignore_underscore_case, buttons = button_markdown_parser( msg.reply_to_message.caption, entities=msg.reply_to_message.parse_entities(), offset=offset) content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text( "आपने निर्दिष्ट नहीं किया कि किसके साथ क्या उत्तर देना है") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) msg.reply_text("हैंडलर '{}' एडेड इन *{}*!".format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop