new notify

This commit is contained in:
Administrator
2023-03-30 00:53:29 +03:00
parent 7b28762c14
commit b11574c188
5 changed files with 104 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ from daemons.bot import bot
from daemons.fetch import fetch_schedule_for_user
from helpers import get_next_daily_notify_time
from helpers.keyboards import main_keyboard, notify_keyboard, yes_no_keyboard, again_keyboard, groups_keyboard, \
no_daily_notify, student_or_teacher_keyboard, campus_keyboard, daily_notify_type
no_daily_notify, student_or_teacher_keyboard, campus_keyboard, daily_notify_type, notify_type, first_lesson_notify
from helpers.models import UserSchema, User
from helpers.mongo import mongo
from helpers.ruz import ruz
@@ -188,10 +188,10 @@ class Answer(BaseAnswer):
elif message.text == "Уведомления о парах":
bot.send_message(
user.chat_id,
"Выбери за сколько минут мне нужно напомнить тебе о предстоящей паре",
reply_markup=notify_keyboard()
"Я умею уведомлять о каждой паре и о первой паре. Что хочешь настроить?",
reply_markup=notify_type()
)
self.set_state(user, "wait_for_notify")
self.set_state(user, "notify_type")
return
elif message.text == "Ежедневные уведомления":
bot.send_message(
@@ -213,6 +213,51 @@ class Answer(BaseAnswer):
reply_markup=main_keyboard()
)
def handle_state_notify_type(self, message: Message, user: User):
text = message.text
if text == "О каждой паре":
bot.send_message(
user.chat_id,
"Выбери за сколько минут мне нужно напомнить тебе о предстоящей паре",
reply_markup=notify_keyboard()
)
self.set_state(user, "wait_for_notify")
elif text == "О первой паре":
bot.send_message(
user.chat_id,
"Выбери за сколько минут мне нужно напоминать тебе о первой паре",
reply_markup=first_lesson_notify()
)
self.set_state(user, "wait_for_first_notify")
elif text == "Назад":
self.set_state(user, "ready")
bot.send_message(
user.chat_id,
text,
reply_markup=main_keyboard()
)
else:
bot.send_message(user.chat_id, "Используй кнопки!", reply_markup=notify_type())
def handle_state_wait_for_first_notify(self, message: Message, user: User):
text = message.text
if text == "30 минут":
time_notify = 30
elif text == "1 час":
time_notify = 60
elif text == "4 часа":
time_notify = 4 * 60
elif text == "12 часов":
time_notify = 12 * 60
elif text == "Не уведомлять":
time_notify = None
else:
bot.send_message(user.chat_id, "Используй кнопки!", reply_markup=first_lesson_notify())
return
mongo.users_collection.update_one({"chat_id": user.chat_id}, {"$set": {"first_lesson_notify": time_notify}})
self.set_state(user, "ready")
bot.send_message(user.chat_id, "Запомнил!", reply_markup=main_keyboard())
def handle_state_wait_for_daily_notify_type(self, message: Message, user: User):
text = message.text
if text == "Текущий день":

View File

@@ -70,3 +70,21 @@ def daily_notify_type():
kb.row("Следующий день")
kb.row("Не уведомлять")
return kb
def notify_type():
kb = telebot.types.ReplyKeyboardMarkup(True, False)
kb.row("О каждой паре")
kb.row("О первой паре")
kb.row("Назад")
return kb
def first_lesson_notify():
kb = telebot.types.ReplyKeyboardMarkup(True, False)
kb.row("30 минут")
kb.row("1 час")
kb.row("4 часа")
kb.row("12 часов")
kb.row("Не уведомлять")
return kb

View File

@@ -19,6 +19,7 @@ class User:
is_teacher: bool = False
campus: str = "Москва"
daily_notify_today: bool = True
first_lesson_notify: Optional[float] = None
class Meta:
unknown = EXCLUDE