Add BeforeExecute/AfterExecute methods to ModuleBase

This commit is contained in:
Joe4evr
2017-01-30 03:14:12 +01:00
parent 35c10a1006
commit c2599977a5
3 changed files with 18 additions and 0 deletions

View File

@@ -166,10 +166,12 @@ namespace Discord.Commands
instance.SetContext(ctx);
try
{
instance.BeforeExecute();
return method.Invoke(instance, args) as Task ?? Task.Delay(0);
}
finally
{
instance.AfterExecute();
(instance as IDisposable)?.Dispose();
}
};

View File

@@ -3,5 +3,9 @@
internal interface IModuleBase
{
void SetContext(ICommandContext context);
void BeforeExecute();
void AfterExecute();
}
}

View File

@@ -15,6 +15,14 @@ namespace Discord.Commands
return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false);
}
protected void BeforeExecute()
{
}
protected void AfterExecute()
{
}
//IModuleBase
void IModuleBase.SetContext(ICommandContext context)
{
@@ -23,5 +31,9 @@ namespace Discord.Commands
throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}");
Context = newValue;
}
void IModuleBase.BeforeExecute() => BeforeExecute();
void IModuleBase.AfterExecute() => AfterExecute();
}
}