Browse Source

Unify ShardedCommandContext with SocketCommandContext (#739)

* Make ShardedCommandContext derive from SocketCommandContext

* Explicitly re-implement ICommandContext.Client
tags/1.0.1
Joe4evr RogueException 7 years ago
parent
commit
8cd99beb62
1 changed files with 6 additions and 16 deletions
  1. +6
    -16
      src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs

+ 6
- 16
src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs 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 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) 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;
} }
} }

Loading…
Cancel
Save