def handle_lang(message): keyboard = telebot.types.InlineKeyboardMarkup() for lang_alias, language in bot_activity["vocabulary"].items(): keyboard.add( telebot.types.InlineKeyboardButton(text=language, callback_data=lang_alias)) logger.bot_logger.info("%s: %s" % (message.chat, message.text)) lang = db_manager.get_lang(message.chat.id) bot.send_message(message.chat.id, bot_activity['commands'][lang][message.text], reply_markup=keyboard)
def get_explanation(message): logger.bot_logger.info("%s: %s" % (message.chat, message.text)) explanation = engine.search(message.text, lang=db_manager.get_lang(message.chat.id)) logger.bot_logger.info( 'Send to %s: %s...' % (message.chat.id, explanation[:min(140, len(explanation))])) for position in range(len(explanation) // (2**12) + 1): from_position = position * (2**12) to_position = min(len(explanation), (position + 1) * (2**12)) bot.send_message(message.chat.id, explanation[from_position:to_position])
def get_top(message): logger.bot_logger.info("%s: %s" % (message.chat, message.text)) lang = db_manager.get_lang(message.chat.id) if len(message.text.split(' ')) != 2: bot.send_message(message.chat.id, bot_activity['commands'][lang]["top_error"]) else: _, limit = message.text.split(' ') try: limit = int(limit) for response in engine.get_top(limit, lang): bot.send_message(message.chat.id, response) except ValueError: bot.send_message(message.chat.id, bot_activity['commands'][lang]["top_error"])
def handle_statistics(message): logger.bot_logger.info("%s: %s" % (message.chat, message.text)) lang = db_manager.get_lang(message.chat.id) bot.send_message(message.chat.id, bot_activity['commands'][lang][message.text]) lang_fname = analytics.language_frequency(message.chat.id) with open(lang_fname, 'rb') as lang_bar_chart: bot.send_message(message.chat.id, bot_activity['commands'][lang]["statistics"]["users"]) bot.send_photo(message.chat.id, lang_bar_chart) os.remove(lang_fname) req_fname = analytics.request_frequency(message.chat.id) with open(req_fname, 'rb') as req_bar_chart: bot.send_message(message.chat.id, bot_activity['commands'][lang]["statistics"]["terms"]) bot.send_photo(message.chat.id, req_bar_chart) os.remove(req_fname)
def handle_start_help(message): logger.bot_logger.info("%s: %s" % (message.chat, message.text)) lang = db_manager.get_lang(message.chat.id) bot.send_message(message.chat.id, bot_activity['commands'][lang][message.text])