Added support for custom ModuleBase command contexts. Added SocketCommandContext/RpcCommandContext.
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Discord.Commands.Builders
|
||||
private readonly List<string> _aliases;
|
||||
|
||||
public ModuleBuilder Module { get; }
|
||||
internal Func<CommandContext, object[], IDependencyMap, Task> Callback { get; set; }
|
||||
internal Func<ICommandContext, object[], IDependencyMap, Task> Callback { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Summary { get; set; }
|
||||
@@ -34,7 +34,7 @@ namespace Discord.Commands.Builders
|
||||
_aliases = new List<string>();
|
||||
}
|
||||
//User-defined
|
||||
internal CommandBuilder(ModuleBuilder module, string primaryAlias, Func<CommandContext, object[], IDependencyMap, Task> callback)
|
||||
internal CommandBuilder(ModuleBuilder module, string primaryAlias, Func<ICommandContext, object[], IDependencyMap, Task> callback)
|
||||
: this(module)
|
||||
{
|
||||
Discord.Preconditions.NotNull(primaryAlias, nameof(primaryAlias));
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Discord.Commands.Builders
|
||||
_preconditions.Add(precondition);
|
||||
return this;
|
||||
}
|
||||
public ModuleBuilder AddCommand(string primaryAlias, Func<CommandContext, object[], IDependencyMap, Task> callback, Action<CommandBuilder> createFunc)
|
||||
public ModuleBuilder AddCommand(string primaryAlias, Func<ICommandContext, object[], IDependencyMap, Task> callback, Action<CommandBuilder> createFunc)
|
||||
{
|
||||
var builder = new CommandBuilder(this, primaryAlias, callback);
|
||||
createFunc(builder);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Discord.Commands
|
||||
{
|
||||
internal static class ModuleClassBuilder
|
||||
{
|
||||
private static readonly TypeInfo _moduleTypeInfo = typeof(ModuleBase).GetTypeInfo();
|
||||
private static readonly TypeInfo _moduleTypeInfo = typeof(IModuleBase).GetTypeInfo();
|
||||
|
||||
public static IEnumerable<TypeInfo> Search(Assembly assembly)
|
||||
{
|
||||
@@ -155,12 +155,12 @@ namespace Discord.Commands
|
||||
});
|
||||
}
|
||||
|
||||
var createInstance = ReflectionUtils.CreateBuilder<ModuleBase>(typeInfo, service);
|
||||
var createInstance = ReflectionUtils.CreateBuilder<IModuleBase>(typeInfo, service);
|
||||
|
||||
builder.Callback = (ctx, args, map) =>
|
||||
{
|
||||
var instance = createInstance(map);
|
||||
instance.Context = ctx;
|
||||
instance.SetContext(ctx);
|
||||
try
|
||||
{
|
||||
return method.Invoke(instance, args) as Task ?? Task.Delay(0);
|
||||
|
||||
Reference in New Issue
Block a user