mirror of
https://github.com/UiO-Gaming/mustafa.git
synced 2026-11-05 13:56:48 +01:00
use bot timezone for midnight loops
This commit is contained in:
2 files changed
+11
-2
No files matched your search
@@ -3,7 +3,6 @@ import datetime
|
||||
import functools
|
||||
import textwrap
|
||||
from math import ceil
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import aiohttp
|
||||
import cv2
|
||||
@@ -13,7 +12,8 @@ from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
from PIL import ImageFont
|
||||
|
||||
MIDNIGHT = datetime.time(hour=0, minute=0, tzinfo=ZoneInfo("Europe/Oslo"))
|
||||
# Midnight in the bot's time zone. run.py sets it before loading the cogs
|
||||
MIDNIGHT = datetime.time(tzinfo=datetime.UTC)
|
||||
|
||||
|
||||
def localize(dt: datetime.datetime, tz: datetime.tzinfo | None) -> datetime.datetime:
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import signal
|
||||
from os import environ
|
||||
from os import listdir
|
||||
from os.path import realpath
|
||||
from time import time
|
||||
from zoneinfo import ZoneInfo
|
||||
from zoneinfo import ZoneInfoNotFoundError
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
@@ -12,6 +14,7 @@ import yaml
|
||||
from discord.ext import commands
|
||||
from psycopg_pool import AsyncConnectionPool
|
||||
|
||||
from cogs.utils import misc_utils
|
||||
from cogs.utils.database import Database
|
||||
from logger import BotLogger
|
||||
|
||||
@@ -92,6 +95,12 @@ class Bot(commands.Bot):
|
||||
self.timezone = ZoneInfo(tz) if (tz := config.get("timezone")) else None # None means the system timezone
|
||||
self.timezone_name = tz or self.system_timezone_name()
|
||||
|
||||
try:
|
||||
midnight_tz = self.timezone or ZoneInfo(self.timezone_name)
|
||||
except (TypeError, ValueError, ZoneInfoNotFoundError):
|
||||
midnight_tz = datetime.UTC
|
||||
misc_utils.MIDNIGHT = datetime.time(tzinfo=midnight_tz)
|
||||
|
||||
async def setup_hook(self):
|
||||
self.http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=15))
|
||||
if self.db_pool:
|
||||
|
||||
Reference in new issue
Block a user