Skip to content

Commit

Permalink
fix(cache): remove use of cache for permission safety
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Oct 21, 2024
1 parent 633c800 commit c297f01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions app/Console/Commands/DiscordBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -384,20 +383,15 @@ 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);

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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/Services/DiscordManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
Expand Down

0 comments on commit c297f01

Please sign in to comment.