tidy up of config commands

This commit is contained in:
itsAzaria
2026-02-18 19:51:06 +00:00
parent f6f1a8f9d4
commit dc421e7a0f
3 changed files with 130 additions and 89 deletions
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Traits;
use Discord\Parts\Interactions\Interaction;
trait SlashCommandHelpers
{
protected function reply($interaction, string $title, string $content)
{
$interaction->sendFollowUpMessage(
$this->message()
->title($title)
->content($content)
->build()
);
}
protected function replyWithError($interaction, string $title, string $content)
{
$interaction->sendFollowUpMessage(
$this->message()
->title($title)
->content($content)
->color(0xFF0000)
->build()
);
}
protected function setConfig($interaction, string $key, $value)
{
$oldValue = \App\Models\Config::get($key);
\App\Models\Config::set($key, $value);
$message = $oldValue === null
? "The config key `$key` has been set to `$value`."
: "The config key `$key` has been updated from `$oldValue` to `$value`.";
return $this->reply($interaction, 'Config Updated', $message);
}
protected function viewConfig($interaction, string $key)
{
$currentValue = \App\Models\Config::get($key);
if ($currentValue === null) {
return $this->reply(
$interaction,
'Config Value',
"The config key `$key` is not set."
);
}
return $this->reply(
$interaction,
'Config Value',
"The current value of the config key `$key` is `$currentValue`."
);
}
}