From: Daniel Karbach Date: Fri, 11 Jul 2025 14:44:58 +0000 (+0200) Subject: call off canceled episodes X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=949ce5002ff2fa93f72962b3a92d5fc1c8f95b78;p=alttp.git call off canceled episodes --- diff --git a/app/Console/Commands/SyncCoopZossy.php b/app/Console/Commands/SyncCoopZossy.php index f4b9a40..c9dea91 100644 --- a/app/Console/Commands/SyncCoopZossy.php +++ b/app/Console/Commands/SyncCoopZossy.php @@ -80,11 +80,19 @@ class SyncCoopZossy extends Command { } private function syncSchedule(Event $event, $row) { - if (empty($row[3]) || $row[3] == 'TBD') { + if (empty($row[3])) { return; } $ext_id = 'coop-zossy:'.$event->id.':'.$row[0]; $episode = Episode::firstWhere('ext_id', '=', $ext_id); + if ($row[3] == 'TBD') { + if ($episode) { + $this->line('calling off'.$row[0]); + $episode->callOff(); + $episode->delete(); + } + return; + } if (!$episode) { $episode = new Episode(); $episode->ext_id = $ext_id; diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index 1d44020..2175d73 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -88,9 +88,7 @@ class SyncSpeedGaming extends Command { ->whereNotIn('ext_id', $ext_ids) ->where('ext_id', 'LIKE', 'sg:%'); foreach ($to_purge->get() as $episode) { - $episode->channels()->detach(); - $episode->crew()->delete(); - $episode->players()->delete(); + $episode->callOff(); } $to_purge->delete(); } diff --git a/app/DiscordBotCommands/BaseCommand.php b/app/DiscordBotCommands/BaseCommand.php index 259176d..5e1c5e6 100644 --- a/app/DiscordBotCommands/BaseCommand.php +++ b/app/DiscordBotCommands/BaseCommand.php @@ -19,6 +19,8 @@ abstract class BaseCommand { public static function resolve(Discord $discord, DiscordBotCommand $cmd): BaseCommand { switch ($cmd->command) { + case 'cancel-event': + return new CancelEventCommand($discord, $cmd); case 'episode-event': return new EpisodeEventCommand($discord, $cmd); case 'message': diff --git a/app/DiscordBotCommands/CancelEventCommand.php b/app/DiscordBotCommands/CancelEventCommand.php new file mode 100644 index 0000000..079fc01 --- /dev/null +++ b/app/DiscordBotCommands/CancelEventCommand.php @@ -0,0 +1,31 @@ +hasParameter('event_id')) { + throw new \Exception('missing event_id parameter'); + } + return $this->fetchGuild() + ->then(function (Guild $guild) { + $event_id = $this->getParameter('event_id'); + return $guild->guild_scheduled_events + ->fetch($event_id) + ->then(function ($event) use ($guild) { + return $guild->guild_scheduled_events->delete($event); + }); + }); + } + +} diff --git a/app/Models/DiscordBotCommand.php b/app/Models/DiscordBotCommand.php index ef3f5ea..aa54937 100644 --- a/app/Models/DiscordBotCommand.php +++ b/app/Models/DiscordBotCommand.php @@ -26,6 +26,18 @@ class DiscordBotCommand extends Model { $this->load(['user']); } + public static function cancelEvent(DiscordGuild $guild, $event_id): DiscordBotCommand { + $cmd = new DiscordBotCommand(); + $cmd->discord_guild()->associate($guild); + $cmd->command = 'cancel-event'; + $cmd->parameters = [ + 'event_id' => $event_id, + ]; + $cmd->status = 'pending'; + $cmd->save(); + return $cmd; + } + public static function episodeEvent(DiscordGuild $guild, Episode $episode): DiscordBotCommand { $cmd = new DiscordBotCommand(); $cmd->discord_guild()->associate($guild); diff --git a/app/Models/Episode.php b/app/Models/Episode.php index fd68cd6..4eb8a57 100644 --- a/app/Models/Episode.php +++ b/app/Models/Episode.php @@ -32,6 +32,10 @@ class Episode extends Model return $this->belongsTo(Event::class); } + public function guildEpisodes() { + return $this->hasMany(DiscordGuildEpisode::class); + } + public function players() { return $this->hasMany(EpisodePlayer::class); } @@ -122,6 +126,18 @@ class Episode extends Model return ''; } + public function callOff(): void { + $this->channels()->detach(); + $this->crew()->delete(); + $this->players()->delete(); + foreach ($this->guildEpisodes as $ge) { + if ($ge->scheduled_event_id) { + DiscordBotCommand::cancelEvent($ge->discord_guild, $ge->scheduled_event_id); + } + } + $this->guildEpisodes()->delete(); + } + protected $casts = [ 'confirmed' => 'boolean', 'start' => 'datetime',