-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
44 lines (37 loc) · 1.65 KB
/
Copy pathbot.py
File metadata and controls
44 lines (37 loc) · 1.65 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
41
42
43
44
import asyncio
from config import keys, WELCOME
from extensions import Exchange, Kbds, News, APIException
from botToken import BOT_TOKEN
from telebot.async_telebot import AsyncTeleBot
bot = AsyncTeleBot(BOT_TOKEN, parse_mode='HTML')
@bot.message_handler(commands=['start', 'help'])
async def welcome(message):
await bot.reply_to(message, WELCOME, reply_markup=Kbds.get_replykbd(),
parse_mode=None)
@bot.message_handler(commands=['values'])
async def value(message):
val = '🔄 Валюты, доступные для конвертации и их ключи:\n'
for key, lst in keys.items():
val += f'\n{lst[2]} ➡ {key}'
await bot.send_message(message.chat.id, val)
@bot.message_handler(content_types=['text'])
async def handl(message):
if message.text == '📈 Курсы доступных валют':
await bot.send_message(message.chat.id, Exchange.get_dayly_rates())
elif message.text == '📰 Новости валютных рынков':
await News.get_news(bot, message=message)
else:
try:
await bot.reply_to(message, Exchange.get_price(message.text))
except APIException as e:
await bot.reply_to(message, f'⛔ Ошибка ввода!\n\n{e}')
except Exception as e:
await bot.reply_to(message, f'⛔ Не удалось обработать команду\n{e}')
@bot.callback_query_handler(func=lambda call: True)
async def callback(call):
if call.data == 'back':
await News.get_news(bot, call=call)
else:
await News.get_text(bot, call)
if __name__ == '__main__':
asyncio.run(bot.infinity_polling())