-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add a Discord Commands framework, and some basic commands as an example. #5
Open
TheCurle
wants to merge
10
commits into
sciwhiz12:dev/1.19.x
Choose a base branch
from
TheCurle:dev/slash
base: dev/1.19.x
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.
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
I'd point out that it would be beneficial if this PR also updates JDA to alphas, knowing that when JDA v5 releases, it will bring breaking changes to the JDA v4 command code. |
TPS is buggy.
TPS is buggy.
I've updated this PR to the latest 1.19 branch, continuing work.. |
I believe this is ready for review now. |
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.
The Command Framework
Because we're using raw JDA and not one of the extras libraries like jdautils or chewutils, I've had to implement my own Slash Commands wrapper system.
Enter, the
CommandDispatcher
.In short, it stores a list of Slash Commands internally and invokes them at the appropriate time.
Slash Commands have a whole system to themselves, based around the abstract class named
SlashCommand
.A Slash Command stores a few key points of data; the primary name they should be invoked by, the description that should be shown to the user, and some extra, more detailed help data that should be shown in the help command.
However, because of aforementioned lack of extras library, the Slash Command is also in charge of adding its' own Sub-Commands and Options. A simple example is provided in the code. For example, the
KickCommand
's setup:When the command is executed by the user, the
execute
method is invoked with theSlashCommandEvent
context passed from JDA.This roughly mirrors how JDAUtils' dispatcher works, but I took it one step further.
Since a command is a couple bits of text and a consumer of a
SlashCommandEvent
, i added a method that takes... a few Strings and aConsumer<SlashCommandEvent>
, for easier implementation of these commands. Observe the implementation of the Stop command:Upsert
The CommandDispatcher itself will handle upserting commands, and since Concord is configured to "belong" to a single guild at a time, it exists constantly in a guild-locked mode.
This has two effects; first, commands are updated immediately. Second, moderation commands cannot be invoked from a guild other than the one that Concord is relaying to.
However, the Dispatcher has an optional global mode (more specifically, the optional guild-only mode is always enabled by default in the Concord configuration) that you can use if you wish the bot to not be restricted like this.
The implemented commands
As mentioned, i've included some commands with this PR to demonstrate the Dispatcher system, as well as begin implementation of a well structured Discord interface for a Minecraft server.
It is my hope that Concord may one day be used in the core of the Hammer ecosystem, but that seems far away right now.
Anyway. The commands implented come in two major forms; moderation and casual.
Moderation commands
There are four moderation commands.
These commands are disabled by default, and are enabled by the setting of the Moderator role ID in the Concord configuration file.
Casual commands
There are also three casual commands.
/forge tps
from in-game.Future plans
ConcordDiscordCommand