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
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App;
use Illuminate\Support\Facades\Route;
use Laracord\Laracord;
class Bot extends Laracord
{
/**
* The HTTP routes.
*/
public function routes(): void
{
Route::middleware('web')->group(function () {
// Route::get('/', fn () => 'Hello world!');
});
Route::middleware('api')->group(function () {
// Route::get('/commands', fn () => collect($this->registeredCommands)->map(fn ($command) => [
// 'signature' => $command->getSignature(),
// 'description' => $command->getDescription(),
// ]));
});
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Events;
use Discord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Event as Events;
use Laracord\Events\Event;
use finfo;
class MessageListener extends Event
{
/**
* The event handler.
*
* @var string
*/
protected $handler = Events::MESSAGE_CREATE;
/**
* Handle the event.
*/
public function handle(Message $message, Discord $discord)
{
if ($message->member->user->bot) {
return;
}
$attachments = $message->attachments;
$message->attachments->map(function ($attachment) use ($message) {
$file = file_get_contents($attachment->url);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($file);
$message->reply('You sent an attachment with mime type ' . $mimeType . ' and filename ' . $attachment->filename);
});
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Config extends Model
{
protected $fillable = ['key', 'value'];
public static function get($key, $default = null)
{
$config = self::where('key', $key)->first();
return $config ? $config->value : $default;
}
public static function set($key, $value)
{
return self::updateOrCreate(['key' => $key], ['value' => $value]);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Mime extends Model
{
protected $fillable = ['mime', 'handling'];
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Sanctum\HasApiTokens;
class User extends Model
{
use HasApiTokens;
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [
'username',
'discord_id',
'is_admin',
];
/**
* The attributes that should be cast.
*
* @var array<string>
*/
protected $casts = [
'is_admin' => 'boolean',
];
/**
* The highlighted Discord ID.
*
* @return string
*/
public function getHighlightAttribute()
{
return "<@{$this->discord_id}>";
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use Laracord\LaracordServiceProvider;
class BotServiceProvider extends LaracordServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
parent::register();
}
}
+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;
}
}
}