-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3 #134
Open
Log1x
wants to merge
102
commits into
main
Choose a base branch
from
next
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,012
−2,078
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🔧 Add missing DiscordPHP options to the `discord.php` config
🎨 Utilize the `Laracord` facade when fetching token while resolving a user
🔊 Utilize the logger instead of console for logs 🧑💻 Improve HTTP server middleware implementation
🧑💻 Implement command component discovery 🎨 Improve command registration
🧑💻 Implement context menu component discovery 🎨 Improve context menu registration
🧑💻 Implement event component discovery 🎨 Improve event registration
🧑💻 Implement service component discovery 🎨 Improve service registration
🧑💻 Implement slash command component discovery 🎨 Improve slash command registration
🏗️ Move interaction logic to a trait
🏗️ Move Discord logic to a trait
✨ Add configuration methods for routing/middleware 🏗️ Move HTTP server boot/configuration logic to a trait
✨ Implement `Prompts` for interacting with the bot console while running 🏗️ Move console logic to a trait
This was
linked to
issues
Feb 8, 2025
🔧 Create a default `mail.php` config
🔇 Only write info level and above to file logging by default
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What started off as a weekend hobby project has grown significantly in features and had become a slight burden to maintain and contribute to due to minimal modularization and excessive logic residing in a single
Laracord.php
god class.Today we right those wrongs. Laracord v3 is a near complete refactor of the architecture of the framework with (hopefully) minimal breaking changes. It boasts plugin support, a full custom console implementation utilizing proper ReactPHP streams (props to @QWp6t), proper logging support, improved error rendering/handling, command/interaction middleware using pipelines, full DI support in component handlers, improved bot configuration, basic sharding support, proper command cooldown support, and more.
Prior to v3, the Laracord skeleton shipped with a
Bot.php
that extended the parent Laracord class allowing you to override methods. This has been removed and all configuration is now done within' theBotServiceProvider
. You can still technically override the Laracord class, but you'd need to do it within the container and a service provider and I'd generally recommend against it.This PR closes #131 #121 #119 #71 #67 #65 #64 #18 #124 #129 #132 #53 so far.
❤️ If you're able, please consider supporting my development on Laracord: https://github.com/sponsors/log1x
Try It Out
Configuration
Plugins
I find the introduction of plugins exciting as it gives Laracord the possibility of having its own little ecosystem. Plugin's have the same capabilities as you would in the bot provider but using the new
Plugin
interface:You would then register the plugin in your
BotServiceProvider.php
.Components are also able to be discovered via directory/namespace with Laracord registering the following defaults:
The above component discovery (and a lot of other changes) are heavily inspired by the Filament team. Huge shoutout to them for easing some of my pain in figuring out where I wanted to go with the structure of the project.
Console
Already existing in Laracord were (undocumented) built-in commands you could execute in the bot's console while it was running such as
status
. For v3, this will now be a documented and you can now make your own bot console commands called Prompts usinglaracord make:prompt
and registering them in yourBotServiceProvider
.Note
Sorry Windows users, you will have to use WSL.
Logging
With the new console implementation, I was able to implement proper logging support rendering logs as you'd expect them in both the console as well as the configured Laravel logger (defaults to
laracord.log
).With this change, you will likely want to move any console logging to the
logger()
instead ofconsole()
:When rendering in the console, logging is now a little more colorful with it properly distinguishing debug and other logs with a unique color:
Error Handling
With the above, I was able to get rid of hack-y solutions such as
Laracord::handleSafe()
and now depend on Laravel's nativerescue()
helper when handling exceptions throughout the framework. This will then properly pass the exception through a try/catch and to our logger which now renders in console. This is great because we can now take advantage of Collision for error rendering and promise rejection while inside the loop while also logging the stack trace to the configured logger:Command Middleware
Commands can now have individual or global middleware. This allows for implementations such as global rate limiting, etc. without overriding parent classes or resorting to less than desirable methods.
Take a simple example where if the command is
ping
– we short-circuit it's handler and give a different message instead using the newMessage
facade:Basic Sharding Support
I'm talkin' real basic here. In the future I'd like to implement a ShardManager that allows for IPC through child processes but today is not that day. For now, you can now pass your shard id/count during boot:
You can pass a custom token using
--token=
now too.Remaining Tasks
User
model handling.!help
command