This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
47 lines (34 loc) · 1.79 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
44
45
46
47
import datetime
import logging
from aiogram import types, Bot, Dispatcher, executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.utils.exceptions import MessageNotModified
from inline_calendar.inline_calendar import InlineCalendar
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
YOUR_TOKEN = 'TOKEN'
bot = Bot(token=YOUR_TOKEN)
dp = Dispatcher(bot, storage=MemoryStorage())
inline_calendar = InlineCalendar()
@dp.message_handler(commands=['calendar'])
async def calendar_test(msg: types.Message):
inline_calendar.init(datetime.date.today(),
datetime.date.today() - datetime.timedelta(weeks=16),
datetime.date.today() + datetime.timedelta(weeks=16))
await bot.send_message(msg.from_user.id, text='test', reply_markup=inline_calendar.get_keyboard())
@dp.callback_query_handler(inline_calendar.filter())
async def calendar_callback_handler(q: types.CallbackQuery, callback_data: dict):
await bot.answer_callback_query(q.id)
return_data = inline_calendar.handle_callback(q.from_user.id, callback_data)
if return_data is None:
await bot.edit_message_reply_markup(chat_id=q.from_user.id, message_id=q.message.message_id,
reply_markup=inline_calendar.get_keyboard(q.from_user.id))
else:
picked_data = return_data
await bot.edit_message_text(text=picked_data, chat_id=q.from_user.id, message_id=q.message.message_id,
reply_markup=inline_calendar.get_keyboard())
@dp.errors_handler(exception=MessageNotModified)
async def error_handler(update, error):
return True
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)