Unify ShardedCommandContext with SocketCommandContext (#739)

* Make ShardedCommandContext derive from SocketCommandContext

* Explicitly re-implement ICommandContext.Client
This commit is contained in:
Joe4evr
2017-07-06 01:23:46 +02:00
committed by RogueException
parent d2afb06942
commit 8cd99beb62

View File

@@ -2,30 +2,20 @@
namespace Discord.Commands namespace Discord.Commands
{ {
public class ShardedCommandContext : ICommandContext public class ShardedCommandContext : SocketCommandContext, ICommandContext
{ {
public DiscordShardedClient Client { get; } public new 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 ShardedCommandContext(DiscordShardedClient client, SocketUserMessage msg) public ShardedCommandContext(DiscordShardedClient client, SocketUserMessage msg)
: base(client.GetShard(GetShardId(client, (msg.Channel as SocketGuildChannel)?.Guild)), msg)
{ {
Client = client; 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 //ICommandContext
IDiscordClient ICommandContext.Client => Client; IDiscordClient ICommandContext.Client => Client;
IGuild ICommandContext.Guild => Guild;
IMessageChannel ICommandContext.Channel => Channel;
IUser ICommandContext.User => User;
IUserMessage ICommandContext.Message => Message;
} }
} }