def send(update, message, keyboard, backup_message): chat = update.effective_chat cleanserv = sql.clean_service(chat.id) reply = update.message.message_id # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply, ) except BadRequest as excp: if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: the current message has an invalid url " "in one of its buttons. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNote: the current message has buttons which " "use url protocols that are unsupported by " "telegram. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: the current message has some bad urls. " "Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("Could not parse! got invalid url host errors") else: msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNote: An error occured when sending the " "custom message. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.exception() return msg
def send(update, message, keyboard, backup_message): chat = update.effective_chat cleanserv = sql.clean_service(chat.id) reply = update.message.message_id # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply) except BadRequest as excp: if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNot: mevcut mesajda geçersiz bir url var " "düğmelerinden birinde. Lütfen güncelle."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNot: geçerli mesajın düğmeleri var" "tarafından desteklenmeyen URL protokollerini kullanın " "telegram. Lütfen güncelle."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNot: mevcut mesajda bazı kötü URL'ler var. " "Lütfen güncelle."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("Could not parse! got invalid url host errors") else: msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNot: Gönderilirken bir hata oluştu " "custom message. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply) LOGGER.exception() return msg
def send(update, message, keyboard, backup_message): try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: the current message has an invalid url " "in one of its buttons. Please update."), parse_mode=ParseMode.MARKDOWN) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: the current message has buttons which " "use url protocols that are unsupported by " "telegram. Please update."), parse_mode=ParseMode.MARKDOWN) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: the current message has some bad urls. " "Please update."), parse_mode=ParseMode.MARKDOWN) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("Could not parse! got invalid url host errors") else: msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNote: An error occured when sending the " "custom message. Please update."), parse_mode=ParseMode.MARKDOWN) LOGGER.exception() return msg
def set_rules(update: Update, context: CallbackContext): chat_id = update.effective_chat.id msg = update.effective_message # type: Optional[Message] raw_text = msg.text args = raw_text.split(None, 1) # use python's maxsplit to separate cmd and args if len(args) == 2: txt = args[1] offset = len(txt) - len(raw_text) # set correct offset relative to command markdown_rules = markdown_parser( txt, entities=msg.parse_entities(), offset=offset ) sql.set_rules(chat_id, markdown_rules) update.effective_message.reply_text("Successfully set rules for this group.")
def set_rules(bot: Bot, update: Update): chat_id = update.effective_chat.id msg = update.effective_message # type: Optional[Message] raw_text = msg.text args = raw_text.split(None, 1) # use python's maxsplit to separate cmd and args if len(args) == 2: txt = args[1] offset = len(txt) - len( raw_text) # set correct offset relative to command markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) sql.set_rules(chat_id, markdown_rules) update.effective_message.reply_text( "Bu grup için kurallar başarıyla ayarlandı.")
def send(update, message, keyboard, backup_message): chat = update.effective_chat cleanserv = sql.clean_service(chat.id) reply = update.message.message_id # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply, ) except BadRequest as excp: if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nQeyd: Mesaj düymələrindən birində etibarsız url " "var. Zəhmət olmasa, yeniləyin."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nQeyd: Mesajda Telegram tərəfindən dəstəklənməyən url protokollarından" "istifadə edən düymələr var. protocols that are unsupported by " "telegram. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nQeyd: Cari mesajda səhv URL. " "var. Zəhmət olmazsa yeniləyin :)."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("Could not parse! got invalid url host errors") elif excp.message == "Have no rights to send a message": return else: msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nQeyd: Xüsusi mesaj" "göndərilərkən bir xəta baş verdi. Zəhmət olmasa, yeniləyin :)." ), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.exception() return msg
def send(update, message, keyboard, backup_message): chat = update.effective_chat cleanserv = sql.clean_service(chat.id) reply = update.message.message_id # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply, ) except BadRequest as excp: if excp.message == "Mensaje de respuesta no encontrado": msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, quote=False) elif excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNota: el mensaje actual tiene una URL no válida " "en uno de sus botones. Por favor actualícelo."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Protocolo de URL no admitido": msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNota: el mensaje actual tiene botones que " "utilizar protocolos de URL que no son compatibles con " "Telegram. Por favor actualícelo."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Host de URL incorrecto": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNota: el mensaje actual tiene algunas URL incorrectas. " "Por favor, actualícelas"), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("¡No se pudo analizar! obtuve errores de host de URL no válidas") elif excp.message == "No tiene derecho a enviar un mensaje": return else: msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNota: Ocurrió un error al enviar el " "mensaje personalizado. Por favor actualícelo."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.exception() return msg
def send(update, message, keyboard, backup_message): chat = update.effective_chat cleanserv = sql.clean_service(chat.id) reply = update.message.message_id # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False try: msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply, ) except BadRequest as excp: if excp.message == "Cevap mesajı bulunamadı": msg = update.effective_message.reply_text( message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, quote=False) elif excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: mevcut iletinin geçersiz bir url'si var " "düğmelerinden birinde. Lütfen güncelleyin."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Desteklenmeyen url protokolü": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: mevcut mesajda " "tarafından desteklenmeyen url protokollerini kullan " "telegram ı Lütfen güncelleyin.."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Yanlış url barındırıcısı": msg = update.effective_message.reply_text( markdown_parser( backup_message + "\nNote: Geçerli iletide bazı hatalı URL'ler var. " "Lütfen güncelle."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception( "Ayrıştırılamadı! geçersiz url ana bilgisayar hataları aldı") elif excp.message == "Mesaj gönderme hakkınız yok": return else: msg = update.effective_message.reply_text( markdown_parser(backup_message + "\nNote: Gönderirken bir hata oluştu " "özel mesaj. Lütfen güncelleyin."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) LOGGER.exception() return msg