X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=9aa29ae59619e5a32bd4f5f711e211e47b85b0bd;hb=9aeade5903cf6d08509fe5b1264a6bc4e0eeb60a;hp=c0a92b885867161acc1ed350574a5b32de070972;hpb=04eb1ab6316aba62b5cbf6f9b729782df1fe5015;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index c0a92b8..9aa29ae 100644 --- a/app/Console/Commands/DiscordBotCommand.php +++ b/app/Console/Commands/DiscordBotCommand.php @@ -2,6 +2,8 @@ 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; @@ -52,6 +54,23 @@ class DiscordBotCommand extends Command $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 { @@ -69,21 +88,21 @@ class DiscordBotCommand extends Command }); $discord->on(Event::CHANNEL_CREATE, function (Channel $channel, Discord $discord) { try { - DiscordGuild::onUpstreamCreate($channel); + 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 { - DiscordGuild::onUpstreamUpdate($channel); + DiscordChannel::onUpstreamUpdate($channel); } catch (\Exception $e) { $this->error('channel update: '.$e->getMessage()); } }); $discord->on(Event::CHANNEL_DELETE, function ($channel, Discord $discord) { try { - DiscordGuild::onUpstreamDelete($channel); + DiscordChannel::onUpstreamDelete($channel); } catch (\Exception $e) { $this->error('channel delete: '.$e->getMessage()); }