X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=4ffbe119f440dbf5d308d05283025cb9557bec57;hb=d566d913c251fbb05e6bd314cc51f8b5ca49fe57;hp=7d51cb9df4868ec0bc76fcfc22c13d28a66606a0;hpb=4622c1d4e89a5feac97fc19a62a2051a8484d364;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index 7d51cb9..4ffbe11 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,80 @@ class DiscordBotCommand extends Command 'logger' => $logger, 'token' => config('discord.token'), ]); + $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->on('ready', function (Discord $discord) { + $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) { + if (!empty($message->guild_id)) return; + if (!empty($message->webhook_id)) return; + if (!empty($message->application_id)) return; + if (is_null($message->author)) return; + if ($message->author->bot) return; + $discord->getLoop()->addTimer(0.6, function() use ($message) { + $message->react('😄'); + }); + if (!is_null($message->channel)) { + $discord->getLoop()->addTimer(2.0, function() use ($message) { + $message->channel->sendMessage('bugger off'); + }); + } else { + $message->delayedReply('bugger off', 2000); + } + }); }); $discord->getLoop()->addSignal(SIGINT, function() use ($discord) { $discord->close();