}
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;
->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();
}
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':
--- /dev/null
+<?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);
+ });
+ });
+ }
+
+}
$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);
return $this->belongsTo(Event::class);
}
+ public function guildEpisodes() {
+ return $this->hasMany(DiscordGuildEpisode::class);
+ }
+
public function players() {
return $this->hasMany(EpisodePlayer::class);
}
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',