From e2fbce88c424f5f40403538ba50227aaadd75ccf Mon Sep 17 00:00:00 2001 From: itsAzaria Date: Thu, 19 Feb 2026 00:40:35 +0000 Subject: [PATCH] laravel pint format --- app/Events/MessageListener.php | 31 ++++++++++++++++-------------- app/Models/Config.php | 2 ++ app/Services/Pastecord.php | 3 ++- app/SlashCommands/Config.php | 3 ++- app/SlashCommands/Mime.php | 23 +++++++++++----------- app/Traits/SlashCommandHelpers.php | 4 ---- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/Events/MessageListener.php b/app/Events/MessageListener.php index 7937e4d..9e41e89 100644 --- a/app/Events/MessageListener.php +++ b/app/Events/MessageListener.php @@ -5,9 +5,9 @@ namespace App\Events; use Discord\Discord; use Discord\Parts\Channel\Message; use Discord\WebSockets\Event as Events; +use finfo; use Illuminate\Support\Str; use Laracord\Events\Event; -use finfo; class MessageListener extends Event { @@ -37,16 +37,17 @@ class MessageListener extends Event collect($codeBlocks)->where('should_upload', true)->isNotEmpty() || $attachmentResult['should_delete']; - if (!$shouldDeleteOriginal) { + if (! $shouldDeleteOriginal) { return; } $message->delete(); - $hasUploadableContent = !empty($files) || collect($codeBlocks)->where('should_upload', true)->isNotEmpty(); + $hasUploadableContent = ! empty($files) || collect($codeBlocks)->where('should_upload', true)->isNotEmpty(); - if (!$hasUploadableContent) { + if (! $hasUploadableContent) { $this->sendDisallowedContentMessage($message, $deletedMimeTypes); + return; } @@ -60,7 +61,7 @@ class MessageListener extends Event private function collectCodeBlocks(string $content): array { - if (!Str::contains($content, '```')) { + if (! Str::contains($content, '```')) { return []; } @@ -93,9 +94,10 @@ class MessageListener extends Event $mimeType = $mimeDetector->buffer($fileContents); $mimeRule = \App\Models\Mime::where('mime', $mimeType)->first(); - if (!$mimeRule) { + if (! $mimeRule) { $shouldDelete = true; $deletedMimeTypes[] = $mimeType; + continue; } @@ -127,7 +129,7 @@ class MessageListener extends Event private function uploadToPastecord(array $codeBlocks, array $files): array { - $pastecord = new \App\Services\Pastecord(); + $pastecord = new \App\Services\Pastecord; foreach ($codeBlocks as $index => $block) { if ($block['should_upload']) { @@ -152,7 +154,8 @@ class MessageListener extends Event $lang = $block['language'] ?: ''; if ($block['should_upload']) { - $responseLines[] = "- **Code Block[{$index}]: **" . ($block['url'] ?? 'Failed to upload'); + $responseLines[] = "- **Code Block[{$index}]: **".($block['url'] ?? 'Failed to upload'); + continue; } @@ -160,7 +163,7 @@ class MessageListener extends Event } foreach ($files as $file) { - $responseLines[] = "- **File:** {$file['name']}: " . ($file['url'] ?? 'Failed to upload'); + $responseLines[] = "- **File:** {$file['name']}: ".($file['url'] ?? 'Failed to upload'); } $strippedContent = trim($this->stripCodeBlocks($content)); @@ -174,17 +177,17 @@ class MessageListener extends Event private function sendLogMessage(Message $message, array $responseLines): void { $loggingChannelId = \App\Models\Config::get(\App\Models\Config::LOGGING_CHANNEL_ID); - if (!$loggingChannelId) { + if (! $loggingChannelId) { return; } $loggingChannel = $this->discord()->getChannel($loggingChannelId); - if (!$loggingChannel) { + if (! $loggingChannel) { return; } $loggingChannel->sendMessage( - "Message from {$this->memberMention($message)} in <#{$message->channel_id}> was deleted due to disallowed content. Uploaded content:\n\n" . + "Message from {$this->memberMention($message)} in <#{$message->channel_id}> was deleted due to disallowed content. Uploaded content:\n\n". implode("\n", $responseLines) ); } @@ -193,7 +196,7 @@ class MessageListener extends Event { $memberId = $message->member?->id ?? $message->author?->id; - if (!$memberId) { + if (! $memberId) { return 'there'; } @@ -208,7 +211,7 @@ class MessageListener extends Event foreach ($matches as $match) { $codeBlocks[] = [ 'language' => $match[1] ?? '', - 'code' => trim($match[2]) + 'code' => trim($match[2]), ]; } } diff --git a/app/Models/Config.php b/app/Models/Config.php index 161488b..6f9d86d 100644 --- a/app/Models/Config.php +++ b/app/Models/Config.php @@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Model; class Config extends Model { const MAX_CODEBLOCK_SIZE = 'MAX_CODEBLOCK_SIZE'; + const LOGGING_CHANNEL_ID = 'LOGGING_CHANNEL_ID'; + protected $fillable = ['key', 'value']; public static function get($key, $default = null) diff --git a/app/Services/Pastecord.php b/app/Services/Pastecord.php index 177424d..78e2637 100644 --- a/app/Services/Pastecord.php +++ b/app/Services/Pastecord.php @@ -15,6 +15,7 @@ class Pastecord 'timeout' => 5.0, ]); } + public function upload(string $content): string { try { @@ -28,7 +29,7 @@ class Pastecord $data = json_decode($response->getBody(), true); - return self::API_BASE_URL . '/' . $data['key']; + return self::API_BASE_URL.'/'.$data['key']; } catch (\Exception $e) { return null; } diff --git a/app/SlashCommands/Config.php b/app/SlashCommands/Config.php index 592decc..4f51b58 100644 --- a/app/SlashCommands/Config.php +++ b/app/SlashCommands/Config.php @@ -9,6 +9,7 @@ use Laracord\Commands\SlashCommand; class Config extends SlashCommand { use SlashCommandHelpers; + /** * The command name. * @@ -42,7 +43,7 @@ class Config extends SlashCommand [ 'name' => 'Logging Channel ID', 'value' => 'LOGGING_CHANNEL_ID', - ] + ], ], ], [ diff --git a/app/SlashCommands/Mime.php b/app/SlashCommands/Mime.php index 3ddcefe..e2e3678 100644 --- a/app/SlashCommands/Mime.php +++ b/app/SlashCommands/Mime.php @@ -9,6 +9,7 @@ use Laracord\Commands\SlashCommand; class Mime extends SlashCommand { use SlashCommandHelpers; + /** * The command name. * @@ -82,12 +83,11 @@ class Mime extends SlashCommand 'required' => true, ], ], - ] + ], ], ], ]; - /** * The permissions required to use the command. * @@ -120,13 +120,13 @@ class Mime extends SlashCommand $interaction->acknowledge(); $operation = collect(['add', 'remove', 'view']) - ->first(fn($action) => $this->value("manage.$action.mime") !== null); + ->first(fn ($action) => $this->value("manage.$action.mime") !== null); - if (!$operation) { + if (! $operation) { return $this->replyWithError($interaction, 'Invalid Operation', 'No valid operation provided.'); } - $method = 'handle' . ucfirst($operation); + $method = 'handle'.ucfirst($operation); if (method_exists($this, $method)) { return $this->$method($interaction); @@ -135,8 +135,8 @@ class Mime extends SlashCommand protected function handleAdd($interaction) { - $mime = $this->value("manage.add.mime"); - $handling = $this->value("manage.add.handling"); + $mime = $this->value('manage.add.mime'); + $handling = $this->value('manage.add.handling'); \App\Models\Mime::updateOrCreate( ['mime' => $mime], @@ -152,7 +152,7 @@ class Mime extends SlashCommand protected function handleRemove($interaction) { - $mime = $this->value("manage.remove.mime"); + $mime = $this->value('manage.remove.mime'); \App\Models\Mime::where('mime', $mime)->delete(); @@ -165,11 +165,11 @@ class Mime extends SlashCommand protected function handleView($interaction) { - $mime = $this->value("manage.view.mime"); + $mime = $this->value('manage.view.mime'); $rule = \App\Models\Mime::where('mime', $mime)->first(); - if (!$rule) { + if (! $rule) { return $this->replyWithError( $interaction, 'No Rule Found', @@ -183,5 +183,4 @@ class Mime extends SlashCommand "The handling rule for mime type `$mime` is `$rule->handling`." ); } - -} \ No newline at end of file +} diff --git a/app/Traits/SlashCommandHelpers.php b/app/Traits/SlashCommandHelpers.php index 0c01c8c..28cd83f 100644 --- a/app/Traits/SlashCommandHelpers.php +++ b/app/Traits/SlashCommandHelpers.php @@ -2,8 +2,6 @@ namespace App\Traits; -use Discord\Parts\Interactions\Interaction; - trait SlashCommandHelpers { protected function reply($interaction, string $title, string $content) @@ -27,7 +25,6 @@ trait SlashCommandHelpers ); } - protected function setConfig($interaction, string $key, $value) { $oldValue = \App\Models\Config::get($key); @@ -41,7 +38,6 @@ trait SlashCommandHelpers return $this->reply($interaction, 'Config Updated', $message); } - protected function viewConfig($interaction, string $key) { $currentValue = \App\Models\Config::get($key);