import os import telebot from latinica import Converter bot = telebot.TeleBot(os.getenv('TELEGRAM_API_TOKEN'), parse_mode='MARKDOWN') @bot.message_handler(commands=['start', 'help']) def handle_start(message): bot.reply_to(message, 'Danný bot sozdan dlja togo, čtoby perevodit́ tekst na russkom jazyke s kirillicy na latinicu.\nPrimer ispoĺzovanija:\n/cy2la Привет, мир!') @bot.message_handler(commands=['cy2la']) def handle_cy2la(message): text = ' '.join(message.text.split(' ')[1:]).strip() if len(text) < 1: bot.reply_to(message, 'Tekst soobŝenija ne dolžen byt́ pustym.') return converter = Converter(text) result = converter.convert() result = result.replace('```', '`').strip() bot.reply_to(message, f'Rezultat:\n```\n{result}```') @bot.inline_handler(lambda _: True) def query_text(inline_query): text = inline_query.query.strip() converter = Converter(text) result = converter.convert() try: r = telebot.types.InlineQueryResultArticle('1', result, telebot.types.InputTextMessageContent(result)) bot.answer_inline_query(inline_query.id, [r]) except: pass bot.infinity_polling()