diff --git a/bot/pydici_bot.py b/bot/pydici_bot.py index 6947362b..994a4467 100755 --- a/bot/pydici_bot.py +++ b/bot/pydici_bot.py @@ -56,7 +56,7 @@ async def alert_consultant(context): """Randomly alert consultant about important stuff to do""" - if outside_business_hours(): + if await outside_business_hours(): return consultants = await get_consultants() @@ -89,7 +89,7 @@ async def alert_consultant(context): async def call_for_timesheet(context): """If needed, remind people to declare timesheet of current day""" - if outside_business_hours(): + if await outside_business_hours(): return msg = _("""Hope the day was fine. Time to declare your timesheet no? Just click /time""") diff --git a/bot/utils.py b/bot/utils.py index 7276a656..146df20f 100644 --- a/bot/utils.py +++ b/bot/utils.py @@ -44,11 +44,12 @@ async def check_user_is_declared(update, context): return None +@db_sync_to_async def outside_business_hours(): """Don't bother people outside business hours""" now = datetime.now() today = date.today() - holiday_today = Holiday.objects.filter(day__contains=today) + holiday_today = Holiday.objects.filter(day=today) return now.weekday() in (5, 6) or now.hour < 9 or now.hour > 19 or holiday_today.count() > 0