Browse Source

Add BeforeExecute/AfterExecute methods to ModuleBase

tags/1.0-rc
Joe4evr 8 years ago
parent
commit
c2599977a5
3 changed files with 18 additions and 0 deletions
  1. +2
    -0
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  2. +4
    -0
      src/Discord.Net.Commands/IModuleBase.cs
  3. +12
    -0
      src/Discord.Net.Commands/ModuleBase.cs

+ 2
- 0
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs 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();
}
};


+ 4
- 0
src/Discord.Net.Commands/IModuleBase.cs View File

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

void BeforeExecute();
void AfterExecute();
}
}

+ 12
- 0
src/Discord.Net.Commands/ModuleBase.cs 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();
}
}

Loading…
Cancel
Save