Exemplo n.º 1
0
def handle_audio_command(message):
    try:
        info = bot.get_file(message.voice.file_id)
        url = 'https://api.telegram.org/file/bot{0}/{1}'.format(
            token, info.file_path)
        opener = req.build_opener(req.ProxyHandler(telebot.apihelper.proxy))
        audio_data = opener.open(url)
        Path('./temp/audio/').mkdir(parents=True, exist_ok=True)
        path = str(Path('./temp/audio/' + info.file_id))
        with open(path + '.oga', 'wb') as f:
            f.write(audio_data.read())
        subprocess.run([
            'ffmpeg', '-hide_banner', '-loglevel', 'panic', '-i',
            path + '.oga', path + '.wav'
        ])
        message.text = transcribe_audio(path + '.wav')
        bot.send_message(message.chat.id, message.text)
        handle_text_command(message)
    except UnknownValueError:
        lang = db.get_lang(message.chat.id)
        bot.send_message(message.chat.id, t('15', lang))
    except RequestError:
        lang = db.get_lang(message.chat.id)
        bot.send_message(message.chat.id, t('16', lang))
    except BaseException:
        lang = db.get_lang(message.chat.id)
        bot.send_message(message.chat.id, t('14', lang))
    finally:
        os.remove(path + '.oga')
        os.remove(path + '.wav')
Exemplo n.º 2
0
def callback_worker(call):
    cid = call.message.chat.id
    if call.data in dicts.keys():
        db.change_lang(cid, call.data)
        bot.edit_message_text(chat_id=cid,
                              message_id=call.message.message_id,
                              text=t('5', call.data))
    if call.data in fiat.keys():
        db.change_currency(cid, call.data)
        lang = db.get_lang(cid)
        bot.edit_message_text(chat_id=cid,
                              message_id=call.message.message_id,
                              text=t('11', lang))
Exemplo n.º 3
0
def select_lang(cid):
    lang = db.get_lang(cid)
    keyboard = telebot.types.InlineKeyboardMarkup()
    key_eng = telebot.types.InlineKeyboardButton(text='\U0001F1F7\U0001F1FA',
                                                 callback_data='rus')
    key_rus = telebot.types.InlineKeyboardButton(text='\U0001F1FA\U0001F1F8',
                                                 callback_data='eng')
    keyboard.add(key_eng, key_rus)
    bot.send_message(cid, t('3', lang) + ':', reply_markup=keyboard)
Exemplo n.º 4
0
def select_currency(cid):
    lang = db.get_lang(cid)
    keyboard = telebot.types.InlineKeyboardMarkup()
    key_usd = telebot.types.InlineKeyboardButton(text=u'\u0024',
                                                 callback_data='usd')
    key_eur = telebot.types.InlineKeyboardButton(text=u'\u20AC',
                                                 callback_data='eur')
    key_rub = telebot.types.InlineKeyboardButton(text=u'\u20BD',
                                                 callback_data='rub')
    keyboard.add(key_usd, key_eur, key_rub)
    bot.send_message(cid, t('10', lang) + ':', reply_markup=keyboard)
Exemplo n.º 5
0
def get_coin_info(cid, coin_name):
    lang = db.get_lang(cid)
    curr = db.get_currency(cid)
    with get_coin_name(cid, coin_name) as coin:
        if coin is None:
            raise UnknownCoinError(coin_name)
        coin = coins[coin]
        info = cg.get_price(ids=coin,
                            vs_currencies=curr,
                            include_market_cap='true',
                            include_24hr_vol='true',
                            include_24hr_change='true')
        msg = ('*' + coin + '*\n' + t('6', lang) + ': ' +
               str(info[coin][curr]) + fiat[curr] + '\n' + t('7', lang) +
               ': ' + str(info[coin][curr + '_market_cap']) + fiat[curr] +
               '\n' + t('8', lang) + ': ' +
               str(info[coin][curr + '_24h_vol']) + fiat[curr] + '\n' +
               t('9', lang) + ': ' + str(info[coin][curr + '_24h_change']) +
               '%')
        bot.send_message(cid, msg, parse_mode='Markdown')
Exemplo n.º 6
0
def get_coin_name(cid, raw_name):
    try:
        if raw_name in coins.keys():
            yield raw_name
        else:
            match = difflib.get_close_matches(raw_name, coins.keys(), 1, 0.75)
            if len(match) > 0:
                lang = db.get_lang(cid)
                bot.send_message(cid,
                                 t('13', lang) + ': _' + match[0] + '_',
                                 parse_mode='Markdown')
                yield match[0]
            else:
                yield None
    except UnknownCoinError as e:
        lang = db.get_lang(cid)
        bot.send_message(cid, t('1', lang) + ': ' + e.msg)
        bot.send_sticker(cid, 'CAADAgADWwADsiFfFVNQKDUCqm9IAg')
    except Exception:
        lang = db.get_lang(cid)
        bot.send_message(cid, t('14', lang))
Exemplo n.º 7
0
def handle_unknown_command(message):
    lang = db.get_lang(message.chat.id)
    bot.send_message(message.chat.id, t('12', lang))
Exemplo n.º 8
0
def handle_help(message):
    lang = db.get_lang(message.chat.id)
    bot.send_message(message.chat.id, t('4', lang), parse_mode='Markdown')
Exemplo n.º 9
0
def handle_start(message):
    lang = db.get_lang(str(message.chat.id))
    bot.send_message(message.chat.id, t('2', lang))
    bot.send_sticker(message.chat.id, 'CAADAgADhAYAAmMr4gmSKCx3G-t1mAI')
    db.add_user(message.chat.id)
    select_lang(message.chat.id)