Skip to content

Commit

Permalink
birthday tweak
Browse files Browse the repository at this point in the history
events work with new site
updated reminder timezones
  • Loading branch information
Mole1424 committed Sep 20, 2023
1 parent 3d5cc25 commit a7a4c12
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cogs/commands/birthday.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def wish(self, ctx: Context):
except (SQLAlchemyError, OperationalError):
pass
await ctx.reply(
f"Happy birthday <@{CONFIG.LORD_CHANCELLOR_ID}>!!!!! {f' You are now {self.age} years old' if first else ''}"
f"Happy birthday <@{CONFIG.LORD_CHANCELLOR_ID}>!!!!! <:ferris_party:1016463393156247623> {f' You are now {self.age} years old' if first else ''}"
)

@birthday.command(help=LONG_HELP_TEXT, brief="Lord Chancellor age")
Expand Down
2 changes: 1 addition & 1 deletion cogs/commands/event_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

SHORT_HELP_TEXT = """Sync events"""

ICAL_URL = "https://uwcs.co.uk/signups/feed.ics"
ICAL_URL = "https://uwcs.co.uk/uwcs.ical"


class Sync(commands.Cog):
Expand Down
3 changes: 2 additions & 1 deletion cogs/commands/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from discord.ext import commands
from discord.ext.commands import Bot, Context
from humanize import precisedelta
from pytz import timezone, utc
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy_utils import ScalarListException

Expand Down Expand Up @@ -87,7 +88,7 @@ async def add(self, ctx: Context, when: str, *, reminder_content: str):
await ctx.send(**result)

def add_base(self, reminder):
now = datetime.now()
now = utc.localize(datetime.now()).astimezone(timezone("Europe/London"))
if not reminder.trigger_at:
return {"content": "Incorrect time format, please see help text."}
elif reminder.trigger_at < now:
Expand Down
25 changes: 20 additions & 5 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dateparser
import discord
from discord.ext.commands import Bot, Context
from pytz import timezone, utc

from config import CONFIG
from models import db_session
Expand Down Expand Up @@ -118,10 +119,18 @@ def is_decimal(num: Any):
def parse_time(time: str, /):
# dateparser.parse returns None if it cannot parse
parsed_time = dateparser.parse(
time, settings={"DATE_ORDER": "DMY", "PREFER_DATES_FROM": "future"}
time,
settings={
"DATE_ORDER": "DMY",
"PREFER_DATES_FROM": "future",
},
)

now = datetime.now()
parsed_time = (
timezone("Europe/London").localize(parsed_time) if parsed_time else None
)

now = utc.localize(datetime.now()).astimezone(timezone("Europe/London"))

if not parsed_time:
try:
Expand Down Expand Up @@ -332,13 +341,19 @@ async def decorator(*args: P.args, **kwargs: P.kwargs):
)

if kwargs[key_name] not in first_run_times:
first_run_times[kwargs[key_name]] = datetime.now()
first_run_times[kwargs[key_name]] = utc.localize(
datetime.now()
).astimezone(timezone("Europe/London"))
return await ctx.reply(confirm_msg, ephemeral=True)

timeout_threshold = datetime.now() - timedelta(minutes=5)
timeout_threshold = utc.localize(datetime.now()).astimezone(
timezone("Europe/London")
) - timedelta(minutes=5)
if timeout_threshold > first_run_times[kwargs[key_name]]:
# If previous run is more than 5 mins ago (timeout after 5)
first_run_times[kwargs[key_name]] = datetime.now()
first_run_times[kwargs[key_name]] = utc.localize(
datetime.now()
).astimezone(timezone("Europe/London"))
return await ctx.reply(confirm_msg, ephemeral=True)

await func(*args, **kwargs)
Expand Down

0 comments on commit a7a4c12

Please sign in to comment.