Files
Discord.Net/src/Discord.Net.Commands/ModuleBase.cs
Finite Reality 032aba9129 Update commands with C#7 features (#689)
* C#7 features in commands, CommandInfo in ModuleBase

* Update TypeReaders with C#7 features and IServiceProvider

* Add best-choice command selection to CommandService

* Normalize type reader scores correctly

* Fix logic error and rebase onto dev

* Change GetMethod for SetMethod in ReflectionUtils

Should be checking against setters, not getters

* Ensure args/params scores do not overwhelm Priority

* Remove possibility of NaNs
2017-06-29 17:43:55 -03:00

38 lines
1.2 KiB
C#

using System;
using System.Threading.Tasks;
namespace Discord.Commands
{
public abstract class ModuleBase : ModuleBase<ICommandContext> { }
public abstract class ModuleBase<T> : IModuleBase
where T : class, ICommandContext
{
public T Context { get; private set; }
protected virtual async Task<IUserMessage> ReplyAsync(string message, bool isTTS = false, Embed embed = null, RequestOptions options = null)
{
return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false);
}
protected virtual void BeforeExecute(CommandInfo command)
{
}
protected virtual void AfterExecute(CommandInfo command)
{
}
//IModuleBase
void IModuleBase.SetContext(ICommandContext context)
{
var newValue = context as T;
Context = newValue ?? throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}");
}
void IModuleBase.BeforeExecute(CommandInfo command) => BeforeExecute(command);
void IModuleBase.AfterExecute(CommandInfo command) => AfterExecute(command);
}
}