X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FDiscordBotCommand.php;h=6c9dba91db8e09952168f97a2a7f54f5f81ff855;hb=9e08a6086d2c982ec9a2b9b79e3441ac8347f695;hp=4ffbe119f440dbf5d308d05283025cb9557bec57;hpb=d566d913c251fbb05e6bd314cc51f8b5ca49fe57;p=alttp.git diff --git a/app/Console/Commands/DiscordBotCommand.php b/app/Console/Commands/DiscordBotCommand.php index 4ffbe11..6c9dba9 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; @@ -10,7 +12,9 @@ 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 Discord\WebSockets\Intents; use Illuminate\Console\Command; use Monolog\Handler\StreamHandler; use Monolog\Logger; @@ -42,9 +46,34 @@ class DiscordBotCommand extends Command $logger = new Logger('DiscordBot'); $logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO)); $discord = new Discord([ + 'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS, 'logger' => $logger, '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->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::delete($discord); + } + }); $discord->on(Event::GUILD_CREATE, function (Guild $guild, Discord $discord) { try { DiscordGuild::onUpstreamCreate($guild); @@ -61,21 +90,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()); } @@ -101,25 +130,6 @@ class DiscordBotCommand extends Command $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(); });