-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (34 loc) · 1.41 KB
/
main.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
import logging
from aiogram import Bot, Dispatcher, executor, types
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from commands import process_command
from commands.cmds import fetch_all
from config import BOT_NAME, BOT_API_TOKEN
# Configure logging
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger('broadcast')
# Configure Bot and Dispatcher
bot = Bot(token=BOT_API_TOKEN)
dp = Dispatcher(bot)
# Configure Job Scheduler
scheduler = AsyncIOScheduler()
@dp.message_handler(state='*')
async def router(message: types.Message):
# user = ctr.get_sender(message)
if message.is_command():
reply = process_command(message)
if isinstance(reply, str):
await message.answer(reply, parse_mode="html")
elif isinstance(reply, dict):
if 'photo' in reply.keys():
text = reply['text'] if 'text' in reply.keys() else ''
await message.answer_photo(reply['photo'], reply['text'], parse_mode="html")
reply['photo'].close()
else:
await message.answer(reply['text'], parse_mode="html")
# else:
# await message.answer("Type /help for available commands.", parse_mode="html")
if __name__ == '__main__':
scheduler.add_job(fetch_all, 'cron', hour=17, minute=30, second=0, kwargs={'bot': bot, 'log': log})
scheduler.start()
executor.start_polling(dp, skip_updates=True)