|
@@ -7,12 +7,12 @@ from handlers.user.states import BookingState
|
|
|
from aiogram.dispatcher.storage import FSMContext
|
|
|
from bot import messages
|
|
|
from handlers.admin.notifications import new_event
|
|
|
-import datetime
|
|
|
+from datetime import date, datetime
|
|
|
import calendar
|
|
|
|
|
|
|
|
|
async def make_event(message: types.message):
|
|
|
- today = datetime.date.today()
|
|
|
+ today = date.today()
|
|
|
month = today.month
|
|
|
days_in_month = calendar.monthrange(today.year, month)[1]
|
|
|
db = database.Database()
|
|
@@ -23,56 +23,74 @@ async def make_event(message: types.message):
|
|
|
else:
|
|
|
if message.text == "🎯 Запланировать мероприятие":
|
|
|
await message.delete()
|
|
|
- # TODO: Добавить переход на следующий месяц
|
|
|
-
|
|
|
await message.answer(messages.events_welcome(make_date()), reply_markup=make_calendar(month,
|
|
|
days_in_month,
|
|
|
- 'month_prev:0',
|
|
|
- 'month_next:0'))
|
|
|
- # await message.answer(messages.events_welcome(make_date()), reply_markup=make_calendar())
|
|
|
- # await asyncio.sleep(60)
|
|
|
- # await msg.delete()
|
|
|
+ f"month_prev:{month}",
|
|
|
+ f"month_next:{month}"))
|
|
|
|
|
|
|
|
|
async def select_date(call: types.CallbackQuery, state: FSMContext):
|
|
|
db = database.Database()
|
|
|
date = call.data.split("_")[1]
|
|
|
booked = db.sql_fetchall(sql.sql_booked_time(date))
|
|
|
- today = datetime.datetime.now()
|
|
|
- if date >= datetime.datetime.strftime(today, '%Y-%m-%d'):
|
|
|
+ today = datetime.strftime(datetime.today(), '%Y-%m-%d')
|
|
|
+ t_day = today.split("-")[2]
|
|
|
+ t_month = today.split("-")[1]
|
|
|
+
|
|
|
+ if int(date.split("-")[1]) == int(t_month):
|
|
|
+ if int(date.split("-")[2]) >= int(t_day):
|
|
|
+ if len(booked) == 0:
|
|
|
+ await BookingState.start.set()
|
|
|
+ await state.update_data(date=to_quotes(date))
|
|
|
+ await state.update_data(owner=call.from_user.id)
|
|
|
+ await call.message.edit_text(f"Вы выбрали дату: {date}\n"
|
|
|
+ f"На этот день мероприятий не запланированно", reply_markup=events_kb())
|
|
|
+ else:
|
|
|
+ await BookingState.start.set()
|
|
|
+ await state.update_data(date=to_quotes(date))
|
|
|
+ await state.update_data(owner=call.from_user.id)
|
|
|
+ await call.message.edit_text(f"Вы выбрали дату: {date}\n\n"
|
|
|
+ f"Занятое время\n\n"
|
|
|
+ f"{beauty_booked_time(sorted(booked, key=lambda t: t['e_start'], reverse=False))}",
|
|
|
+ reply_markup=events_kb())
|
|
|
+ else:
|
|
|
+ msg = await call.message.answer("Нельзя выбрать дату позже сегодняшней")
|
|
|
+ await asyncio.sleep(5)
|
|
|
+ await msg.delete()
|
|
|
+ elif int(date.split("-")[1]) > int(t_month):
|
|
|
if len(booked) == 0:
|
|
|
await BookingState.start.set()
|
|
|
await state.update_data(date=to_quotes(date))
|
|
|
await state.update_data(owner=call.from_user.id)
|
|
|
await call.message.edit_text(f"Вы выбрали дату: {date}\n"
|
|
|
- f"На этот день мероприятий не запланированно", reply_markup=events_kb())
|
|
|
- # await asyncio.sleep(30)
|
|
|
- # await msg.delete()
|
|
|
+ f"На этот день мероприятий не запланированно", reply_markup=events_kb())
|
|
|
else:
|
|
|
await BookingState.start.set()
|
|
|
await state.update_data(date=to_quotes(date))
|
|
|
await state.update_data(owner=call.from_user.id)
|
|
|
await call.message.edit_text(f"Вы выбрали дату: {date}\n\n"
|
|
|
- f"Занятое время\n\n"
|
|
|
- f"{beauty_booked_time(sorted(booked, key=lambda t: t['e_start'], reverse=False))}",
|
|
|
- reply_markup=events_kb())
|
|
|
- # await asyncio.sleep(60)
|
|
|
- # await msg.delete()
|
|
|
+ f"Занятое время\n\n"
|
|
|
+ f"{beauty_booked_time(sorted(booked, key=lambda t: t['e_start'], reverse=False))}",
|
|
|
+ reply_markup=events_kb())
|
|
|
else:
|
|
|
- await call.message.answer("Нельзя выбрать дату позже сегодняшней")
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
+ msg = await call.message.answer("Нельзя выбрать дату позже сегодняшней")
|
|
|
+ await asyncio.sleep(5)
|
|
|
+ await msg.delete()
|
|
|
|
|
|
|
|
|
async def edit_date(call: types.CallbackQuery, state: FSMContext):
|
|
|
+ today = date.today()
|
|
|
+ month = today.month
|
|
|
+ days_in_month = calendar.monthrange(today.year, month)[1]
|
|
|
await call.message.edit_text(f"выберите дату чтобы увидеть список мероприятий\n\n"
|
|
|
- f"Так же календарь мероприятий можно посмотреть в "
|
|
|
- f"<a href=moodle.tomtit-tomsk.ru>Moodle</a>\n\n"
|
|
|
- f"Сегодняшняя дата <b>{make_date()}</b>", reply_markup=make_calendar(month, days_in_month))
|
|
|
- await call.message.delete()
|
|
|
+ f"Так же календарь мероприятий можно посмотреть в "
|
|
|
+ f"<a href=moodle.tomtit-tomsk.ru>Moodle</a>\n\n"
|
|
|
+ f"Сегодняшняя дата <b>{make_date()}</b>", reply_markup=make_calendar(month,
|
|
|
+ days_in_month,
|
|
|
+ f"month_prev:{month}",
|
|
|
+ f"month_next:{month}"))
|
|
|
+
|
|
|
await state.finish()
|
|
|
- # await asyncio.sleep(30)
|
|
|
- # await msg.delete()
|
|
|
|
|
|
|
|
|
async def booking_date(call: types.CallbackQuery):
|
|
@@ -83,49 +101,36 @@ async def booking_date(call: types.CallbackQuery):
|
|
|
"10:30 14:00\n"
|
|
|
"11.50-12.30\n", reply_markup=cancel_booking())
|
|
|
await BookingState.time.set()
|
|
|
- # await asyncio.sleep(20)
|
|
|
- # await msg.delete()
|
|
|
|
|
|
|
|
|
async def get_time(message: types.Message, state: FSMContext):
|
|
|
# Парсим то что ввел пользователь
|
|
|
time = normalize_time(message.text)
|
|
|
await message.delete()
|
|
|
- # Забираем текущую дату
|
|
|
date = await state.get_data()
|
|
|
# Проверяем валидность времени
|
|
|
if time_validator(message.text):
|
|
|
# Проверяем что старт не позже конца
|
|
|
if time[0] > time[1]:
|
|
|
await message.answer("Начало не может быть раньше конца")
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
elif not check_overlap(time[0], time[1], date['date']):
|
|
|
- print(time[0],time[1])
|
|
|
await message.answer("Указанное время пеерсекается")
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
+
|
|
|
else:
|
|
|
await state.update_data(t_start=time[0])
|
|
|
await state.update_data(t_end=time[1])
|
|
|
- print(time)
|
|
|
await BookingState.description.set()
|
|
|
await message.answer("Введите краткое описание мероприятия", reply_markup=cancel_booking())
|
|
|
- # await asyncio.sleep(10)
|
|
|
- # await msg.delete()
|
|
|
+
|
|
|
else:
|
|
|
await message.answer("Неверный формат времени")
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
|
|
|
|
|
|
async def send_event(message: types.Message, state: FSMContext):
|
|
|
db = database.Database()
|
|
|
if len(message.text) > 100:
|
|
|
await message.answer("Описание слишком длинное")
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
- # await message.delete()
|
|
|
+
|
|
|
else:
|
|
|
await state.update_data(description=message.text)
|
|
|
await state.update_data(approved=0)
|
|
@@ -136,19 +141,24 @@ async def send_event(message: types.Message, state: FSMContext):
|
|
|
"они получат оповощение автоматически", reply_markup=main_kb)
|
|
|
await state.finish()
|
|
|
db.sql_query_send(sql.sql_send_event(data))
|
|
|
- # await asyncio.sleep(5)
|
|
|
- # await msg.delete()
|
|
|
- await new_event()
|
|
|
|
|
|
|
|
|
async def next_month(call: types.CallbackQuery):
|
|
|
- m_id = int(call.data.split(":")[1]) + 1
|
|
|
- month = datetime.date.today().month
|
|
|
- month = month-m_id
|
|
|
- days_in_month = calendar.monthrange(2022, month-1)[1]
|
|
|
- print(month)
|
|
|
- await call.message.edit_reply_markup(reply_markup=make_calendar(month, days_in_month,
|
|
|
- f"month_prev:{m_id}", f"month_next:{m_id}"))
|
|
|
+ m_id = int(call.data.split(":")[1])+1
|
|
|
+ days = calendar.monthrange(2022, m_id)[1]
|
|
|
+ await call.message.edit_reply_markup(reply_markup=make_calendar(m_id,
|
|
|
+ days,
|
|
|
+ f"month_prev:{m_id}",
|
|
|
+ f"month_next:{m_id}"))
|
|
|
+
|
|
|
+
|
|
|
+async def prev_month(call: types.CallbackQuery):
|
|
|
+ m_id = int(call.data.split(":")[1])-1
|
|
|
+ days = calendar.monthrange(2022, m_id)[1]
|
|
|
+ await call.message.edit_reply_markup(reply_markup=make_calendar(m_id,
|
|
|
+ days,
|
|
|
+ f"month_prev:{m_id}",
|
|
|
+ f"month_next:{m_id}"))
|
|
|
|
|
|
|
|
|
def events_register(dp: Dispatcher):
|
|
@@ -161,3 +171,4 @@ def events_register(dp: Dispatcher):
|
|
|
dp.register_message_handler(get_time, state=BookingState.time)
|
|
|
dp.register_message_handler(send_event, state=BookingState.description)
|
|
|
dp.register_callback_query_handler(next_month, text_startswith='month_next')
|
|
|
+ dp.register_callback_query_handler(prev_month, text_startswith='month_prev')
|