-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
56 lines (44 loc) · 1.36 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
import asyncio
import logging
from aiogram import Bot, Dispatcher, F, types
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import StatesGroup, State
from aiogram.fsm.storage.memory import MemoryStorage
from name_filter import NameFilter
logging.basicConfig(
level=logging.DEBUG,
format="[%(levelname)s]%(asctime)s - %(name)s.%(funcName)s - %(message)s"
)
bot = Bot(token='')
dp = Dispatcher(storage=MemoryStorage())
class StGroup(StatesGroup):
entrypoint = State()
name = State()
@dp.message(Command('Start'))
async def start(message: types.Message):
await message.answer(f"Привет, {message.from_user.username}")
@dp.message(Command('name'))
async def name_entrypoint(
message: types.Message,
state: FSMContext
):
await message.answer('Отправьте имя')
await state.set_state(StGroup.name)
@dp.message(NameFilter(), StGroup.name)
async def name_message(
message: types.Message,
state: FSMContext,
name: list
):
await message.answer(f"Ваше имя: {name}")
await state.clear()
async def main():
try:
await dp.start_polling(bot,
allowed_updates=dp.resolve_used_update_types())
finally:
await dp.storage.close()
await bot.session.close()
if __name__ == "__main__":
asyncio.run(main())