Add cadence argument to the /schedule command
This allows setting the cadence, or changing it. When changing the initial start time will be reset
This commit is contained in:
parent
b86aaf7016
commit
e9cccefacb
2 changed files with 17 additions and 8 deletions
|
@ -110,7 +110,8 @@ class MatcherCog(commands.Cog):
|
|||
interaction: discord.Interaction,
|
||||
members_min: int | None = None,
|
||||
weekday: int | None = None,
|
||||
hour: int | None = None):
|
||||
hour: int | None = None,
|
||||
cadence: int | None = None):
|
||||
"""Schedule a match using the input parameters"""
|
||||
|
||||
# Set all the defaults
|
||||
|
@ -120,6 +121,8 @@ class MatcherCog(commands.Cog):
|
|||
weekday = 0
|
||||
if hour is None:
|
||||
hour = 9
|
||||
if cadence is None:
|
||||
cadence = 1
|
||||
channel_id = str(interaction.channel.id)
|
||||
|
||||
# Bail if not a matcher
|
||||
|
@ -130,11 +133,11 @@ class MatcherCog(commands.Cog):
|
|||
|
||||
# Add the scheduled task and save
|
||||
state.State.set_channel_match_task(
|
||||
channel_id, members_min, weekday, hour)
|
||||
channel_id, members_min, weekday, hour, cadence)
|
||||
|
||||
# Let the user know what happened
|
||||
logger.info("Scheduled new match task in %s with min %s weekday %s hour %s",
|
||||
channel_id, members_min, weekday, hour)
|
||||
logger.info("Scheduled new match task in %s with min %s weekday %s hour %s and cadence %s",
|
||||
channel_id, members_min, weekday, hour, cadence)
|
||||
next_run = util.get_next_datetime(weekday, hour)
|
||||
|
||||
view = discord.ui.View(timeout=None)
|
||||
|
|
|
@ -72,7 +72,7 @@ def _migrate_to_v5(d: dict):
|
|||
for match in match_tasks:
|
||||
# All previous matches were every week starting from now
|
||||
match[_Key.CADENCE] = 1
|
||||
match[_Key.CADENCE_START] = int(datetime.now().timestamp())
|
||||
match[_Key.CADENCE_START] = datetime_to_ts(datetime.now())
|
||||
|
||||
|
||||
# Set of migration functions to apply
|
||||
|
@ -107,7 +107,7 @@ class _Key(str):
|
|||
WEEKDAY = "weekdays"
|
||||
HOUR = "hours"
|
||||
CADENCE = "cadence"
|
||||
CADENCE_START = "CADENCE_START"
|
||||
CADENCE_START = "cadence_start"
|
||||
|
||||
# Unused
|
||||
_MATCHEES = "matchees"
|
||||
|
@ -154,7 +154,7 @@ _SCHEMA = Schema(
|
|||
_Key.WEEKDAY: Use(int),
|
||||
_Key.HOUR: Use(int),
|
||||
_Key.CADENCE: Use(int),
|
||||
_Key.CADENCE_START: Use(int),
|
||||
_Key.CADENCE_START: Use(str),
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ class _State():
|
|||
yield (task[_Key.WEEKDAY], task[_Key.HOUR], task[_Key.MEMBERS_MIN])
|
||||
|
||||
@safe_write
|
||||
def set_channel_match_task(self, channel_id: str, members_min: int, weekday: int, hour: int):
|
||||
def set_channel_match_task(self, channel_id: str, members_min: int, weekday: int, hour: int, cadence: int):
|
||||
"""Set up a match task on a channel"""
|
||||
channel = self._tasks.setdefault(str(channel_id), {})
|
||||
matches = channel.setdefault(_Key.MATCH_TASKS, [])
|
||||
|
@ -368,6 +368,10 @@ class _State():
|
|||
if match[_Key.WEEKDAY] == weekday and match[_Key.HOUR] == hour:
|
||||
found = True
|
||||
match[_Key.MEMBERS_MIN] = members_min
|
||||
# If the cadence has changed, update it and reset the start
|
||||
if cadence != match[_Key.CADENCE]:
|
||||
match[_Key.CADENCE] = cadence
|
||||
match[_Key.CADENCE_START] = datetime_to_ts(datetime.now())
|
||||
# Return true as we've successfully changed the data in place
|
||||
return True
|
||||
|
||||
|
@ -377,6 +381,8 @@ class _State():
|
|||
_Key.MEMBERS_MIN: members_min,
|
||||
_Key.WEEKDAY: weekday,
|
||||
_Key.HOUR: hour,
|
||||
_Key.CADENCE: cadence,
|
||||
_Key.CADENCE_START: datetime_to_ts(datetime.now())
|
||||
})
|
||||
|
||||
@safe_write
|
||||
|
|
Loading…
Add table
Reference in a new issue