X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=066f5ff51920027f5b0f72b1bb609532d5bb484e;hb=3caf693c776de3293ec3cb86e19ddebdf9891368;hp=7d51cb9df4868ec0bc76fcfc22c13d28a66606a0;hpb=4622c1d4e89a5feac97fc19a62a2051a8484d364;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index 7d51cb9..066f5ff 100644 --- a/app/Console/Commands/DiscordBotCommand.php +++ b/app/Console/Commands/DiscordBotCommand.php @@ -2,7 +2,15 @@ namespace App\Console\Commands; +use App\Models\DiscordChannel; +use App\Models\DiscordGuild; +use App\Models\DiscordRole; use Discord\Discord; +use Discord\Parts\Channel\Channel; +use Discord\Parts\Channel\Message; +use Discord\Parts\Guild\Guild; +use Discord\Parts\Guild\Role; +use Discord\WebSockets\Event; use Illuminate\Console\Command; use Monolog\Handler\StreamHandler; use Monolog\Logger; @@ -37,7 +45,61 @@ class DiscordBotCommand extends Command 'logger' => $logger, 'token' => config('discord.token'), ]); - $discord->on('ready', function (Discord $discord) { + $discord->on(Event::GUILD_CREATE, function (Guild $guild, Discord $discord) { + try { + DiscordGuild::onUpstreamCreate($guild); + } catch (\Exception $e) { + $this->error('guild create: '.$e->getMessage()); + } + }); + $discord->on(Event::GUILD_UPDATE, function (Guild $guild, Discord $discord, ?Guild $old) { + try { + DiscordGuild::onUpstreamUpdate($guild); + } catch (\Exception $e) { + $this->error('guild update: '.$e->getMessage()); + } + }); + $discord->on(Event::CHANNEL_CREATE, function (Channel $channel, Discord $discord) { + try { + DiscordGuild::onUpstreamCreate($channel); + } catch (\Exception $e) { + $this->error('channel create: '.$e->getMessage()); + } + }); + $discord->on(Event::CHANNEL_UPDATE, function (Channel $channel, Discord $discord, ?Channel $old) { + try { + DiscordGuild::onUpstreamUpdate($channel); + } catch (\Exception $e) { + $this->error('channel update: '.$e->getMessage()); + } + }); + $discord->on(Event::CHANNEL_DELETE, function ($channel, Discord $discord) { + try { + DiscordGuild::onUpstreamDelete($channel); + } catch (\Exception $e) { + $this->error('channel delete: '.$e->getMessage()); + } + }); + $discord->on(Event::GUILD_ROLE_CREATE, function (Role $role, Discord $discord) { + try { + DiscordRole::onUpstreamCreate($role); + } catch (\Exception $e) { + $this->error('guild role create: '.$e->getMessage()); + } + }); + $discord->on(Event::GUILD_ROLE_UPDATE, function (Role $role, Discord $discord, ?Role $old) { + try { + DiscordRole::onUpstreamUpdate($role); + } catch (\Exception $e) { + $this->error('guild role update: '.$e->getMessage()); + } + }); + $discord->on(Event::GUILD_ROLE_DELETE, function ($role, Discord $discord) { + try { + DiscordRole::onUpstreamDelete($role); + } catch (\Exception $e) { + $this->error('guild role delete: '.$e->getMessage()); + } }); $discord->getLoop()->addSignal(SIGINT, function() use ($discord) { $discord->close();