]> git.localhorst.tv Git - alttp.git/blobdiff - app/Console/Commands/DiscordBotCommand.php
add aosr slash command
[alttp.git] / app / Console / Commands / DiscordBotCommand.php
index c0a92b885867161acc1ed350574a5b32de070972..9aa29ae59619e5a32bd4f5f711e211e47b85b0bd 100644 (file)
@@ -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());
                        }