Skip to content

Commit 5f541d9

Browse files
committed
ENHANCEMENTS:
- Scheduler can now handle presets on startup and action CHANGES: - Scheduler: local_times and utc_times migrated to times (auto-migration) - MizEdit: can work with timezones now
1 parent 5ab508f commit 5f541d9

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

plugins/mission/status.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,8 @@ async def render(self, server: Server):
207207
self.add_field(name="This server runs on the following schedule:", value='_ _', inline=False)
208208
value = ''
209209
now = datetime.now()
210-
tz = now.astimezone().tzinfo
210+
tz = ZoneInfo(config['timezone']) if 'timezone' in config else now.astimezone().tzinfo
211211
for period, daystate in config['schedule'].items():
212-
if period == 'timezone':
213-
tz = ZoneInfo(daystate)
214-
continue
215212
for c in daystate:
216213
if c == 'Y':
217214
value += '✅|'

plugins/scheduler/commands.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ async def check_server_state(server: Server, config: dict) -> Status:
140140
# ------------------------------------------------------------------
141141
now = datetime.now()
142142
tz = (
143-
ZoneInfo(config['schedule'].get('timezone'))
144-
if 'timezone' in config['schedule']
143+
ZoneInfo(config.get('timezone'))
144+
if 'timezone' in config
145145
else None
146146
)
147147

@@ -155,9 +155,6 @@ async def check_server_state(server: Server, config: dict) -> Status:
155155
# 3. Walk through the schedule periods
156156
# ------------------------------------------------------------------
157157
for period, daystate in config['schedule'].items():
158-
if period == 'timezone': # skip the optional tz key
159-
continue
160-
161158
# Validate that the daystate string is 7 characters long
162159
if len(daystate) != 7:
163160
server.log.error(
@@ -602,14 +599,7 @@ def _handle_times(server: Server, config: dict, rconf: dict, warn_time: int) ->
602599
"""
603600
if 'times' in rconf:
604601
option = 'times'
605-
tz = next(
606-
(
607-
v
608-
for k, v in config.get("schedule", {}).items()
609-
if k == "timezone"
610-
),
611-
None,
612-
)
602+
tz = config.get('timezone')
613603
elif 'local_times' in rconf:
614604
option = 'local_times'
615605
tz = None
@@ -685,15 +675,11 @@ def _handle_cron(server: Server, config: dict, rconf: dict, warn_time: int) -> i
685675
"""
686676
*cron* – evaluate the cron expression at the *restart_time* that would occur after *warn_time* seconds.
687677
"""
688-
tz = next(
689-
(
690-
v
691-
for k, v in config.get("schedule", {}).items()
692-
if k == "timezone"
693-
),
694-
None,
678+
tzinfo = (
679+
ZoneInfo(config.get('timezone'))
680+
if 'timezone' in config
681+
else None
695682
)
696-
tzinfo = ZoneInfo(tz) if tz else None
697683
restart_time = datetime.now(tz=tzinfo) + timedelta(seconds=warn_time)
698684
restart_time = restart_time.replace(second=0, microsecond=0)
699685

plugins/scheduler/listener.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import asyncio
2-
import os
3-
import random
42
from zoneinfo import ZoneInfo
53

64
from croniter import croniter
75

8-
from core import EventListener, utils, Server, Player, Status, event, chat_command
6+
from core import EventListener, utils, Server, Player, event, chat_command
97
from datetime import datetime, timedelta, timezone
108
from typing import TYPE_CHECKING
119

@@ -93,7 +91,7 @@ async def get_next_restart(self, server: Server, restart: dict | list) -> tuple[
9391
return None
9492
elif 'cron' in restart:
9593
now = datetime.now().replace(second=0, microsecond=0)
96-
tz = next((v for x, v in self.get_config(server).get('schedule', {}).items() if x == 'timezone'), None)
94+
tz = self.get_config(server).get('timezone')
9795
if tz:
9896
tzinfo = ZoneInfo(tz)
9997
now = now.replace(tzinfo=tzinfo)

0 commit comments

Comments
 (0)