This commit is contained in:
itsAzaria
2026-02-18 19:27:33 +00:00
commit f6f1a8f9d4
28 changed files with 9784 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
<?php
namespace App\SlashCommands;
use Discord\Parts\Interactions\Command\Option;
use Discord\Parts\Interactions\Interaction;
use Laracord\Commands\SlashCommand;
class Config extends SlashCommand
{
/**
* The command name.
*
* @var string
*/
protected $name = 'config';
/**
* The command description.
*
* @var string
*/
protected $description = 'Configuration for the bot.';
/**
* The command options.
*
* @var array
*/
protected $options = [
[
'name' => 'key',
'description' => 'The config key to set or get.',
'type' => Option::STRING,
'required' => true,
'choices' => [
[
'name' => 'Max Codeblock Size',
'value' => 'MAX_CODEBLOCK_SIZE',
],
[
'name' => 'Logging Channel ID',
'value' => 'LOGGING_CHANNEL_ID',
]
],
],
[
'name' => 'value',
'description' => 'The value to set for the config key. If not provided, the current value will be returned.',
'type' => Option::STRING,
'required' => false,
],
];
/**
* The permissions required to use the command.
*
* @var array
*/
protected $permissions = ['manage_messages'];
/**
* Indicates whether the command requires admin permissions.
*
* @var bool
*/
protected $admin = false;
/**
* Indicates whether the command should be displayed in the commands list.
*
* @var bool
*/
protected $hidden = false;
/**
* Handle the slash command.
*
* @param \Discord\Parts\Interactions\Interaction $interaction
* @return mixed
*/
public function handle($interaction)
{
$interaction->acknowledge();
$key = $this->value('key');
$value = $this->value('value');
if ($value) {
\App\Models\Config::set($key, $value);
$interaction->sendFollowUpMessage(
$this
->message()
->title('Config Updated')
->content("The config key `$key` has been set to `$value`.")
->build()
);
} else {
$currentValue = \App\Models\Config::get($key, 'Not set');
$interaction->sendFollowUpMessage(
$this
->message()
->title('Config Value')
->content("The current value of the config key `$key` is `$currentValue`.")
->build()
);
}
}
}
+194
View File
@@ -0,0 +1,194 @@
<?php
namespace App\SlashCommands;
use Discord\Parts\Interactions\Command\Option;
use Laracord\Commands\SlashCommand;
class Mime extends SlashCommand
{
/**
* The command name.
*
* @var string
*/
protected $name = 'mime';
/**
* The command description.
*
* @var string
*/
protected $description = 'The Mime slash command.';
/**
* The command options.
*
* @var array
*/
protected $options = [
[
'name' => 'manage',
'description' => 'Add or Remove rules for handling mime types.',
'type' => Option::SUB_COMMAND_GROUP,
'options' => [
[
'name' => 'add',
'description' => 'Add a rule for handling a mime type.',
'type' => Option::SUB_COMMAND,
'options' => [
[
'name' => 'mime',
'description' => 'The mime type to add a rule for.',
'type' => Option::STRING,
'required' => true,
],
[
'name' => 'handling',
'description' => 'How to handle the mime type.',
'type' => Option::STRING,
'required' => true,
'choices' => [
['name' => 'Allow', 'value' => 'ALLOW'],
['name' => 'Upload', 'value' => 'UPLOAD'],
],
],
],
],
[
'name' => 'remove',
'description' => 'Remove a rule for handling a mime type.',
'type' => Option::SUB_COMMAND,
'options' => [
[
'name' => 'mime',
'description' => 'The mime type to remove the rule for.',
'type' => Option::STRING,
'required' => true,
],
],
],
[
'name' => 'view',
'description' => 'View the current rules for handling mime types.',
'type' => Option::SUB_COMMAND,
'options' => [
[
'name' => 'mime',
'description' => 'The mime type to view the rule for.',
'type' => Option::STRING,
'required' => true,
],
],
]
],
],
];
/**
* The permissions required to use the command.
*
* @var array
*/
protected $permissions = ['manage_messages'];
/**
* Indicates whether the command requires admin permissions.
*
* @var bool
*/
protected $admin = false;
/**
* Indicates whether the command should be displayed in the commands list.
*
* @var bool
*/
protected $hidden = false;
/**
* Handle the slash command.
*
* @param \Discord\Parts\Interactions\Interaction $interaction
* @return mixed
*/
public function handle($interaction)
{
$interaction->acknowledge();
$actions = ['add', 'remove', 'view'];
$operation = null;
foreach ($actions as $action) {
if ($this->value("manage.$action.mime") !== null) {
$operation = $action;
break;
}
}
switch ($operation) {
case 'add':
$mime = $this->value("manage.add.mime");
$handling = $this->value("manage.add.handling");
$this->console()->log("the handling is $handling for mime $mime");
\App\Models\Mime::updateOrCreate(
['mime' => $mime],
['handling' => $handling]
);
$interaction->sendFollowUpMessage(
$this
->message()
->title('Mime Rule')
->content("The handling rule for mime type `$mime` is set to `$handling`.")
->build()
);
break;
case 'remove':
$mime = $this->value("manage.remove.mime");
\App\Models\Mime::where('mime', $mime)->delete();
$interaction->sendFollowUpMessage(
$this
->message()
->title('Mime Rule Removed')
->content("The handling rule for mime type `$mime` has been removed.")
->build()
);
break;
case 'view':
$mime = $this->value("manage.view.mime");
$rule = \App\Models\Mime::where('mime', $mime)->first();
if (!$rule) {
$interaction->sendFollowUpMessage(
$this
->message()
->title('No Rule Found')
->content("No rule found for mime type `$mime`.")
->build()
);
} else {
$interaction->sendFollowUpMessage(
$this
->message()
->title('Mime Rule')
->content("The handling rule for mime type `$mime` is `$rule->handling`.")
->build()
);
}
break;
}
}
}