X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=c0a92b885867161acc1ed350574a5b32de070972;hb=04eb1ab6316aba62b5cbf6f9b729782df1fe5015;hp=7d51cb9df4868ec0bc76fcfc22c13d28a66606a0;hpb=4622c1d4e89a5feac97fc19a62a2051a8484d364;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index 7d51cb9..c0a92b8 100644 --- a/app/Console/Commands/DiscordBotCommand.php +++ b/app/Console/Commands/DiscordBotCommand.php @@ -2,7 +2,16 @@ 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\Parts\User\Activity; +use Discord\WebSockets\Event; use Illuminate\Console\Command; use Monolog\Handler\StreamHandler; use Monolog\Logger; @@ -38,6 +47,67 @@ class DiscordBotCommand extends Command 'token' => config('discord.token'), ]); $discord->on('ready', function (Discord $discord) { + $activity = new Activity($discord); + $activity->type = Activity::TYPE_LISTENING; + $activity->name = 'HolySmoke'; + $activity->url = 'https://alttp.localhorst.tv/'; + $discord->updatePresence($activity); + }); + $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();