-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
130 lines (104 loc) · 4.88 KB
/
bot.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import logging
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.markdown import text
from aiogram.types import ParseMode
import constants as cnst
import messages as m
from settings import BOT_TOKEN
from messages import get_contacts_msg, get_help_msg, get_start_msg, get_random_input_msg, get_taxi_msg, \
get_feedback_msg, get_transport_msg
from keyboards import main_kb, inline_transport_kb, inline_shops_kb
from constants import BUTTONS, HELP, FEEDBACK
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def send_welcome(message: types.Message):
"""
This handler will be called when user sends `/start` command
"""
msg = get_start_msg()
await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=main_kb)
@dp.message_handler(commands=['help'])
async def process_help_command(message: types.Message):
msg = get_help_msg()
await message.reply(msg, parse_mode=ParseMode.MARKDOWN)
@dp.message_handler(commands=['feedback'])
async def process_feedback_command(message: types.Message):
msg = get_feedback_msg()
await message.reply(msg, parse_mode=ParseMode.HTML)
@dp.message_handler(commands=['myvisit'])
async def process_myvisit_command(message: types.Message):
msg = text("Выбери, какую запись ты хочешь сделать:\n"
)
# TODO add buttons for Darkon and Teudat Zeut
await message.reply(msg, parse_mode=ParseMode.MARKDOWN)
@dp.message_handler(commands=['contacts'])
async def process_contacts_command(message: types.Message):
msg = get_contacts_msg()
await message.reply(msg, parse_mode=ParseMode.HTML)
@dp.message_handler(commands=['transport'])
async def process_transport_command(message: types.Message):
if message.text == '/taxi':
msg = get_taxi_msg()
await message.reply(msg, parse_mode=ParseMode.MARKDOWN)
else:
msg = get_transport_msg()
await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=inline_transport_kb)
@dp.callback_query_handler(lambda c: c.data in cnst.GROUP_TRANSPORT)
async def process_callback_transport(callback_query: types.CallbackQuery):
await bot.answer_callback_query(callback_query.id)
command = callback_query.data
if command == cnst.TAXI:
msg = m.get_taxi_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.MARKDOWN)
elif command == cnst.RAVKAV:
msg = m.get_ravkav_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.HTML)
else:
await bot.answer_callback_query(callback_query.id)
@dp.message_handler(commands=['shops'])
async def process_shops_command(message: types.Message):
msg = text("Что будем покупать?\n")
await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=inline_shops_kb)
@dp.callback_query_handler(lambda c: c.data in cnst.GROUP_SHOPS)
async def process_callback_shops(callback_query: types.CallbackQuery):
await bot.answer_callback_query(callback_query.id)
command = callback_query.data
if command == cnst.GROCERY:
msg = m.get_grocery_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.HTML)
elif command == cnst.HOME_GOODS:
msg = m.get_home_goods_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.HTML)
elif command == cnst.APPLIANCES:
msg = m.get_appliances_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.HTML)
elif command == cnst.OFFICE_SUPPLIES:
msg = m.get_office_supplies_msg()
await bot.answer_callback_query(callback_query.id)
await bot.send_message(chat_id=callback_query.from_user.id, text=msg, parse_mode=ParseMode.HTML)
else:
await bot.answer_callback_query(callback_query.id)
@dp.message_handler()
async def handle_random_input(message: types.Message):
"""handle unknown messages and main keyboard"""
command = BUTTONS.get(message.text)
if not command:
msg = get_random_input_msg()
await message.reply(msg, parse_mode=ParseMode.MARKDOWN)
else:
message.text = command
if command == HELP:
await process_help_command(message)
elif command == FEEDBACK:
await process_feedback_command(message)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)