Skip to content

Commit

Permalink
fix code to properly be async compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed May 20, 2024
1 parent dfde9ec commit 6cbc369
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bot/pydici_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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""")

Expand Down
3 changes: 2 additions & 1 deletion bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6cbc369

Please sign in to comment.