From c297f01e773464b43d3baed9e5ba1c2e7eb144aa Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Mon, 21 Oct 2024 18:59:11 +0100 Subject: [PATCH] fix(cache): remove use of cache for permission safety --- app/Console/Commands/DiscordBot.php | 10 ++-------- app/Services/DiscordManager.php | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/DiscordBot.php b/app/Console/Commands/DiscordBot.php index a3c69a4529..f133c7a593 100644 --- a/app/Console/Commands/DiscordBot.php +++ b/app/Console/Commands/DiscordBot.php @@ -19,7 +19,6 @@ use Discord\WebSockets\Event; use Discord\WebSockets\Intents; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Cache; use Monolog\Handler\StreamHandler; use Monolog\Logger; @@ -384,10 +383,6 @@ function ($e) use ($command) { } }); - $discord->on(Event::MESSAGE_CREATE, function (Message $message) { - Cache::put('message_'.$message->id, $message->content, 86400); - }); - $discord->on(Event::MESSAGE_UPDATE, function (Message $newMessage, Discord $discord, ?Message $oldMessage) use ($guild) { try { $channel = $guild->channels->get('id', $this->log_channel_id); @@ -395,9 +390,8 @@ function ($e) use ($command) { if ($oldMessage) { $oldContent = $oldMessage->content; } else { - $oldContent = Cache::get('message_'.$newMessage->id, 'Unknown Content (Cache Expired)'); + $oldContent = 'Unknown Content (Cache Expired)'; } - Cache::put('message_'.$newMessage->id, $newMessage->content, 86400); // Create an embed message $embed = new Embed($discord); @@ -427,7 +421,7 @@ function ($e) use ($command) { if ($message instanceof Message) { $oldContent = $message->content; } else { - $oldContent = Cache::get('message_'.$message->id, 'Unknown Content (Cache Expired)'); + $oldContent = 'Unknown Content (Cache Expired)'; } $channel = $guild->channels->get('id', $this->log_channel_id); $embed = new Embed($discord); diff --git a/app/Services/DiscordManager.php b/app/Services/DiscordManager.php index 130dd79aaa..9edddf7e11 100644 --- a/app/Services/DiscordManager.php +++ b/app/Services/DiscordManager.php @@ -438,12 +438,12 @@ public function roll($interaction) { } $options = $interaction->data->options->toArray(); - $sides = $options['sides']['value']; + $sides = isset($options['sides']['value']) ? $options['sides']['value'] : 6; if (!is_numeric($sides) || $sides < 2) { return 'Invalid dice sides. Must be a number greater than 1.'; } - $quantity = $options['quantity']['value'] ?? 1; + $quantity = isset($options['quantity']['value']) ? $options['quantity']['value'] : 1; if (!is_numeric($quantity) || $quantity < 1) { return 'Invalid dice quantity. Must be a number greater than 0.'; }