]> git.localhorst.tv Git - alttp.git/commitdiff
call off canceled episodes
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 11 Jul 2025 14:44:58 +0000 (16:44 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 11 Jul 2025 14:44:58 +0000 (16:44 +0200)
app/Console/Commands/SyncCoopZossy.php
app/Console/Commands/SyncSpeedGaming.php
app/DiscordBotCommands/BaseCommand.php
app/DiscordBotCommands/CancelEventCommand.php [new file with mode: 0644]
app/Models/DiscordBotCommand.php
app/Models/Episode.php

index f4b9a4058e58b17674598265a53d0320a856e334..c9dea91ebfd9cd48c42043acd35d9cb9031a9b81 100644 (file)
@@ -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;
index 1d440201ae24397e56881895583fa7c0c675c6f2..2175d737f50d2cba7634cb1644f6ee7e89388d2c 100644 (file)
@@ -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();
        }
index 259176d51b0e2848fad03df3d58798fd3cbfcfa7..5e1c5e6ef48be5f144b3a49616bf925f3695a02d 100644 (file)
@@ -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 (file)
index 0000000..079fc01
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace App\DiscordBotCommands;
+
+use App\Models\DiscordBotCommand;
+use Discord\Discord;
+use Discord\Parts\Guild\Guild;
+use React\Promise\PromiseInterface;
+
+class CancelEventCommand extends BaseCommand {
+
+       public function __construct(Discord $discord, DiscordBotCommand $cmd) {
+               parent::__construct($discord, $cmd);
+       }
+
+       public function execute(): PromiseInterface {
+               if (!$this->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);
+                                       });
+                       });
+       }
+
+}
index ef3f5ea5b9e06cad2b6b64fc7dfea97325a06a50..aa549379a163f4d7f3af61982db90ba5f208878b 100644 (file)
@@ -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);
index fd68cd6c86d0f480a1dc3dccf5d2a22c2e672739..4eb8a57e2442e4c0c2bb46fd83943d169688fb58 100644 (file)
@@ -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',