using Discord.Commands.Builders; using System; using System.Threading.Tasks; 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 { #region ModuleBase /// /// 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. /// /// The request options for this request. /// The message references to be included. Used to reply to specific messages. /// The message components to be included with this message. Used for interactions. /// A collection of stickers to send with the file. /// A array of s to send with this response. Max 10. protected virtual async Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) { return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); } /// /// The method to execute asynchronously before executing the command. /// /// The of the command to be executed. protected virtual Task BeforeExecuteAsync(CommandInfo command) => Task.CompletedTask; /// /// 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 asynchronously after executing the command. /// /// The of the command to be executed. protected virtual Task AfterExecuteAsync(CommandInfo command) => Task.CompletedTask; /// /// 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) { } #endregion #region 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}."); } Task IModuleBase.BeforeExecuteAsync(CommandInfo command) => BeforeExecuteAsync(command); void IModuleBase.BeforeExecute(CommandInfo command) => BeforeExecute(command); Task IModuleBase.AfterExecuteAsync(CommandInfo command) => AfterExecuteAsync(command); void IModuleBase.AfterExecute(CommandInfo command) => AfterExecute(command); void IModuleBase.OnModuleBuilding(CommandService commandService, ModuleBuilder builder) => OnModuleBuilding(commandService, builder); #endregion } }