X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=9aa29ae59619e5a32bd4f5f711e211e47b85b0bd;hb=4aeaa2ab482a0915da0016fc8175e7cbaa0ab261;hp=d2cc73e4def81fab37d50188c1d0cee3c7cf6237;hpb=3960ca694af45464a44e5a4a68ae67fc895050c0;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index d2cc73e..9aa29ae 100644 --- a/app/Console/Commands/DiscordBotCommand.php +++ b/app/Console/Commands/DiscordBotCommand.php @@ -2,8 +2,17 @@ namespace App\Console\Commands; +use App\DiscordAppCommands\AosrPresetCommand; +use App\Models\DiscordBotCommand as CommandModel; +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; @@ -40,23 +49,84 @@ class DiscordBotCommand extends Command 'token' => config('discord.token'), ]); $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); + $activity = new Activity($discord); + $activity->type = Activity::TYPE_LISTENING; + $activity->name = 'HolySmoke'; + $activity->url = 'https://alttp.localhorst.tv/'; + $discord->updatePresence($activity); + + $discord->getLoop()->addPeriodicTimer(1, function () use ($discord) { + $command = CommandModel::where('status', '=', 'pending')->oldest()->first(); + if ($command) { + try { + $command->execute($discord); + } catch (\Exception $e) { + } } }); + + if (config('discord.enable_commands')) { + AosrPresetCommand::listen($discord); + } + if (config('discord.create_commands')) { + AosrPresetCommand::create($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 { + DiscordChannel::onUpstreamCreate($channel); + } catch (\Exception $e) { + $this->error('channel create: '.$e->getMessage()); + } + }); + $discord->on(Event::CHANNEL_UPDATE, function (Channel $channel, Discord $discord, ?Channel $old) { + try { + DiscordChannel::onUpstreamUpdate($channel); + } catch (\Exception $e) { + $this->error('channel update: '.$e->getMessage()); + } + }); + $discord->on(Event::CHANNEL_DELETE, function ($channel, Discord $discord) { + try { + DiscordChannel::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();