-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
59 lines (43 loc) · 1.61 KB
/
Copy pathbot.py
File metadata and controls
59 lines (43 loc) · 1.61 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
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from app.handlers.common import register_handlers_common
from app.handlers.location import register_handlers_location
from app.services.db import init_db
from config import BOT_TOKEN, ADMIN_ID
logger = logging.getLogger(__name__)
async def set_commands(bot: Bot):
# команды бота
commands = [
BotCommand(command='/start', description='Запустить бота'),
BotCommand(command='/help', description='Помощь'),
]
await bot.set_my_commands(commands)
async def bot_started(bot: Bot):
await bot.send_message(chat_id=ADMIN_ID, text='Бот Запущен')
async def main():
# настройка логирования
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
)
logger.error('Starting bot')
# Инициализируем бота и диспетчера
bot = Bot(token=BOT_TOKEN, parse_mode='html')
dp = Dispatcher(bot, storage=MemoryStorage())
# Регистрация хэндлеров
register_handlers_common(dp, ADMIN_ID)
register_handlers_location(dp)
# Установка команд бота
await set_commands(bot)
await bot_started(bot)
await init_db()
# Запуск поллинга
await dp.skip_updates()
await dp.start_polling()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()