tomorrow notify
This commit is contained in:
parent
09012e4d15
commit
01fcf640c2
@ -36,16 +36,20 @@ def process():
|
|||||||
time_now = datetime.datetime.now()
|
time_now = datetime.datetime.now()
|
||||||
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
|
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
|
||||||
user_model = UserSchema().load(user)
|
user_model = UserSchema().load(user)
|
||||||
if time_now.weekday() != 6:
|
deny_weekday = 6 if user_model.daily_notify_today else 5
|
||||||
lessons = mongo.get_today_lessons(user_model)
|
if time_now.weekday() != deny_weekday:
|
||||||
|
if user_model.daily_notify_today:
|
||||||
|
lessons = mongo.get_today_lessons(user_model)
|
||||||
|
else:
|
||||||
|
lessons = mongo.get_tomorrow_lessons(user_model)
|
||||||
if len(lessons) == 0:
|
if len(lessons) == 0:
|
||||||
text = "Сегодня у тебя нет пар, отдыхай."
|
text = f"{'Сегодня' if user_model.daily_notify_today else 'Завтра'} у тебя нет пар, отдыхай."
|
||||||
else:
|
else:
|
||||||
text = ruz.schedule_builder(lessons)
|
text = ruz.schedule_builder(lessons)
|
||||||
try:
|
try:
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
user["chat_id"],
|
user["chat_id"],
|
||||||
"Уведомляю о занятиях! Твое расписание на сегодня:\n" + text
|
f"Уведомляю о занятиях! Твое расписание на {'сегодня' if user_model.daily_notify_today else 'завтра'}:\n" + text
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -4,7 +4,7 @@ from daemons.bot import bot
|
|||||||
from daemons.fetch import fetch_schedule_for_user
|
from daemons.fetch import fetch_schedule_for_user
|
||||||
from helpers import get_next_daily_notify_time
|
from helpers import get_next_daily_notify_time
|
||||||
from helpers.keyboards import main_keyboard, notify_keyboard, yes_no_keyboard, again_keyboard, groups_keyboard, \
|
from helpers.keyboards import main_keyboard, notify_keyboard, yes_no_keyboard, again_keyboard, groups_keyboard, \
|
||||||
no_daily_notify, student_or_teacher_keyboard, campus_keyboard
|
no_daily_notify, student_or_teacher_keyboard, campus_keyboard, daily_notify_type
|
||||||
from helpers.models import UserSchema, User
|
from helpers.models import UserSchema, User
|
||||||
from helpers.mongo import mongo
|
from helpers.mongo import mongo
|
||||||
from helpers.ruz import ruz
|
from helpers.ruz import ruz
|
||||||
@ -196,10 +196,10 @@ class Answer(BaseAnswer):
|
|||||||
elif message.text == "Ежедневные уведомления":
|
elif message.text == "Ежедневные уведомления":
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
user.chat_id,
|
user.chat_id,
|
||||||
"Каждый день (кроме воскресенья) я буду присылать тебе расписание на день. Пришли мне в формате чч:мм время, в которое ты хочешь получать расписание. Например, 09:30",
|
"Я могу присылать тебе расписание на текущий день или на следующий. Как ты хочешь чтобы я тебя уведомлял?",
|
||||||
reply_markup=no_daily_notify()
|
reply_markup=daily_notify_type()
|
||||||
)
|
)
|
||||||
self.set_state(user, "wait_for_daily_notify")
|
self.set_state(user, "wait_for_daily_notify_type")
|
||||||
return
|
return
|
||||||
elif message.text == "Сброс настроек":
|
elif message.text == "Сброс настроек":
|
||||||
bot.send_message(user.chat_id, "Ты уверен что хочешь сбросить все настройки и больше не получать уведомления?", reply_markup=yes_no_keyboard())
|
bot.send_message(user.chat_id, "Ты уверен что хочешь сбросить все настройки и больше не получать уведомления?", reply_markup=yes_no_keyboard())
|
||||||
@ -213,6 +213,45 @@ class Answer(BaseAnswer):
|
|||||||
reply_markup=main_keyboard()
|
reply_markup=main_keyboard()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def handle_state_wait_for_daily_notify_type(self, message: Message, user: User):
|
||||||
|
text = message.text
|
||||||
|
if text == "Текущий день":
|
||||||
|
bot.send_message(
|
||||||
|
user.chat_id,
|
||||||
|
"Каждый день (кроме воскресенья) я буду присылать тебе расписание на текущий день. Пришли мне в формате чч:мм время, в которое ты хочешь получать расписание. Например, 09:30",
|
||||||
|
reply_markup=no_daily_notify()
|
||||||
|
)
|
||||||
|
mongo.users_collection.update_one(
|
||||||
|
{"chat_id": user.chat_id},
|
||||||
|
{"$set": {"daily_notify_today": True, "state": "wait_for_daily_notify"}}
|
||||||
|
)
|
||||||
|
elif text == "Следующий день":
|
||||||
|
bot.send_message(
|
||||||
|
user.chat_id,
|
||||||
|
"Каждый день (кроме субботы) я буду присылать тебе расписание на следующий день. Пришли мне в формате чч:мм время, в которое ты хочешь получать расписание. Например, 20:30",
|
||||||
|
reply_markup=no_daily_notify()
|
||||||
|
)
|
||||||
|
mongo.users_collection.update_one(
|
||||||
|
{"chat_id": user.chat_id},
|
||||||
|
{"$set": {"daily_notify_today": False, "state": "wait_for_daily_notify"}}
|
||||||
|
)
|
||||||
|
elif text == "Не уведомлять":
|
||||||
|
bot.send_message(
|
||||||
|
user.chat_id,
|
||||||
|
"Принято! Я не уведомлять тебя.",
|
||||||
|
reply_markup=main_keyboard()
|
||||||
|
)
|
||||||
|
mongo.users_collection.update_one(
|
||||||
|
{"chat_id": user.chat_id},
|
||||||
|
{"$set": {"next_daily_notify_time": None, "daily_notify_time": None, "state": "ready"}}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
bot.send_message(
|
||||||
|
user.chat_id,
|
||||||
|
"Ты прислал мне что-то неправильное, используй кнопки. Как ты хочешь чтобы я тебя уведомлял?",
|
||||||
|
reply_markup=daily_notify_type()
|
||||||
|
)
|
||||||
|
|
||||||
def handle_state_wait_for_notify(self, message: Message, user: User):
|
def handle_state_wait_for_notify(self, message: Message, user: User):
|
||||||
text = message.text
|
text = message.text
|
||||||
if text == "Не уведомлять":
|
if text == "Не уведомлять":
|
||||||
@ -258,16 +297,15 @@ class Answer(BaseAnswer):
|
|||||||
def handle_state_wait_for_daily_notify(self, message: Message, user: User):
|
def handle_state_wait_for_daily_notify(self, message: Message, user: User):
|
||||||
text = message.text
|
text = message.text
|
||||||
if text == "Не уведомлять":
|
if text == "Не уведомлять":
|
||||||
mongo.users_collection.update_one(
|
|
||||||
{"chat_id": user.chat_id},
|
|
||||||
{"$set": {"daily_notify_time": None, "next_daily_notify_time": None}}
|
|
||||||
)
|
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
user.chat_id,
|
user.chat_id,
|
||||||
"Принято! Я не буду присылать тебе ежедневные уведомления.",
|
"Принято! Я не буду присылать тебе ежедневные уведомления.",
|
||||||
reply_markup=main_keyboard()
|
reply_markup=main_keyboard()
|
||||||
)
|
)
|
||||||
self.set_state(user, "ready")
|
mongo.users_collection.update_one(
|
||||||
|
{"chat_id": user.chat_id},
|
||||||
|
{"$set": {"daily_notify_time": None, "next_daily_notify_time": None, "state": "ready"}}
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if not self._validate_time(text):
|
if not self._validate_time(text):
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
|
@ -62,3 +62,11 @@ def no_daily_notify():
|
|||||||
kb = telebot.types.ReplyKeyboardMarkup(True, False)
|
kb = telebot.types.ReplyKeyboardMarkup(True, False)
|
||||||
kb.row("Не уведомлять")
|
kb.row("Не уведомлять")
|
||||||
return kb
|
return kb
|
||||||
|
|
||||||
|
|
||||||
|
def daily_notify_type():
|
||||||
|
kb = telebot.types.ReplyKeyboardMarkup(True, False)
|
||||||
|
kb.row("Текущий день")
|
||||||
|
kb.row("Следующий день")
|
||||||
|
kb.row("Не уведомлять")
|
||||||
|
return kb
|
||||||
|
@ -18,6 +18,7 @@ class User:
|
|||||||
next_daily_notify_time: Optional[datetime.datetime] = None
|
next_daily_notify_time: Optional[datetime.datetime] = None
|
||||||
is_teacher: bool = False
|
is_teacher: bool = False
|
||||||
campus: str = "Москва"
|
campus: str = "Москва"
|
||||||
|
daily_notify_today: bool = True
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unknown = EXCLUDE
|
unknown = EXCLUDE
|
||||||
|
Loading…
Reference in New Issue
Block a user