laravel pint format

This commit is contained in:
itsAzaria
2026-02-19 00:40:35 +00:00
parent ac4b6f166f
commit e2fbce88c4
6 changed files with 34 additions and 32 deletions
+17 -14
View File
@@ -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]),
];
}
}
+2
View File
@@ -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)
+2 -1
View File
@@ -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;
}
+2 -1
View File
@@ -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',
]
],
],
],
[
+11 -12
View File
@@ -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`."
);
}
}
}
-4
View File
@@ -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);