-
-
Notifications
You must be signed in to change notification settings - Fork 319
Introducing a new command framework #1553
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
Closed
Closed
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
9102db1
Started on the command handler.
Instellate 6578bd8
Merge remote-tracking branch 'origin/master'
Instellate 531f1aa
Moved message related stuff into it's own namspace
Instellate 50e36c5
Finished implementing all possible option types.
Instellate f3b833b
Some preperation for further commits.
Instellate 33fbc0b
Added README.md and TODO.md
Instellate 2782a05
Added another TODO item.
Instellate 224b177
Started on the convertion error handler.
Instellate 0b73af1
Changed a comment.
Instellate 12efcaf
Implemented a way for developers to add convertion fail handling.
Instellate f0c0a12
Added the option for DiscordRole.
Instellate bca6173
Implemented middlewares.
Instellate 6209ede
Merge branch 'DSharpPlus:master' into master
Instellate 45500c2
Tests is in DSharpPlus.Test
Instellate 8a4a802
horror, part 1
inftord 20ecd83
Merge pull request #1 from InFTord/master
Instellate 48b40d6
Replaced every complain about Count().
Instellate f98cf4e
Remade the Middleware system to only be pre module
Instellate dc8f90f
Started implementing groups for commands.
Instellate 3303118
Started the optimisation of the option parser.
Instellate 93d4ab3
Optimised the parser.
Instellate ae0be7a
horror, part 2
inftord 1f55ed2
Completed the new routine system.
Instellate 2b16c19
Added names.md and updated README.md
Instellate a59abb0
Implemented error handling for invalid options into the new routine.
Instellate 17fb223
Fully implemented spacing in module and command names.
Instellate 80bb2c4
Added more TODO items.
Instellate f3c0361
Added the possibilities for string options to have spaces by quotes.
Instellate 1c87801
Implemented default type.
Instellate 98895a7
Merge branch 'DSharpPlus:master' into master
Instellate ca6d764
Added WaitForReactionAsync into MessageCommandModule.
Instellate 70cda68
Added WaitForReactionAsync into MessageCommandModule.
Instellate d8da8d8
Added conditions for MessageReactionHandler.cs
Instellate 8349c8c
CommandModule methods can have no return value now.
Instellate 211c627
Renamed files to better names.
Instellate 93190fe
Implemented RemainingArgumentsAttribute
Instellate 3a2facd
Update names.md
Instellate a39f876
Renamed middlewares to conditions.
Instellate d1efcba
Condition construction uses Expressions delegates instead of Activator.
Instellate ca7dda1
Implemented more standard conditons.
Instellate 07b1336
General improvements.
Instellate d951bd4
Added a more developer friendly way to configure and use CH on startup.
Instellate c4af039
General improvements.
Instellate 8441507
Added a test for IErrorHandler.
Instellate 90a0b2e
Added another decision.
Instellate b0bf080
Made some improvements.
Instellate 66c926a
Started on application commands.
Instellate 8df8554
Finished the base of application commands.
Instellate c795db0
Renamed and fixed typos
Instellate 575e497
Renamed CH to UnifiedCommands
Instellate b17fe0b
Made registeration a lot better.
Instellate 141149d
fix a skill issue
inftord 8c3e8e4
Kinda implemented registration and execution of sub commands.
Instellate 72e9990
Documented almost everything public facing in the message part of the…
Instellate fe8342d
Implemented conditions for applications.
Instellate aab7c7d
Addressed a big chunk of the reviews addressed.
Instellate 5af8730
Merge branch 'DSharpPlus:master' into master
Instellate 4741d1a
Merge branch 'DSharpPlus:master' into master
Instellate 3b294c3
Addressed many of aki's review.
Instellate 8dddd38
Added a missing semicolon.
Instellate ccfeba6
Fixed all the building errors.
Instellate 4553528
Merge branch 'DSharpPlus:master' into master
Instellate 395f631
Started on IMessageConverter and remade the application conditions in…
Instellate 3c68abd
Merge branch 'master' into master
inftord 3b6ebf8
Added converters
Instellate bf0c985
Started on adding overloads
Instellate 42c2df9
Merge branch 'DSharpPlus:master' into master
Instellate de17425
Refactored error handler
Instellate 4bd084b
Merge branch 'DSharpPlus:master' into master
Instellate c3b4c83
Merge remote-tracking branch 'origin/master'
Instellate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
DSharpPlus.Test/UnifiedCommandsApplicationConditionsTest.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System.Threading.Tasks; | ||
| using DSharpPlus.Entities; | ||
| using DSharpPlus.UnifiedCommands.Application.Conditions; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace DSharpPlus.Test; | ||
|
|
||
| public class UnifiedCommandsApplicationConditionsTest : IApplicationCondition | ||
| { | ||
| public ValueTask<bool> InvokeAsync(DiscordInteraction _, DiscordClient client) | ||
| { | ||
| client.Logger.LogInformation("This got passed through this pass"); | ||
| return ValueTask.FromResult(true); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using System.Threading.Tasks; | ||
| using DSharpPlus.Entities; | ||
| using DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| namespace DSharpPlus.Test; | ||
|
|
||
| [ApplicationModule("app", "Random application commands.")] | ||
| public class UnifiedCommandsApplicationModuleTest : ApplicationModule | ||
| { | ||
| [ApplicationName("reply-test", "This is a reply test")] | ||
| public IApplicationResult ReplyTest() | ||
| { | ||
| DiscordEmbedBuilder builder = new(); | ||
| builder.WithTitle("Hello, world!").WithDescription("This is a test. Thank you for joining in!"); | ||
| return Reply(builder); | ||
| } | ||
|
|
||
| [ApplicationName("reply-opt-async", "This has options and replies async with a followup.")] | ||
| public async Task<IApplicationResult> ReplyOptAsync([ApplicationOption("user", "A user")] DiscordUser user) | ||
| { | ||
| await PostAsync(Reply("Test test.")); | ||
| return FollowUp($"You selected user {Formatter.Mention(user)}"); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using System.Threading.Tasks; | ||
| using DSharpPlus.Entities; | ||
| using DSharpPlus.UnifiedCommands; | ||
| using DSharpPlus.UnifiedCommands.Message.Errors; | ||
| using Remora.Results; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace DSharpPlus.Test; | ||
|
|
||
| public class UnifiedCommandsErrorHandler : IErrorHandler | ||
| { | ||
| public Task HandleInteractionErrorAsync(IResultError error, DiscordInteraction interaction, DiscordClient client) | ||
| { | ||
| client.Logger.LogError("Failed interaction with error: {Error}", error); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| public Task HandleMessageErrorAsync(IResultError error, DiscordMessage message, DiscordClient client) | ||
| { | ||
| client.Logger.LogError("Failed message command with error: {Error}", error); | ||
|
|
||
|
|
||
| return error is FailedConversionError e | ||
| ? message.Channel.SendMessageAsync($"Option `{e.Name}` is invalid.") | ||
| : Task.CompletedTask; | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using DSharpPlus.UnifiedCommands.Message; | ||
| using DSharpPlus.UnifiedCommands.Message.Conditions; | ||
|
|
||
| namespace DSharpPlus.Test; | ||
|
|
||
| [MessageModule("test")] | ||
| public class UnifiedCommandsMessageModuleTest : MessageModule | ||
| { | ||
| // This is commented out until I have implemented default converters for all other types | ||
| private readonly string _str; | ||
|
|
||
| public UnifiedCommandsMessageModuleTest(string str) => _str = str; | ||
|
|
||
| [Message("sync")] | ||
| public IMessageResult TestSync() => Reply("Sync works."); | ||
|
|
||
| [Message("async")] | ||
| public async Task<IMessageResult> TestAsync() | ||
| { | ||
| await PostAsync(Reply("Async works")); | ||
| return Empty(); | ||
| } | ||
|
|
||
| [Message("arg opt")] | ||
| public IMessageResult TestArgOpt(string argument, | ||
| [MessageOption("user", "u")] Entities.DiscordUser? user, [MessageOption("string", "s")] string str = "hello") | ||
| => Reply( | ||
| user is not null | ||
| ? $"Argument was `{argument}`, user {user.Username}, and string was `{str}`." | ||
| : $"Argument was `{argument}`, user wasn't provided, and string was `{str}`."); | ||
|
|
||
|
|
||
| [Message("permissions")] | ||
| [MessagePermission(Permissions.Administrator)] | ||
| public IMessageResult TestPermissions() => Reply("You are a admin."); | ||
|
|
||
| [Message("di")] | ||
| public IMessageResult TestDi() => Reply($"DI gave me value `{_str}`."); | ||
|
|
||
| [Message("no value")] | ||
| public async ValueTask TestNoValueAsync() | ||
| { | ||
| await PostAsync(Reply("This returns nothing.")); | ||
| return; | ||
| } | ||
|
|
||
| // TODO: Implement this when new custom converters exist | ||
| [Message("remaining arguments")] | ||
| public IMessageResult TestRemainingArguments([RemainingArguments] string arguments, | ||
| [MessageOption("str", "s")] string? str) | ||
| => Reply(str is null | ||
| ? $"Remaining arguments is `{arguments}`. Str is null" | ||
| : $"Remaining arguments is `{arguments}`. Str is `{str}`."); | ||
|
|
||
| [Message("cooldown"), Cooldown(10)] | ||
| public IMessageResult TestCooldowns() | ||
| => Reply("No cooldown."); | ||
|
|
||
| [Message("failing")] | ||
| public IMessageResult TestFailing() | ||
| => throw new Exception("Fuck you"); | ||
|
|
||
| [Message("overload")] | ||
| public IMessageResult TestOverload([MessageOption("str")] string str) | ||
| { | ||
| IMessageResult result = Reply(str); | ||
| return result; | ||
| } | ||
|
|
||
| [Message("overload")] | ||
| public IMessageResult TestOverload([MessageOption("int")] int num) | ||
| { | ||
| IMessageResult result = Reply(num.ToString()); | ||
| return result; | ||
| } | ||
|
|
||
| [Message("overload nested")] | ||
| public IMessageResult TestOverloadNested() | ||
| => Reply("Nested \"overload\""); | ||
| } |
30 changes: 30 additions & 0 deletions
30
DSharpPlus.UnifiedCommands/Application/ApplicationModule.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using DSharpPlus.Entities; | ||
| using DSharpPlus.UnifiedCommands.Application.Internals; | ||
|
|
||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| public abstract class ApplicationModule | ||
| { | ||
| internal ApplicationHandler _handler = null!; | ||
|
|
||
| public DiscordClient Client { get; internal set; } = null!; | ||
| public DiscordInteraction Interaction { get; internal set; } = null!; | ||
|
|
||
| protected Task PostAsync(IApplicationResult result) | ||
| => _handler.TurnResultIntoActionAsync(result); | ||
|
|
||
| protected IApplicationResult Reply(ApplicationResult result) | ||
| { | ||
| result.Type = ApplicationResultType.Reply; | ||
| return result; | ||
| } | ||
|
|
||
| protected IApplicationResult FollowUp(ApplicationResult result) | ||
| { | ||
| result.Type = ApplicationResultType.FollowUp; | ||
| return result; | ||
| } | ||
|
|
||
| protected Task<DiscordMessage> GetOriginalResponseAsync() | ||
| => Interaction.GetOriginalResponseAsync(); | ||
| } |
18 changes: 18 additions & 0 deletions
18
DSharpPlus.UnifiedCommands/Application/ApplicationModuleAttribute.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| [AttributeUsage(AttributeTargets.Class)] | ||
| public class ApplicationModuleAttribute : Attribute | ||
| { | ||
| public string? Name { get; } | ||
| public string? Description { get; } | ||
|
|
||
| public ApplicationModuleAttribute() | ||
| { | ||
| } | ||
|
|
||
| public ApplicationModuleAttribute(string name, string description) | ||
| { | ||
| Name = name; | ||
| Description = description; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
DSharpPlus.UnifiedCommands/Application/ApplicationNameAttribute.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| [AttributeUsage(AttributeTargets.Method)] | ||
| public class ApplicationNameAttribute : Attribute | ||
| { | ||
| public string Name { get; } | ||
| public string Description { get; } | ||
|
|
||
| public ApplicationNameAttribute(string name, string description) | ||
| { | ||
| Name = name; | ||
| Description = description; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
DSharpPlus.UnifiedCommands/Application/ApplicationOptionAttribute.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| [AttributeUsage(AttributeTargets.Parameter)] | ||
| public class ApplicationOptionAttribute : Attribute | ||
| { | ||
| public string Name { get; } | ||
| public string Description { get; } | ||
|
|
||
| public ApplicationOptionAttribute(string name, string description) | ||
| { | ||
| Name = name; | ||
| Description = description; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
DSharpPlus.UnifiedCommands/Application/ApplicationResult.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using DSharpPlus.Entities; | ||
|
|
||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| public class ApplicationResult : IApplicationResult | ||
| { | ||
| public ApplicationResultType Type { get; set; } | ||
| public List<DiscordEmbed>? Embeds { get; set; } | ||
| public string? Content { get; set; } | ||
|
|
||
| public static implicit operator ApplicationResult(DiscordEmbed embed) | ||
| { | ||
| ApplicationResult result = new() { Embeds = new() { embed } }; | ||
| return result; | ||
| } | ||
|
|
||
| public static implicit operator ApplicationResult(DiscordEmbedBuilder builder) | ||
| { | ||
| ApplicationResult result = new() { Embeds = new() { builder.Build() } }; | ||
| return result; | ||
| } | ||
|
|
||
| public static implicit operator ApplicationResult(string content) | ||
| { | ||
| ApplicationResult result = new() { Content = content }; | ||
| return result; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
DSharpPlus.UnifiedCommands/Application/ApplicationResultType.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| public enum ApplicationResultType | ||
| { | ||
| Reply, | ||
| FollowUp, | ||
| Edit, | ||
| Defer, | ||
| Modal, | ||
| } |
8 changes: 8 additions & 0 deletions
8
DSharpPlus.UnifiedCommands/Application/Conditions/IApplicationCondition.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using DSharpPlus.Entities; | ||
|
|
||
| namespace DSharpPlus.UnifiedCommands.Application.Conditions; | ||
|
|
||
| public interface IApplicationCondition | ||
| { | ||
| public ValueTask<bool> InvokeAsync(DiscordInteraction interaction, DiscordClient client); | ||
| } |
6 changes: 6 additions & 0 deletions
6
DSharpPlus.UnifiedCommands/Application/Entities/DiscordModalBuilder.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace DSharpPlus.UnifiedCommands.Application.Entities; | ||
|
|
||
| public class DiscordModalBuilder | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be moved to corelib, once finished |
||
| { | ||
| public string Title { get; private set; } = string.Empty; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
DSharpPlus.UnifiedCommands/Application/IApplicationResult.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using DSharpPlus.Entities; | ||
|
|
||
| namespace DSharpPlus.UnifiedCommands.Application; | ||
|
|
||
| public interface IApplicationResult | ||
| { | ||
| public ApplicationResultType Type { get; set; } | ||
| public List<DiscordEmbed>? Embeds { get; set; } | ||
| public string? Content { get; set; } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.