using System;
using System.Threading.Tasks;
using Discord.Commands.Builders;
namespace Discord.Commands
{
///
/// Provides a base class for a command module to inherit from.
///
public abstract class ModuleBase : ModuleBase { }
///
/// Provides a base class for a command module to inherit from.
///
/// A class that implements .
public abstract class ModuleBase : IModuleBase
where T : class, ICommandContext
{
///
/// The underlying context of the command.
///
///
///
public T Context { get; private set; }
///
/// Sends a message to the source channel.
///
///
/// Contents of the message; optional only if is specified.
///
/// Specifies if Discord should read this aloud using text-to-speech.
/// An embed to be displayed alongside the .
///
/// Specifies if notifications are sent for mentioned users and roles in the .
/// If null, all mentioned roles and users will be notified.
///
protected virtual async Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null)
{
return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions).ConfigureAwait(false);
}
///
/// The method to execute before executing the command.
///
/// The of the command to be executed.
protected virtual void BeforeExecute(CommandInfo command)
{
}
///
/// The method to execute after executing the command.
///
/// The of the command to be executed.
protected virtual void AfterExecute(CommandInfo command)
{
}
///
/// The method to execute when building the module.
///
/// The used to create the module.
/// The builder used to build the module.
protected virtual void OnModuleBuilding(CommandService commandService, ModuleBuilder builder)
{
}
//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);
void IModuleBase.OnModuleBuilding(CommandService commandService, ModuleBuilder builder) => OnModuleBuilding(commandService, builder);
}
}