countdown-bot

A Discord bot that runs countdown games and generates analytics
git clone https://git.ashermorgan.net/countdown-bot/
Log | Files | Refs | README

commit 9cde31ea3e2e592fbddd9d36534c04ab537240fc
parent 144eaee28c0b30f3d5023ed7fbf16fd6a9faee05
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat, 27 Apr 2024 19:19:44 -0700

Fix timezones for negative UTC offsets, again

Diffstat:
Mcountdown_bot/coreCog.py | 11+++++------
Mmodels/dml-core.sql | 8++++----
2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/countdown_bot/coreCog.py b/countdown_bot/coreCog.py @@ -91,7 +91,7 @@ class Core(commands.Cog): embed.description += f"**Command Prefixes:** `{'`, `'.join(prefixes)}`\n" cur.execute("CALL getTimezone(%s, null);", (countdown,)) - timezone = cur.fetchone()["_timezone"].total_seconds() / 3600 + timezone = cur.fetchone()["_timezone"] if (timezone >= 0): embed.description += f"**Countdown Timezone:** UTC+{timezone:.2f}\n" else: @@ -114,16 +114,15 @@ class Core(commands.Cog): raise CommandError("Please provide a value for the setting") elif (key in ["tz", "timezone"]): try: - offset = float(args[0]) - timezone = timedelta(hours = offset) + timezone = float(args[0]) except: raise CommandError(f"Invalid timezone: `{args[0]}`") else: cur.execute("CALL setTimezone(%s, %s);", (countdown, timezone)) - if (offset >= 0): - embed.description = f"Timezone set to UTC+{offset:.2f}\n" + if (timezone >= 0): + embed.description = f"Timezone set to UTC+{timezone:.2f}\n" else: - embed.description = f"Timezone set to UTC-{abs(offset):.2f}\n" + embed.description = f"Timezone set to UTC-{abs(timezone):.2f}\n" elif (key in ["prefix", "prefixes"]): cur.execute("CALL setPrefixes(%s, %s);", (countdown, list(args))) embed.description = f"Prefixes updated" diff --git a/models/dml-core.sql b/models/dml-core.sql @@ -207,11 +207,11 @@ $$; -- Get the timezone of a countdown CREATE PROCEDURE getTimezone ( _countdownID IN BIGINT, -- The countdown channel ID - _timezone OUT INTERVAL -- The timezone as a UTC offest + _timezone OUT FLOAT -- The timezone as a UTC offest ) LANGUAGE plpgsql AS $$ BEGIN - SELECT timezone + SELECT extract(hour FROM timezone) + extract(minute FROM timezone) / 60 INTO _timezone FROM countdowns WHERE countdownID = _countdownID; @@ -221,12 +221,12 @@ $$; -- Set the timezone of a countdown CREATE PROCEDURE setTimezone ( _countdownID IN BIGINT, -- The countdown channel ID - _timezone IN INTERVAL -- The timezone as a UTC offest + _timezone IN FLOAT -- The timezone as a UTC offest ) LANGUAGE plpgsql AS $$ BEGIN UPDATE countdowns - SET timezone = _timezone + SET timezone = make_interval(mins => (_timezone * 60)::integer) WHERE countdownID = _countdownID; END $$;