mirror of
https://github.com/the-programmers-hangout/Mimic.git
synced 2026-09-04 01:06:00 +02:00
laravel pint format
This commit is contained in:
@@ -5,9 +5,9 @@ namespace App\Events;
|
|||||||
use Discord\Discord;
|
use Discord\Discord;
|
||||||
use Discord\Parts\Channel\Message;
|
use Discord\Parts\Channel\Message;
|
||||||
use Discord\WebSockets\Event as Events;
|
use Discord\WebSockets\Event as Events;
|
||||||
|
use finfo;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Laracord\Events\Event;
|
use Laracord\Events\Event;
|
||||||
use finfo;
|
|
||||||
|
|
||||||
class MessageListener extends Event
|
class MessageListener extends Event
|
||||||
{
|
{
|
||||||
@@ -37,16 +37,17 @@ class MessageListener extends Event
|
|||||||
collect($codeBlocks)->where('should_upload', true)->isNotEmpty() ||
|
collect($codeBlocks)->where('should_upload', true)->isNotEmpty() ||
|
||||||
$attachmentResult['should_delete'];
|
$attachmentResult['should_delete'];
|
||||||
|
|
||||||
if (!$shouldDeleteOriginal) {
|
if (! $shouldDeleteOriginal) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message->delete();
|
$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);
|
$this->sendDisallowedContentMessage($message, $deletedMimeTypes);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ class MessageListener extends Event
|
|||||||
|
|
||||||
private function collectCodeBlocks(string $content): array
|
private function collectCodeBlocks(string $content): array
|
||||||
{
|
{
|
||||||
if (!Str::contains($content, '```')) {
|
if (! Str::contains($content, '```')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +94,10 @@ class MessageListener extends Event
|
|||||||
$mimeType = $mimeDetector->buffer($fileContents);
|
$mimeType = $mimeDetector->buffer($fileContents);
|
||||||
$mimeRule = \App\Models\Mime::where('mime', $mimeType)->first();
|
$mimeRule = \App\Models\Mime::where('mime', $mimeType)->first();
|
||||||
|
|
||||||
if (!$mimeRule) {
|
if (! $mimeRule) {
|
||||||
$shouldDelete = true;
|
$shouldDelete = true;
|
||||||
$deletedMimeTypes[] = $mimeType;
|
$deletedMimeTypes[] = $mimeType;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +129,7 @@ class MessageListener extends Event
|
|||||||
|
|
||||||
private function uploadToPastecord(array $codeBlocks, array $files): array
|
private function uploadToPastecord(array $codeBlocks, array $files): array
|
||||||
{
|
{
|
||||||
$pastecord = new \App\Services\Pastecord();
|
$pastecord = new \App\Services\Pastecord;
|
||||||
|
|
||||||
foreach ($codeBlocks as $index => $block) {
|
foreach ($codeBlocks as $index => $block) {
|
||||||
if ($block['should_upload']) {
|
if ($block['should_upload']) {
|
||||||
@@ -152,7 +154,8 @@ class MessageListener extends Event
|
|||||||
$lang = $block['language'] ?: '';
|
$lang = $block['language'] ?: '';
|
||||||
|
|
||||||
if ($block['should_upload']) {
|
if ($block['should_upload']) {
|
||||||
$responseLines[] = "- **Code Block[{$index}]: **" . ($block['url'] ?? 'Failed to upload');
|
$responseLines[] = "- **Code Block[{$index}]: **".($block['url'] ?? 'Failed to upload');
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +163,7 @@ class MessageListener extends Event
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($files as $file) {
|
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));
|
$strippedContent = trim($this->stripCodeBlocks($content));
|
||||||
@@ -174,17 +177,17 @@ class MessageListener extends Event
|
|||||||
private function sendLogMessage(Message $message, array $responseLines): void
|
private function sendLogMessage(Message $message, array $responseLines): void
|
||||||
{
|
{
|
||||||
$loggingChannelId = \App\Models\Config::get(\App\Models\Config::LOGGING_CHANNEL_ID);
|
$loggingChannelId = \App\Models\Config::get(\App\Models\Config::LOGGING_CHANNEL_ID);
|
||||||
if (!$loggingChannelId) {
|
if (! $loggingChannelId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loggingChannel = $this->discord()->getChannel($loggingChannelId);
|
$loggingChannel = $this->discord()->getChannel($loggingChannelId);
|
||||||
if (!$loggingChannel) {
|
if (! $loggingChannel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loggingChannel->sendMessage(
|
$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)
|
implode("\n", $responseLines)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -193,7 +196,7 @@ class MessageListener extends Event
|
|||||||
{
|
{
|
||||||
$memberId = $message->member?->id ?? $message->author?->id;
|
$memberId = $message->member?->id ?? $message->author?->id;
|
||||||
|
|
||||||
if (!$memberId) {
|
if (! $memberId) {
|
||||||
return 'there';
|
return 'there';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +211,7 @@ class MessageListener extends Event
|
|||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
$codeBlocks[] = [
|
$codeBlocks[] = [
|
||||||
'language' => $match[1] ?? '',
|
'language' => $match[1] ?? '',
|
||||||
'code' => trim($match[2])
|
'code' => trim($match[2]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Config extends Model
|
class Config extends Model
|
||||||
{
|
{
|
||||||
const MAX_CODEBLOCK_SIZE = 'MAX_CODEBLOCK_SIZE';
|
const MAX_CODEBLOCK_SIZE = 'MAX_CODEBLOCK_SIZE';
|
||||||
|
|
||||||
const LOGGING_CHANNEL_ID = 'LOGGING_CHANNEL_ID';
|
const LOGGING_CHANNEL_ID = 'LOGGING_CHANNEL_ID';
|
||||||
|
|
||||||
protected $fillable = ['key', 'value'];
|
protected $fillable = ['key', 'value'];
|
||||||
|
|
||||||
public static function get($key, $default = null)
|
public static function get($key, $default = null)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Pastecord
|
|||||||
'timeout' => 5.0,
|
'timeout' => 5.0,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upload(string $content): string
|
public function upload(string $content): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -28,7 +29,7 @@ class Pastecord
|
|||||||
|
|
||||||
$data = json_decode($response->getBody(), true);
|
$data = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
return self::API_BASE_URL . '/' . $data['key'];
|
return self::API_BASE_URL.'/'.$data['key'];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use Laracord\Commands\SlashCommand;
|
|||||||
class Config extends SlashCommand
|
class Config extends SlashCommand
|
||||||
{
|
{
|
||||||
use SlashCommandHelpers;
|
use SlashCommandHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command name.
|
* The command name.
|
||||||
*
|
*
|
||||||
@@ -42,7 +43,7 @@ class Config extends SlashCommand
|
|||||||
[
|
[
|
||||||
'name' => 'Logging Channel ID',
|
'name' => 'Logging Channel ID',
|
||||||
'value' => 'LOGGING_CHANNEL_ID',
|
'value' => 'LOGGING_CHANNEL_ID',
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
+11
-12
@@ -9,6 +9,7 @@ use Laracord\Commands\SlashCommand;
|
|||||||
class Mime extends SlashCommand
|
class Mime extends SlashCommand
|
||||||
{
|
{
|
||||||
use SlashCommandHelpers;
|
use SlashCommandHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command name.
|
* The command name.
|
||||||
*
|
*
|
||||||
@@ -82,12 +83,11 @@ class Mime extends SlashCommand
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The permissions required to use the command.
|
* The permissions required to use the command.
|
||||||
*
|
*
|
||||||
@@ -120,13 +120,13 @@ class Mime extends SlashCommand
|
|||||||
$interaction->acknowledge();
|
$interaction->acknowledge();
|
||||||
|
|
||||||
$operation = collect(['add', 'remove', 'view'])
|
$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.');
|
return $this->replyWithError($interaction, 'Invalid Operation', 'No valid operation provided.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$method = 'handle' . ucfirst($operation);
|
$method = 'handle'.ucfirst($operation);
|
||||||
|
|
||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
return $this->$method($interaction);
|
return $this->$method($interaction);
|
||||||
@@ -135,8 +135,8 @@ class Mime extends SlashCommand
|
|||||||
|
|
||||||
protected function handleAdd($interaction)
|
protected function handleAdd($interaction)
|
||||||
{
|
{
|
||||||
$mime = $this->value("manage.add.mime");
|
$mime = $this->value('manage.add.mime');
|
||||||
$handling = $this->value("manage.add.handling");
|
$handling = $this->value('manage.add.handling');
|
||||||
|
|
||||||
\App\Models\Mime::updateOrCreate(
|
\App\Models\Mime::updateOrCreate(
|
||||||
['mime' => $mime],
|
['mime' => $mime],
|
||||||
@@ -152,7 +152,7 @@ class Mime extends SlashCommand
|
|||||||
|
|
||||||
protected function handleRemove($interaction)
|
protected function handleRemove($interaction)
|
||||||
{
|
{
|
||||||
$mime = $this->value("manage.remove.mime");
|
$mime = $this->value('manage.remove.mime');
|
||||||
|
|
||||||
\App\Models\Mime::where('mime', $mime)->delete();
|
\App\Models\Mime::where('mime', $mime)->delete();
|
||||||
|
|
||||||
@@ -165,11 +165,11 @@ class Mime extends SlashCommand
|
|||||||
|
|
||||||
protected function handleView($interaction)
|
protected function handleView($interaction)
|
||||||
{
|
{
|
||||||
$mime = $this->value("manage.view.mime");
|
$mime = $this->value('manage.view.mime');
|
||||||
|
|
||||||
$rule = \App\Models\Mime::where('mime', $mime)->first();
|
$rule = \App\Models\Mime::where('mime', $mime)->first();
|
||||||
|
|
||||||
if (!$rule) {
|
if (! $rule) {
|
||||||
return $this->replyWithError(
|
return $this->replyWithError(
|
||||||
$interaction,
|
$interaction,
|
||||||
'No Rule Found',
|
'No Rule Found',
|
||||||
@@ -183,5 +183,4 @@ class Mime extends SlashCommand
|
|||||||
"The handling rule for mime type `$mime` is `$rule->handling`."
|
"The handling rule for mime type `$mime` is `$rule->handling`."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use Discord\Parts\Interactions\Interaction;
|
|
||||||
|
|
||||||
trait SlashCommandHelpers
|
trait SlashCommandHelpers
|
||||||
{
|
{
|
||||||
protected function reply($interaction, string $title, string $content)
|
protected function reply($interaction, string $title, string $content)
|
||||||
@@ -27,7 +25,6 @@ trait SlashCommandHelpers
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function setConfig($interaction, string $key, $value)
|
protected function setConfig($interaction, string $key, $value)
|
||||||
{
|
{
|
||||||
$oldValue = \App\Models\Config::get($key);
|
$oldValue = \App\Models\Config::get($key);
|
||||||
@@ -41,7 +38,6 @@ trait SlashCommandHelpers
|
|||||||
return $this->reply($interaction, 'Config Updated', $message);
|
return $this->reply($interaction, 'Config Updated', $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function viewConfig($interaction, string $key)
|
protected function viewConfig($interaction, string $key)
|
||||||
{
|
{
|
||||||
$currentValue = \App\Models\Config::get($key);
|
$currentValue = \App\Models\Config::get($key);
|
||||||
|
|||||||
Reference in New Issue
Block a user