Merge pull request #502 from Joe4evr/Before/AfterExecute
Add BeforeExecute/AfterExecute methods to ModuleBase
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,5 +3,9 @@
|
||||
internal interface IModuleBase
|
||||
{
|
||||
void SetContext(ICommandContext context);
|
||||
|
||||
void BeforeExecute();
|
||||
|
||||
void AfterExecute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@ namespace Discord.Commands
|
||||
return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected virtual void BeforeExecute()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user