mirror of
https://github.com/the-programmers-hangout/Mimic.git
synced 2026-09-04 09:16:00 +02:00
init
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
quote_type = single
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.php]
|
||||||
|
indent_size = 4
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
APP_NAME=Laracord
|
||||||
|
APP_ENV=development
|
||||||
|
|
||||||
|
DISCORD_TOKEN=
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
|
/.github export-ignore
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
/vendor
|
||||||
|
/builds
|
||||||
|
/.laracord
|
||||||
|
*.sqlite
|
||||||
|
.env
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "es5"
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Brandon Nifong
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img title="Laracord" height="100" src="https://raw.githubusercontent.com/laracord/laracord.com/main/public/images/logo-full-dark.png" alt="Laracord Logo" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/laracord/framework/actions"><img src="https://img.shields.io/github/actions/workflow/status/laracord/framework/main.yml?branch=main&style=flat-square" alt="Build Status" /></a>
|
||||||
|
<a href="https://packagist.org/packages/laracord/framework"><img src="https://img.shields.io/packagist/dt/laracord/framework.svg?style=flat-square" alt="Total Downloads" /></a>
|
||||||
|
<a href="https://packagist.org/packages/laracord/framework"><img src="https://img.shields.io/packagist/v/laracord/framework.svg?label=framework&style=flat-square" alt="Latest Stable Version" /></a>
|
||||||
|
<a href="https://packagist.org/packages/laracord/framework"><img src="https://img.shields.io/packagist/l/laracord/framework.svg?style=flat-square" alt="License" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Laracord is a [micro-framework](https://github.com/laracord/framework) providing a powerful starting point for your next [Discord](https://discord.com/developers/docs/intro) bot.
|
||||||
|
|
||||||
|
Quickly build functional, elegant bots using [Laravel](https://laravel.com/) alongside [DiscordPHP](https://github.com/discord-php/DiscordPHP).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- ⚡️ Out of the box support for databases, caching, and many other Laravel features thanks to [Laravel Zero](https://laravel-zero.com/).
|
||||||
|
- 🚀 Instantly generate working bot [commands](https://laracord.com/docs/commands) and [event listeners](https://laracord.com/docs/events) with 0 knowledge.
|
||||||
|
- 🧑💻 Automatic handling of registering/updating/unregistering application [slash commands](https://laracord.com/docs/slash-commands).
|
||||||
|
- 🚚 Easy to use [interaction routing](https://laracord.com/docs/interactions) for persistence on message buttons and actions.
|
||||||
|
- 👷 Generate asynchronous [services/tasks](https://laracord.com/docs/services) that run parallel to the bot.
|
||||||
|
- 🌎 Optional [HTTP Server](https://laracord.com/docs/http-server) with native Laravel routing and [Livewire support](https://laracord.com/docs/livewire).
|
||||||
|
- 🔧 Fully configurable and extendable.
|
||||||
|
- 💄 Beautiful console logging with timestamps.
|
||||||
|
- 🔍️ Fully [documented](https://laracord.com) and maintained.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
For full documentation, visit [Laracord.com](https://laracord.com).
|
||||||
|
|
||||||
|
## Bug Reports
|
||||||
|
|
||||||
|
If you discover a bug in Laracord, please [open an issue](https://github.com/laracord/framework/issues).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Laracord is provided under the [MIT License](LICENSE.md).
|
||||||
+26
@@ -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(),
|
||||||
|
// ]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Mime extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = ['mime', 'handling'];
|
||||||
|
}
|
||||||
@@ -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}>";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use LaravelZero\Framework\Application;
|
||||||
|
|
||||||
|
return Application::configure(basePath: dirname(__DIR__))->create();
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"chmod": "0755",
|
||||||
|
"directories": [
|
||||||
|
"app",
|
||||||
|
"bootstrap",
|
||||||
|
"config",
|
||||||
|
"vendor",
|
||||||
|
"database"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"composer.json"
|
||||||
|
],
|
||||||
|
"exclude-composer-files": false,
|
||||||
|
"compression": "GZ",
|
||||||
|
"compactors": [
|
||||||
|
"KevinGH\\Box\\Compactor\\Php",
|
||||||
|
"KevinGH\\Box\\Compactor\\Json"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "laracord/laracord",
|
||||||
|
"type": "project",
|
||||||
|
"description": "Create Discord bots harnessing the full power of Laravel.",
|
||||||
|
"keywords": ["framework", "laravel", "discord"],
|
||||||
|
"license": "MIT",
|
||||||
|
"require": {
|
||||||
|
"php": "^8.2",
|
||||||
|
"laracord/framework": "^2.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"fakerphp/faker": "^1.23",
|
||||||
|
"laravel/pint": "^1.15"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "app/",
|
||||||
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"post-root-package-install": [
|
||||||
|
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"preferred-install": "dist",
|
||||||
|
"sort-packages": true,
|
||||||
|
"optimize-autoloader": true,
|
||||||
|
"allow-plugins": {
|
||||||
|
"php-http/discovery": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
|
}
|
||||||
Generated
+8715
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Name
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value is the name of your application. This value is used when the
|
||||||
|
| framework needs to place the application's name in a notification or
|
||||||
|
| any other location as required by the application or its packages.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'name' => env('APP_NAME', 'Laracord'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Version
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value determines the "version" your application is currently running
|
||||||
|
| in. You may want to follow the "Semantic Versioning" - Given a version
|
||||||
|
| number MAJOR.MINOR.PATCH when an update happens: https://semver.org.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'version' => app('git.version'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Environment
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value determines the "environment" your application is currently
|
||||||
|
| running in. This may determine how you prefer to configure various
|
||||||
|
| services the application utilizes. This can be overridden using
|
||||||
|
| the global command line "--env" option when calling commands.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'env' => env('APP_ENV', 'production'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Timezone
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the default timezone for your application, which
|
||||||
|
| will be used by the PHP date and date-time functions. We have gone
|
||||||
|
| ahead and set this to a sensible default for you out of the box.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'timezone' => env('APP_TIMEZONE', 'UTC'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Autoloaded Service Providers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The service providers listed here will be automatically loaded on the
|
||||||
|
| request to your application. Feel free to add your own services to
|
||||||
|
| this array to grant expanded functionality to your applications.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'providers' => [
|
||||||
|
App\Providers\BotServiceProvider::class,
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Discord\WebSockets\Intents;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Discord Bot Description
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the description of your Discord bot. This will be
|
||||||
|
| used when the bot is mentioned in chat, or when you run the "servers"
|
||||||
|
| command. Change this to anything you like.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'description' => env('DISCORD_BOT_DESCRIPTION', 'The Laracord Discord Bot.'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Discord Token
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify your Discord bot token. You can find it under the
|
||||||
|
| "Bot" section of your Discord application. Make sure to keep this
|
||||||
|
| token private and never share it with anyone for security.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'token' => env('DISCORD_TOKEN', ''),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Gateway Intents
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the gateway intents for your Discord bot. This
|
||||||
|
| will tell Discord what events your bot should receive. Intents can be
|
||||||
|
| enabled in the Discord developer application portal under:
|
||||||
|
|
|
||||||
|
| Settings > Bot > Privileged Gateway Intents
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'intents' => Intents::getDefaultIntents() | Intents::MESSAGE_CONTENT | Intents::GUILD_MEMBERS,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Command Prefix
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the command prefix for the Discord bot. This
|
||||||
|
| prefix will be used to distinguish commands from regular chat
|
||||||
|
| messages. To use mentioning the bot as a prefix, use "@mention".
|
||||||
|
| To use multiple prefixes, you may pass an array instead.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'prefix' => env('DISCORD_COMMAND_PREFIX', '!'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Additional DiscordPHP Options
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify any additional options for the DiscordPHP client.
|
||||||
|
| These options will be passed directly to the DiscordPHP client.
|
||||||
|
|
|
||||||
|
| For more information, see the DiscordPHP documentation:
|
||||||
|
| ↪ <https://discord-php.github.io/DiscordPHP/#basics>
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'options' => [
|
||||||
|
'loadAllMembers' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| HTTP Server
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The Laracord HTTP server allows you to receive and respond to HTTP
|
||||||
|
| requests from the bot at the specified address/port. This can be useful
|
||||||
|
| for creating a RESTful API for your bot.
|
||||||
|
|
|
||||||
|
| The HTTP server is automatically started when a `routes.php` file is
|
||||||
|
| present and contains valid routes. You can override this behavior by
|
||||||
|
| setting this option to `false`.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'http' => env('HTTP_SERVER', ':8080'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Timestamp Format
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the timestamp format for the Discord bot. This
|
||||||
|
| format will be used when formatting console output. You can set this
|
||||||
|
| to `false` to disable timestamps.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'timestamp' => 'h:i:s A',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Bot Admins
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may manually specify bot admins without using the User model.
|
||||||
|
| These users will have access to all bot admin commands. User's must
|
||||||
|
| be specified by their Discord user ID.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'admins' => [
|
||||||
|
//
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Additional Commands
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify any additional commands for the Discord bot. These
|
||||||
|
| commands will be loaded in addition to the commands automatically loaded
|
||||||
|
| in your project. By default, the Laracord-provided help command is
|
||||||
|
| is registered here.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'commands' => [
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Additional Context Menus
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify any additional context menus for the Discord bot.
|
||||||
|
| These context menus will be loaded in addition to the context menus
|
||||||
|
| automatically loaded in your project.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'menus' => [
|
||||||
|
//
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Additional Services
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify any additional services to run asynchronously
|
||||||
|
| alongside the Discord bot. These services will be loaded in addition
|
||||||
|
| to the services automatically loaded from your project.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'services' => [
|
||||||
|
//
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Additional Events
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify any additional events to listen for in your
|
||||||
|
| Discord bot. These events will be registered in addition to the
|
||||||
|
| events automatically registered from your project.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'events' => [
|
||||||
|
//
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('users', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('username')->index();
|
||||||
|
$table->string('discord_id')->index()->unique();
|
||||||
|
$table->boolean('is_admin')->default(false);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('users');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->morphs('tokenable');
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('token', 64)->unique();
|
||||||
|
$table->text('abilities')->nullable();
|
||||||
|
$table->timestamp('last_used_at')->nullable();
|
||||||
|
$table->timestamp('expires_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('personal_access_tokens');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('configs', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('key')->unique();
|
||||||
|
$table->text('value')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('configs');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('mimes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('mime')->unique();
|
||||||
|
$table->enum('handling', ['ALLOW', 'UPLOAD'])->default('ALLOW');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('mimes');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
define('LARAVEL_START', microtime(true));
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register The Auto Loader
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Composer provides a convenient, automatically generated class loader
|
||||||
|
| for our application. We just need to utilize it! We'll require it
|
||||||
|
| into the script here so that we do not have to worry about the
|
||||||
|
| loading of any our classes "manually". Feels great to relax.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$autoloader = require file_exists(__DIR__.'/vendor/autoload.php') ? __DIR__.'/vendor/autoload.php' : __DIR__.'/../../autoload.php';
|
||||||
|
|
||||||
|
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Run The Artisan Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When we run the console application, the current CLI command will be
|
||||||
|
| executed in this console and the response sent back to a terminal
|
||||||
|
| or another output device for the developers. Here goes nothing!
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||||
|
|
||||||
|
$status = $kernel->handle(
|
||||||
|
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||||
|
new Symfony\Component\Console\Output\ConsoleOutput
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Shutdown The Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Once Artisan has finished running, we will fire off the shutdown events
|
||||||
|
| so that any final work may be done by the application before we shut
|
||||||
|
| down the process. This is the last thing to happen to the request.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$kernel->terminate($input, $status);
|
||||||
|
|
||||||
|
exit($status);
|
||||||
Reference in New Issue
Block a user