-
-
Notifications
You must be signed in to change notification settings - Fork 18
v3 #134
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
base: main
Are you sure you want to change the base?
Conversation
🔧 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
… between major framework versions
|
👀 Any movement on this? |
Just launched the new site & docs redesign yesterday: https://laracord.com I just have to write docs for v3 and I can tag at least a beta. |
|
Nice! Yeah the site & docs look great. I'm definitely interested in the sharding support even if it's only a basic implementation right now. Looking forward to that being expanded on as well with the ShardManager too. Any idea how scalable Laracord actually is in it's current state, versus something like discord.js? |
|
I don't have any way to really know, but I can only assume discord.js is far easier to scale. DiscordPHP will eat memory for truly large bots. Stuff like that is difficult to optimize or even begin to think about if you don't have access to a bot with the reach to actually test though. Extremely small community of developers/users in comparison. |
|
Gotcha. With proper sharding support and good caching, I'd think a few instances could support a few thousand servers. I'd hope anyway! |
|
I think a few thousand servers would be doable for sure. You might have to shard a little more aggressive than other libs, but I still don't really know. Another big factor is what Intents you have enabled on the bot. Feel free to join the Discord if you're not! https://laracord.com/discord |
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.phpgod 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.phpthat 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
Plugininterface: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:promptand 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 newMessagefacade: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, but this typically wouldn't be recommended.Remaining Tasks
Usermodel handling.!helpcommand.ServicestoTasks.