From 8cd99beb622532290ce34ef39ae3000a3992831e Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Thu, 6 Jul 2017 01:23:46 +0200 Subject: [PATCH] Unify ShardedCommandContext with SocketCommandContext (#739) * Make ShardedCommandContext derive from SocketCommandContext * Explicitly re-implement ICommandContext.Client --- .../Commands/ShardedCommandContext.cs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs b/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs index 627b9b390..a29c9bb70 100644 --- a/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs +++ b/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs @@ -2,30 +2,20 @@ namespace Discord.Commands { - public class ShardedCommandContext : ICommandContext + public class ShardedCommandContext : SocketCommandContext, ICommandContext { - public DiscordShardedClient 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 new DiscordShardedClient Client { get; } public ShardedCommandContext(DiscordShardedClient client, SocketUserMessage msg) + : base(client.GetShard(GetShardId(client, (msg.Channel as SocketGuildChannel)?.Guild)), msg) { Client = client; - Guild = (msg.Channel as SocketGuildChannel)?.Guild; - Channel = msg.Channel; - User = msg.Author; - Message = msg; } + private static int GetShardId(DiscordShardedClient client, IGuild guild) + => guild == null ? 0 : client.GetShardIdFor(guild); + //ICommandContext IDiscordClient ICommandContext.Client => Client; - IGuild ICommandContext.Guild => Guild; - IMessageChannel ICommandContext.Channel => Channel; - IUser ICommandContext.User => User; - IUserMessage ICommandContext.Message => Message; } }