X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=4ffbe119f440dbf5d308d05283025cb9557bec57;hb=d566d913c251fbb05e6bd314cc51f8b5ca49fe57;hp=a049eba3bacd4327ee46df2beb5f53b173e1f912;hpb=a058ba02c473649714add36edd021faab7a96e4c;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index a049eba..4ffbe11 100644 --- a/app/Console/Commands/DiscordBotCommand.php +++ b/app/Console/Commands/DiscordBotCommand.php @@ -2,10 +2,14 @@ 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; @@ -42,10 +46,60 @@ class DiscordBotCommand extends Command 'token' => config('discord.token'), ]); $discord->on(Event::GUILD_CREATE, function (Guild $guild, Discord $discord) { - DiscordGuild::sync($guild); + 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) { - DiscordGuild::sync($guild); + $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->on('ready', function (Discord $discord) { $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {