-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
97 lines (67 loc) · 3.11 KB
/
bot.py
File metadata and controls
97 lines (67 loc) · 3.11 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
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
from config import TOKEN, logger
import services
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher.filters import Text
from aiogram.utils import executor
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
class UserStates(StatesGroup):
user_setName = State()
bot = Bot(token=TOKEN, parse_mode=types.ParseMode.HTML)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
def launch_bot():
try:
services.create_notification_tasks()
executor.start_polling(dp, skip_updates=True)
except Exception as _ex:
logger.error(f'Telegram bot startup error:\n{_ex}')
if __name__ == '__main__':
launch_bot()
@dp.message_handler(lambda message: services.its_admin(message.from_user.id) is False)
async def cmd_start(message: types.Message):
await services.command_start(message)
@dp.message_handler(commands='start')
async def cmd_start(message: types.Message):
await services.command_start(message)
@dp.message_handler(commands='m')
@dp.message_handler(Text(startswith='🆙'))
async def cmd_menu(message: types.Message):
await services.get_main_menu(message)
@dp.message_handler(commands='h')
@dp.message_handler(Text(startswith='❌'))
async def hide_menu(message: types.Message):
await message.reply(text="Спрятано", reply_markup=types.ReplyKeyboardRemove())
@dp.message_handler(Text(startswith='😸 Мои котики'))
async def del_user(message: types.Message):
await services.get_users(message=message, user_type=services.user_types[0])
@dp.message_handler(Text(startswith='🛄 Запросы'))
async def del_user(message: types.Message):
await services.get_users(message=message, user_type=services.user_types[1])
@dp.message_handler(Text(startswith='😐 Заблокированные'))
async def del_user(message: types.Message):
await services.get_users(message=message, user_type=services.user_types[2])
@dp.callback_query_handler(lambda c: c.data.startswith('user_'))
async def callback_user(call: types.callback_query, state: FSMContext):
async with state.proxy() as data:
data['user_id'] = await services.user_callback(call=call, state=state)
data['message'] = call.message
@dp.message_handler(state='*', commands='c')
@dp.message_handler(Text(equals='Отмена', ignore_case=True), state='*')
async def cancel_handler(message: types.Message, state: FSMContext):
"""
Allow user to cancel any action
"""
# Cancel state and inform user about it
await state.finish()
# And remove keyboard (just in case)
await message.reply('Отменено.')
@dp.message_handler(state=UserStates.user_setName)
async def user_set_mame(message: types.Message, state: FSMContext):
async with state.proxy() as data:
await services.user_set_name(message=message, user_id=data['user_id'])
await state.finish()
@dp.callback_query_handler(lambda c: c.data.startswith('notif_'))
async def callback_user(call: types.callback_query):
await services.notification_callback(call=call)