Skip to content
Closed
Show file tree
Hide file tree
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 Apr 24, 2023
6578bd8
Merge remote-tracking branch 'origin/master'
Instellate Apr 24, 2023
531f1aa
Moved message related stuff into it's own namspace
Instellate Apr 25, 2023
50e36c5
Finished implementing all possible option types.
Instellate Apr 25, 2023
f3b833b
Some preperation for further commits.
Instellate Apr 25, 2023
33fbc0b
Added README.md and TODO.md
Instellate Apr 25, 2023
2782a05
Added another TODO item.
Instellate Apr 25, 2023
224b177
Started on the convertion error handler.
Instellate Apr 25, 2023
0b73af1
Changed a comment.
Instellate Apr 25, 2023
12efcaf
Implemented a way for developers to add convertion fail handling.
Instellate Apr 25, 2023
f0c0a12
Added the option for DiscordRole.
Instellate Apr 26, 2023
bca6173
Implemented middlewares.
Instellate Apr 26, 2023
6209ede
Merge branch 'DSharpPlus:master' into master
Instellate Apr 26, 2023
45500c2
Tests is in DSharpPlus.Test
Instellate Apr 26, 2023
8a4a802
horror, part 1
inftord Apr 26, 2023
20ecd83
Merge pull request #1 from InFTord/master
Instellate Apr 26, 2023
48b40d6
Replaced every complain about Count().
Instellate Apr 26, 2023
f98cf4e
Remade the Middleware system to only be pre module
Instellate Apr 26, 2023
dc8f90f
Started implementing groups for commands.
Instellate Apr 28, 2023
3303118
Started the optimisation of the option parser.
Instellate Apr 28, 2023
93d4ab3
Optimised the parser.
Instellate Apr 29, 2023
ae0be7a
horror, part 2
inftord Apr 29, 2023
1f55ed2
Completed the new routine system.
Instellate Apr 30, 2023
2b16c19
Added names.md and updated README.md
Instellate Apr 30, 2023
a59abb0
Implemented error handling for invalid options into the new routine.
Instellate Apr 30, 2023
17fb223
Fully implemented spacing in module and command names.
Instellate May 1, 2023
80bb2c4
Added more TODO items.
Instellate May 1, 2023
f3c0361
Added the possibilities for string options to have spaces by quotes.
Instellate May 1, 2023
1c87801
Implemented default type.
Instellate May 1, 2023
98895a7
Merge branch 'DSharpPlus:master' into master
Instellate May 3, 2023
ca6d764
Added WaitForReactionAsync into MessageCommandModule.
Instellate May 3, 2023
70cda68
Added WaitForReactionAsync into MessageCommandModule.
Instellate May 3, 2023
d8da8d8
Added conditions for MessageReactionHandler.cs
Instellate May 3, 2023
8349c8c
CommandModule methods can have no return value now.
Instellate May 3, 2023
211c627
Renamed files to better names.
Instellate May 4, 2023
93190fe
Implemented RemainingArgumentsAttribute
Instellate May 4, 2023
3a2facd
Update names.md
Instellate May 4, 2023
a39f876
Renamed middlewares to conditions.
Instellate May 5, 2023
d1efcba
Condition construction uses Expressions delegates instead of Activator.
Instellate May 5, 2023
ca7dda1
Implemented more standard conditons.
Instellate May 6, 2023
07b1336
General improvements.
Instellate May 6, 2023
d951bd4
Added a more developer friendly way to configure and use CH on startup.
Instellate May 7, 2023
c4af039
General improvements.
Instellate May 7, 2023
8441507
Added a test for IErrorHandler.
Instellate May 7, 2023
90a0b2e
Added another decision.
Instellate May 8, 2023
b0bf080
Made some improvements.
Instellate May 10, 2023
66c926a
Started on application commands.
Instellate May 11, 2023
8df8554
Finished the base of application commands.
Instellate May 11, 2023
c795db0
Renamed and fixed typos
Instellate May 11, 2023
575e497
Renamed CH to UnifiedCommands
Instellate May 11, 2023
b17fe0b
Made registeration a lot better.
Instellate May 12, 2023
141149d
fix a skill issue
inftord May 12, 2023
8c3e8e4
Kinda implemented registration and execution of sub commands.
Instellate May 12, 2023
72e9990
Documented almost everything public facing in the message part of the…
Instellate May 12, 2023
fe8342d
Implemented conditions for applications.
Instellate May 12, 2023
aab7c7d
Addressed a big chunk of the reviews addressed.
Instellate May 16, 2023
5af8730
Merge branch 'DSharpPlus:master' into master
Instellate May 16, 2023
4741d1a
Merge branch 'DSharpPlus:master' into master
Instellate May 17, 2023
3b294c3
Addressed many of aki's review.
Instellate May 17, 2023
8dddd38
Added a missing semicolon.
Instellate May 17, 2023
ccfeba6
Fixed all the building errors.
Instellate May 17, 2023
4553528
Merge branch 'DSharpPlus:master' into master
Instellate May 25, 2023
395f631
Started on IMessageConverter and remade the application conditions in…
Instellate May 25, 2023
3c68abd
Merge branch 'master' into master
inftord Jun 9, 2023
3b6ebf8
Added converters
Instellate Jun 14, 2023
bf0c985
Started on adding overloads
Instellate Jun 15, 2023
42c2df9
Merge branch 'DSharpPlus:master' into master
Instellate Jun 15, 2023
de17425
Refactored error handler
Instellate Jun 15, 2023
4bd084b
Merge branch 'DSharpPlus:master' into master
Instellate Jun 18, 2023
c3b4c83
Merge remote-tracking branch 'origin/master'
Instellate Jun 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ csharp_style_throw_expression = true:error
csharp_style_conditional_delegate_call = true:error

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:error

# Expression-level preferences
csharp_prefer_braces = true:error
Expand Down
1 change: 1 addition & 0 deletions DSharpPlus.Test/DSharpPlus.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<ProjectReference Include="..\DSharpPlus.CommandsNext\DSharpPlus.CommandsNext.csproj" />
<ProjectReference Include="..\DSharpPlus.Interactivity\DSharpPlus.Interactivity.csproj" />
<ProjectReference Include="..\DSharpPlus.VoiceNext\DSharpPlus.VoiceNext.csproj" />
<ProjectReference Include="..\DSharpPlus.UnifiedCommands\DSharpPlus.UnifiedCommands.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
130 changes: 89 additions & 41 deletions DSharpPlus.Test/TestBot.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions DSharpPlus.Test/UnifiedCommandsApplicationConditionsTest.cs
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);
}
}
24 changes: 24 additions & 0 deletions DSharpPlus.Test/UnifiedCommandsApplicationModuleTest.cs
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)}");
}
}
27 changes: 27 additions & 0 deletions DSharpPlus.Test/UnifiedCommandsErrorHandler.cs
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;
}
}
82 changes: 82 additions & 0 deletions DSharpPlus.Test/UnifiedCommandsMessageModuleTest.cs
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 DSharpPlus.UnifiedCommands/Application/ApplicationModule.cs
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();
}
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 DSharpPlus.UnifiedCommands/Application/ApplicationNameAttribute.cs
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;
}
}
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 DSharpPlus.UnifiedCommands/Application/ApplicationResult.cs
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 DSharpPlus.UnifiedCommands/Application/ApplicationResultType.cs
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,
}
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DSharpPlus.UnifiedCommands.Application.Entities;

public class DiscordModalBuilder
Copy link
Member

Choose a reason for hiding this comment

The 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 DSharpPlus.UnifiedCommands/Application/IApplicationResult.cs
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; }
}
Loading