-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (33 loc) · 1.58 KB
/
app.py
File metadata and controls
40 lines (33 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import telebot
from config import TOKEN, symbols
from extensions import APIException, Converter
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start', 'help'])
def help(message: telebot.types.Message):
text = 'Чтобы начать работу введите комманду боту в следующем формате:\n<имя валюты> \
<в какую валюту перевести> \
<количество переводимойвалюты>\nУвидеть список всех доступных валют:/values'
bot.reply_to(message, text)
@bot.message_handler(commands=['values'])
def values(message: telebot.types.Message):
text = 'Доступные валюты:'
for key in symbols.keys():
text = '\n'.join((text, key))
bot.reply_to(message, text)
@bot.message_handler(content_types=['text',])
def converter(message: telebot.types.Message):
try:
values = message.text.split(' ')
values = list(map(str.lower, values))
if len(values) != 3:
raise APIException('Не правильное количество параметров.')
quote, base, amount = values
total_base = Converter.get_price(quote, base, amount)
except APIException as e:
bot.reply_to(message, f'Ошибка пользователя\n{e}')
except Exception as e:
bot.reply_to(message, f'Не удалось обработать команду\n{e}')
else:
text = f'Цена {amount} {quote} в {base} - {total_base}'
bot.send_message(message.chat.id, text)
bot.polling()