Add GeekbotBase as an extension of ModuleBase

This commit is contained in:
runebaas 2019-05-23 23:23:16 +02:00
parent ced287e492
commit 8d9c436cfc
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
8 changed files with 113 additions and 11 deletions

View file

@ -0,0 +1,56 @@
using Discord;
using Geekbot.net.Lib.Localization;
namespace Geekbot.net.Lib.Context
{
/// <summary> The context of a command which may contain the client, user, guild, channel, and message. </summary>
public class GeekbotContext : IGeekbotContext
{
/// <inheritdoc />
public IDiscordClient Client { get; }
/// <inheritdoc />
public IGuild Guild { get; }
/// <inheritdoc />
public IMessageChannel Channel { get; }
/// <inheritdoc />
public IUser User { get; }
/// <inheritdoc />
public IUserMessage Message { get; }
/// <inheritdoc />
public IGuildUser GuildUser { get; }
/// <inheritdoc />
public TranslationGuildContext Translations { get; }
/// <summary> Indicates whether the channel that the command is executed in is a private channel. </summary>
public bool IsPrivate
{
get
{
return this.Channel is IPrivateChannel;
}
}
/// <summary>
/// Initializes a new <see cref="T:Discord.Commands.CommandContext" /> class with the provided client and message.
/// </summary>
/// <param name="client">The underlying client.</param>
/// <param name="msg">The underlying message.</param>
/// <param name="translationHandler">the translation handler</param>
public GeekbotContext(IDiscordClient client, IUserMessage msg, ITranslationHandler translationHandler)
{
this.Client = client;
this.Guild = (msg.Channel as IGuildChannel)?.Guild;
this.Channel = msg.Channel;
this.User = msg.Author;
this.GuildUser = msg.Author as IGuildUser;
this.Message = msg;
this.Translations = translationHandler.GetGuildContext(this.Guild, this.Message).Result;
}
}
}

View file

@ -0,0 +1,19 @@
using Discord;
using Discord.Commands;
using Geekbot.net.Lib.Localization;
namespace Geekbot.net.Lib.Context
{
public interface IGeekbotContext : ICommandContext
{
/// <summary>
/// Gets the <see cref="T:Discord:IGuildUser"/> who executed the command.
/// </summary>
IGuildUser GuildUser { get; }
/// <summary>
/// Gets the <see cref="T:Geekbot:net:Lib:Localization:TranslationGuildContext"/> containing the necessary tools for command localization.
/// </summary>
TranslationGuildContext Translations { get; }
}
}