diff --git a/src/cogs/social_credit.py b/src/cogs/social_credit.py index 5b9d2f6..5028e6e 100644 --- a/src/cogs/social_credit.py +++ b/src/cogs/social_credit.py @@ -316,7 +316,7 @@ class SocialCredit(commands.Cog): illegal_hours = [5, 6, 7, 8, 9] - if message.created_at.hour in illegal_hours: + if message.created_at.astimezone(self.bot.timezone).hour in illegal_hours: await self.social_punishment(message.author.id, 10, "early-bird") @roll(percent=50) @@ -331,7 +331,7 @@ class SocialCredit(commands.Cog): happy_hours = [1, 2, 3, 4] - if message.created_at.hour in happy_hours: + if message.created_at.astimezone(self.bot.timezone).hour in happy_hours: await self.social_reward(message.author.id, 10, "night-owl") async def robort_slur(self, message: discord.Message): diff --git a/src/config/config.yaml.example b/src/config/config.yaml.example index d960dae..9b3d3e8 100644 --- a/src/config/config.yaml.example +++ b/src/config/config.yaml.example @@ -2,6 +2,9 @@ config_mode: dev dev_guild: 747542543750660178 +# IANA timezone name. Leave empty to use the system's timezone +timezone: Europe/Oslo + # Bot settings bot: token: diff --git a/src/run.py b/src/run.py index 2f250ca..6dadfad 100644 --- a/src/run.py +++ b/src/run.py @@ -2,6 +2,7 @@ import asyncio import signal from os import listdir from time import time +from zoneinfo import ZoneInfo import discord import psycopg2 @@ -72,6 +73,7 @@ class Bot(commands.Bot): self.presence = config["bot"].get("presence", {}) self.emoji = config.get("emoji", {}) self.misc = config.get("misc", {}) + self.timezone = ZoneInfo(tz) if (tz := config.get("timezone")) else None # None means the system timezone async def setup_hook(self): # Docker stops the container with SIGTERM. Close gracefully so cogs can save their caches