diff --git a/src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs b/src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs index 3bf8d177a..168d15e5f 100644 --- a/src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs @@ -6,6 +6,6 @@ namespace Discord.Commands [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] public abstract class ParameterPreconditionAttribute : Attribute { - public abstract Task CheckPermissions(CommandContext context, ParameterInfo parameter, object value, IDependencyMap map); + public abstract Task CheckPermissions(ICommandContext context, ParameterInfo parameter, object value, IDependencyMap map); } } \ No newline at end of file diff --git a/src/Discord.Net.Commands/Attributes/PreconditionAttribute.cs b/src/Discord.Net.Commands/Attributes/PreconditionAttribute.cs index 067c8e93b..7755d459b 100644 --- a/src/Discord.Net.Commands/Attributes/PreconditionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/PreconditionAttribute.cs @@ -6,6 +6,6 @@ namespace Discord.Commands [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public abstract class PreconditionAttribute : Attribute { - public abstract Task CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map); + public abstract Task CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map); } } diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs index 9f0e3c905..520cfa6fd 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs @@ -41,7 +41,7 @@ namespace Discord.Commands GuildPermission = null; } - public override async Task CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map) + public override async Task CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map) { var guildUser = await context.Guild.GetCurrentUserAsync(); diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs index bc5d9af58..42d835c30 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs @@ -37,7 +37,7 @@ namespace Discord.Commands Contexts = contexts; } - public override Task CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map) + public override Task CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map) { bool isValid = false; diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs index 5b290954c..cfedcad23 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs @@ -10,7 +10,7 @@ namespace Discord.Commands [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class RequireOwnerAttribute : PreconditionAttribute { - public override async Task CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map) + public override async Task CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map) { var application = await context.Client.GetApplicationInfoAsync(); if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess(); diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs index 04e221008..c5b79c5b9 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs @@ -42,7 +42,7 @@ namespace Discord.Commands GuildPermission = null; } - public override Task CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map) + public override Task CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map) { var guildUser = context.User as IGuildUser; diff --git a/src/Discord.Net.Commands/Builders/CommandBuilder.cs b/src/Discord.Net.Commands/Builders/CommandBuilder.cs index 3b14da263..eec43c230 100644 --- a/src/Discord.Net.Commands/Builders/CommandBuilder.cs +++ b/src/Discord.Net.Commands/Builders/CommandBuilder.cs @@ -12,7 +12,7 @@ namespace Discord.Commands.Builders private readonly List _aliases; public ModuleBuilder Module { get; } - internal Func Callback { get; set; } + internal Func Callback { get; set; } public string Name { get; set; } public string Summary { get; set; } @@ -34,7 +34,7 @@ namespace Discord.Commands.Builders _aliases = new List(); } //User-defined - internal CommandBuilder(ModuleBuilder module, string primaryAlias, Func callback) + internal CommandBuilder(ModuleBuilder module, string primaryAlias, Func callback) : this(module) { Discord.Preconditions.NotNull(primaryAlias, nameof(primaryAlias)); diff --git a/src/Discord.Net.Commands/Builders/ModuleBuilder.cs b/src/Discord.Net.Commands/Builders/ModuleBuilder.cs index 4e5b705f6..f15737e81 100644 --- a/src/Discord.Net.Commands/Builders/ModuleBuilder.cs +++ b/src/Discord.Net.Commands/Builders/ModuleBuilder.cs @@ -72,7 +72,7 @@ namespace Discord.Commands.Builders _preconditions.Add(precondition); return this; } - public ModuleBuilder AddCommand(string primaryAlias, Func callback, Action createFunc) + public ModuleBuilder AddCommand(string primaryAlias, Func callback, Action createFunc) { var builder = new CommandBuilder(this, primaryAlias, callback); createFunc(builder); diff --git a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs index 1333edd78..b7b02e4b2 100644 --- a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs +++ b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs @@ -10,7 +10,7 @@ namespace Discord.Commands { internal static class ModuleClassBuilder { - private static readonly TypeInfo _moduleTypeInfo = typeof(ModuleBase).GetTypeInfo(); + private static readonly TypeInfo _moduleTypeInfo = typeof(IModuleBase).GetTypeInfo(); public static IEnumerable Search(Assembly assembly) { @@ -155,12 +155,12 @@ namespace Discord.Commands }); } - var createInstance = ReflectionUtils.CreateBuilder(typeInfo, service); + var createInstance = ReflectionUtils.CreateBuilder(typeInfo, service); builder.Callback = (ctx, args, map) => { var instance = createInstance(map); - instance.Context = ctx; + instance.SetContext(ctx); try { return method.Invoke(instance, args) as Task ?? Task.Delay(0); diff --git a/src/Discord.Net.Commands/CommandContext.cs b/src/Discord.Net.Commands/CommandContext.cs index 50b41f02e..05bde56b1 100644 --- a/src/Discord.Net.Commands/CommandContext.cs +++ b/src/Discord.Net.Commands/CommandContext.cs @@ -1,6 +1,6 @@ namespace Discord.Commands { - public struct CommandContext + public class CommandContext : ICommandContext { public IDiscordClient Client { get; } public IGuild Guild { get; } @@ -9,15 +9,7 @@ public IUserMessage Message { get; } public bool IsPrivate => Channel is IPrivateChannel; - - public CommandContext(IDiscordClient client, IGuild guild, IMessageChannel channel, IUser user, IUserMessage msg) - { - Client = client; - Guild = guild; - Channel = channel; - User = user; - Message = msg; - } + public CommandContext(IDiscordClient client, IUserMessage msg) { Client = client; diff --git a/src/Discord.Net.Commands/CommandMatch.cs b/src/Discord.Net.Commands/CommandMatch.cs index 2e13e0f46..6e78b8509 100644 --- a/src/Discord.Net.Commands/CommandMatch.cs +++ b/src/Discord.Net.Commands/CommandMatch.cs @@ -14,13 +14,13 @@ namespace Discord.Commands Alias = alias; } - public Task CheckPreconditionsAsync(CommandContext context, IDependencyMap map = null) + public Task CheckPreconditionsAsync(ICommandContext context, IDependencyMap map = null) => Command.CheckPreconditionsAsync(context, map); - public Task ParseAsync(CommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null) + public Task ParseAsync(ICommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null) => Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult); - public Task ExecuteAsync(CommandContext context, IEnumerable argList, IEnumerable paramList, IDependencyMap map) + public Task ExecuteAsync(ICommandContext context, IEnumerable argList, IEnumerable paramList, IDependencyMap map) => Command.ExecuteAsync(context, argList, paramList, map); - public Task ExecuteAsync(CommandContext context, ParseResult parseResult, IDependencyMap map) + public Task ExecuteAsync(ICommandContext context, ParseResult parseResult, IDependencyMap map) => Command.ExecuteAsync(context, parseResult, map); } } diff --git a/src/Discord.Net.Commands/CommandParser.cs b/src/Discord.Net.Commands/CommandParser.cs index 53ea1330f..5b4ba2480 100644 --- a/src/Discord.Net.Commands/CommandParser.cs +++ b/src/Discord.Net.Commands/CommandParser.cs @@ -13,7 +13,7 @@ namespace Discord.Commands QuotedParameter } - public static async Task ParseArgs(CommandInfo command, CommandContext context, string input, int startPos) + public static async Task ParseArgs(CommandInfo command, ICommandContext context, string input, int startPos) { ParameterInfo curParam = null; StringBuilder argBuilder = new StringBuilder(input.Length); diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 18c6c3426..0d27bd178 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -222,9 +222,9 @@ namespace Discord.Commands } //Execution - public SearchResult Search(CommandContext context, int argPos) + public SearchResult Search(ICommandContext context, int argPos) => Search(context, context.Message.Content.Substring(argPos)); - public SearchResult Search(CommandContext context, string input) + public SearchResult Search(ICommandContext context, string input) { string searchInput = _caseSensitive ? input : input.ToLowerInvariant(); var matches = _map.GetCommands(searchInput).OrderByDescending(x => x.Command.Priority).ToImmutableArray(); @@ -235,9 +235,9 @@ namespace Discord.Commands return SearchResult.FromError(CommandError.UnknownCommand, "Unknown command."); } - public Task ExecuteAsync(CommandContext context, int argPos, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + public Task ExecuteAsync(ICommandContext context, int argPos, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) => ExecuteAsync(context, context.Message.Content.Substring(argPos), dependencyMap, multiMatchHandling); - public async Task ExecuteAsync(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + public async Task ExecuteAsync(ICommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) { dependencyMap = dependencyMap ?? DependencyMap.Empty; diff --git a/src/Discord.Net.Commands/IModuleBase.cs b/src/Discord.Net.Commands/IModuleBase.cs new file mode 100644 index 000000000..e65a059e3 --- /dev/null +++ b/src/Discord.Net.Commands/IModuleBase.cs @@ -0,0 +1,7 @@ +namespace Discord.Commands +{ + internal interface IModuleBase + { + void SetContext(ICommandContext context); + } +} diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs index abe802d53..031d37581 100644 --- a/src/Discord.Net.Commands/Info/CommandInfo.cs +++ b/src/Discord.Net.Commands/Info/CommandInfo.cs @@ -17,7 +17,7 @@ namespace Discord.Commands private static readonly System.Reflection.MethodInfo _convertParamsMethod = typeof(CommandInfo).GetTypeInfo().GetDeclaredMethod(nameof(ConvertParamsList)); private static readonly ConcurrentDictionary, object>> _arrayConverters = new ConcurrentDictionary, object>>(); - private readonly Func _action; + private readonly Func _action; public ModuleInfo Module { get; } public string Name { get; } @@ -63,7 +63,7 @@ namespace Discord.Commands _action = builder.Callback; } - public async Task CheckPreconditionsAsync(CommandContext context, IDependencyMap map = null) + public async Task CheckPreconditionsAsync(ICommandContext context, IDependencyMap map = null) { if (map == null) map = DependencyMap.Empty; @@ -85,7 +85,7 @@ namespace Discord.Commands return PreconditionResult.FromSuccess(); } - public async Task ParseAsync(CommandContext context, int startIndex, SearchResult searchResult, PreconditionResult? preconditionResult = null) + public async Task ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult? preconditionResult = null) { if (!searchResult.IsSuccess) return ParseResult.FromError(searchResult); @@ -96,7 +96,7 @@ namespace Discord.Commands return await CommandParser.ParseArgs(this, context, input, 0).ConfigureAwait(false); } - public Task ExecuteAsync(CommandContext context, ParseResult parseResult, IDependencyMap map) + public Task ExecuteAsync(ICommandContext context, ParseResult parseResult, IDependencyMap map) { if (!parseResult.IsSuccess) return Task.FromResult(ExecuteResult.FromError(parseResult)); @@ -119,7 +119,7 @@ namespace Discord.Commands return ExecuteAsync(context, argList, paramList, map); } - public async Task ExecuteAsync(CommandContext context, IEnumerable argList, IEnumerable paramList, IDependencyMap map) + public async Task ExecuteAsync(ICommandContext context, IEnumerable argList, IEnumerable paramList, IDependencyMap map) { if (map == null) map = DependencyMap.Empty; diff --git a/src/Discord.Net.Commands/Info/ParameterInfo.cs b/src/Discord.Net.Commands/Info/ParameterInfo.cs index f8a97647a..45ce3f0f4 100644 --- a/src/Discord.Net.Commands/Info/ParameterInfo.cs +++ b/src/Discord.Net.Commands/Info/ParameterInfo.cs @@ -41,7 +41,7 @@ namespace Discord.Commands _reader = builder.TypeReader; } - public async Task CheckPreconditionsAsync(CommandContext context, object[] args, IDependencyMap map = null) + public async Task CheckPreconditionsAsync(ICommandContext context, object[] args, IDependencyMap map = null) { if (map == null) map = DependencyMap.Empty; @@ -61,7 +61,7 @@ namespace Discord.Commands return PreconditionResult.FromSuccess(); } - public async Task Parse(CommandContext context, string input) + public async Task Parse(ICommandContext context, string input) { return await _reader.Read(context, input).ConfigureAwait(false); } diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index 96dedcb23..ccd96ed08 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -1,14 +1,27 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; namespace Discord.Commands { - public abstract class ModuleBase + public abstract class ModuleBase : ModuleBase { } + + public abstract class ModuleBase : IModuleBase + where T : class, ICommandContext { - public CommandContext Context { get; internal set; } + public T Context { get; private set; } protected virtual async Task ReplyAsync(string message, bool isTTS = false, EmbedBuilder embed = null, RequestOptions options = null) { return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false); } + + //IModuleBase + void IModuleBase.SetContext(ICommandContext context) + { + var newValue = context as T; + if (newValue == null) + throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}"); + Context = newValue; + } } } diff --git a/src/Discord.Net.Commands/Readers/ChannelTypeReader.cs b/src/Discord.Net.Commands/Readers/ChannelTypeReader.cs index e05c02abb..08821c62f 100644 --- a/src/Discord.Net.Commands/Readers/ChannelTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/ChannelTypeReader.cs @@ -9,7 +9,7 @@ namespace Discord.Commands internal class ChannelTypeReader : TypeReader where T : class, IChannel { - public override async Task Read(CommandContext context, string input) + public override async Task Read(ICommandContext context, string input) { if (context.Guild != null) { diff --git a/src/Discord.Net.Commands/Readers/EnumTypeReader.cs b/src/Discord.Net.Commands/Readers/EnumTypeReader.cs index 81870ecaf..7b2ff505a 100644 --- a/src/Discord.Net.Commands/Readers/EnumTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/EnumTypeReader.cs @@ -44,7 +44,7 @@ namespace Discord.Commands _enumsByValue = byValueBuilder.ToImmutable(); } - public override Task Read(CommandContext context, string input) + public override Task Read(ICommandContext context, string input) { T baseValue; object enumValue; diff --git a/src/Discord.Net.Commands/Readers/MessageTypeReader.cs b/src/Discord.Net.Commands/Readers/MessageTypeReader.cs index 57bfc21cd..9baa1901a 100644 --- a/src/Discord.Net.Commands/Readers/MessageTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/MessageTypeReader.cs @@ -6,7 +6,7 @@ namespace Discord.Commands internal class MessageTypeReader : TypeReader where T : class, IMessage { - public override async Task Read(CommandContext context, string input) + public override async Task Read(ICommandContext context, string input) { ulong id; diff --git a/src/Discord.Net.Commands/Readers/PrimitiveTypeReader.cs b/src/Discord.Net.Commands/Readers/PrimitiveTypeReader.cs index 824154cd0..aa4c7c7a4 100644 --- a/src/Discord.Net.Commands/Readers/PrimitiveTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/PrimitiveTypeReader.cs @@ -21,7 +21,7 @@ namespace Discord.Commands _tryParse = PrimitiveParsers.Get(); } - public override Task Read(CommandContext context, string input) + public override Task Read(ICommandContext context, string input) { T value; if (_tryParse(input, out value)) diff --git a/src/Discord.Net.Commands/Readers/RoleTypeReader.cs b/src/Discord.Net.Commands/Readers/RoleTypeReader.cs index 66b76b7e7..48544eeda 100644 --- a/src/Discord.Net.Commands/Readers/RoleTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/RoleTypeReader.cs @@ -9,7 +9,7 @@ namespace Discord.Commands internal class RoleTypeReader : TypeReader where T : class, IRole { - public override Task Read(CommandContext context, string input) + public override Task Read(ICommandContext context, string input) { ulong id; diff --git a/src/Discord.Net.Commands/Readers/TypeReader.cs b/src/Discord.Net.Commands/Readers/TypeReader.cs index 23562cb16..d53491e92 100644 --- a/src/Discord.Net.Commands/Readers/TypeReader.cs +++ b/src/Discord.Net.Commands/Readers/TypeReader.cs @@ -4,6 +4,6 @@ namespace Discord.Commands { public abstract class TypeReader { - public abstract Task Read(CommandContext context, string input); + public abstract Task Read(ICommandContext context, string input); } } diff --git a/src/Discord.Net.Commands/Readers/UserTypeReader.cs b/src/Discord.Net.Commands/Readers/UserTypeReader.cs index 82e8e9828..a5f92a277 100644 --- a/src/Discord.Net.Commands/Readers/UserTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/UserTypeReader.cs @@ -10,7 +10,7 @@ namespace Discord.Commands internal class UserTypeReader : TypeReader where T : class, IUser { - public override async Task Read(CommandContext context, string input) + public override async Task Read(ICommandContext context, string input) { var results = new Dictionary(); IReadOnlyCollection channelUsers = (await context.Channel.GetUsersAsync(CacheMode.CacheOnly).Flatten().ConfigureAwait(false)).ToArray(); //TODO: must be a better way? diff --git a/src/Discord.Net.Core/Commands/ICommandContext.cs b/src/Discord.Net.Core/Commands/ICommandContext.cs new file mode 100644 index 000000000..ac1424339 --- /dev/null +++ b/src/Discord.Net.Core/Commands/ICommandContext.cs @@ -0,0 +1,11 @@ +namespace Discord.Commands +{ + public interface ICommandContext + { + IDiscordClient Client { get; } + IGuild Guild { get; } + IMessageChannel Channel { get; } + IUser User { get; } + IUserMessage Message { get; } + } +} diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj index d589dbd4b..ec4373263 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj +++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj @@ -1,4 +1,4 @@ - + A core Discord.Net library containing the REST client and models. 1.0.0-beta2 diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs similarity index 100% rename from src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs rename to src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs diff --git a/src/Discord.Net.Rpc/Commands/RpcCommandContext.cs b/src/Discord.Net.Rpc/Commands/RpcCommandContext.cs new file mode 100644 index 000000000..80dfddbab --- /dev/null +++ b/src/Discord.Net.Rpc/Commands/RpcCommandContext.cs @@ -0,0 +1,29 @@ +using Discord.Rpc; + +namespace Discord.Commands +{ + public class RpcCommandContext : ICommandContext + { + public DiscordRpcClient Client { get; } + public IMessageChannel Channel { get; } + public RpcUser User { get; } + public RpcUserMessage Message { get; } + + public bool IsPrivate => Channel is IPrivateChannel; + + public RpcCommandContext(DiscordRpcClient client, RpcUserMessage msg) + { + Client = client; + Channel = msg.Channel; + User = msg.Author; + Message = msg; + } + + //ICommandContext + IDiscordClient ICommandContext.Client => Client; + IGuild ICommandContext.Guild => null; + IMessageChannel ICommandContext.Channel => Channel; + IUser ICommandContext.User => User; + IUserMessage ICommandContext.Message => Message; + } +} diff --git a/src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs b/src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs index d0464487b..b85071f2a 100644 --- a/src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs +++ b/src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs @@ -33,7 +33,7 @@ namespace Discord.Rpc public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks); - internal RpcMessage(DiscordRpcClient discord, ulong id, IMessageChannel channel, RpcUser author) + internal RpcMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author) : base(discord, id) { Channel = channel; @@ -62,7 +62,9 @@ namespace Discord.Rpc => MessageHelper.DeleteAsync(this, Discord, options); public override string ToString() => Content; - + + //IMessage + IMessageChannel IMessage.Channel => Channel; MessageType IMessage.Type => MessageType.Default; IUser IMessage.Author => Author; IReadOnlyCollection IMessage.Attachments => Attachments; diff --git a/src/Discord.Net.Rpc/Entities/Messages/RpcSystemMessage.cs b/src/Discord.Net.Rpc/Entities/Messages/RpcSystemMessage.cs index 734ef38bc..e8c918bc6 100644 --- a/src/Discord.Net.Rpc/Entities/Messages/RpcSystemMessage.cs +++ b/src/Discord.Net.Rpc/Entities/Messages/RpcSystemMessage.cs @@ -9,7 +9,7 @@ namespace Discord.Rpc { public MessageType Type { get; private set; } - internal RpcSystemMessage(DiscordRpcClient discord, ulong id, IMessageChannel channel, RpcUser author) + internal RpcSystemMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author) : base(discord, id, channel, author) { } diff --git a/src/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs b/src/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs index bf5ad6510..f7600bbcb 100644 --- a/src/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs +++ b/src/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs @@ -32,7 +32,7 @@ namespace Discord.Rpc public override IReadOnlyCollection Tags => _tags; public IReadOnlyDictionary Reactions => ImmutableDictionary.Create(); - internal RpcUserMessage(DiscordRpcClient discord, ulong id, IMessageChannel channel, RpcUser author) + internal RpcUserMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author) : base(discord, id, channel, author) { } diff --git a/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs b/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs new file mode 100644 index 000000000..c8b0747e7 --- /dev/null +++ b/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs @@ -0,0 +1,31 @@ +using Discord.WebSocket; + +namespace Discord.Commands +{ + public class SocketCommandContext : ICommandContext + { + public DiscordSocketClient Client { get; } + public SocketGuild Guild { get; } + public ISocketMessageChannel Channel { get; } + public SocketUser User { get; } + public SocketUserMessage Message { get; } + + public bool IsPrivate => Channel is IPrivateChannel; + + public SocketCommandContext(DiscordSocketClient client, SocketUserMessage msg) + { + Client = client; + Guild = (msg.Channel as SocketGuildChannel)?.Guild; + Channel = msg.Channel; + User = msg.Author; + Message = msg; + } + + //ICommandContext + IDiscordClient ICommandContext.Client => Client; + IGuild ICommandContext.Guild => Guild; + IMessageChannel ICommandContext.Channel => Channel; + IUser ICommandContext.User => User; + IUserMessage ICommandContext.Message => Message; + } +}