Added support for custom ModuleBase command contexts. Added SocketCommandContext/RpcCommandContext.

This commit is contained in:
RogueException
2016-12-23 16:52:32 -04:00
parent 1965c0539a
commit 2c075e186a
32 changed files with 138 additions and 53 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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);