Browse Source

Changed ids to uint64s

tags/docs-0.9
RogueException 9 years ago
parent
commit
2dca7d9ebe
42 changed files with 302 additions and 372 deletions
  1. +1
    -1
      src/Discord.Net.Audio/API/Messages/GatewaySocket.cs
  2. +3
    -3
      src/Discord.Net.Audio/API/Messages/VoiceSocket.cs
  3. +8
    -8
      src/Discord.Net.Audio/AudioService.cs
  4. +5
    -5
      src/Discord.Net.Audio/DiscordAudioClient.cs
  5. +4
    -4
      src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs
  6. +7
    -7
      src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs
  7. +1
    -1
      src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs
  8. +9
    -9
      src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs
  9. +1
    -1
      src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs
  10. +6
    -6
      src/Discord.Net.Modules/ModuleManager.cs
  11. +6
    -6
      src/Discord.Net.Shared/IdConvert.cs
  12. +6
    -6
      src/Discord.Net/API/Converters/LongStringCollectionConverter.cs
  13. +4
    -4
      src/Discord.Net/API/Converters/LongStringConverter.cs
  14. +22
    -22
      src/Discord.Net/API/Endpoints.cs
  15. +6
    -6
      src/Discord.Net/API/Messages/Channels.cs
  16. +2
    -2
      src/Discord.Net/API/Messages/GatewaySocket.cs
  17. +1
    -1
      src/Discord.Net/API/Messages/Maintenance.cs
  18. +7
    -7
      src/Discord.Net/API/Messages/Members.cs
  19. +6
    -6
      src/Discord.Net/API/Messages/Messages.cs
  20. +1
    -1
      src/Discord.Net/API/Messages/Permissions.cs
  21. +6
    -6
      src/Discord.Net/API/Messages/Roles.cs
  22. +5
    -5
      src/Discord.Net/API/Messages/Servers.cs
  23. +4
    -4
      src/Discord.Net/API/Messages/Users.cs
  24. +30
    -91
      src/Discord.Net/DiscordAPIClient.cs
  25. +7
    -8
      src/Discord.Net/DiscordClient.Channels.cs
  26. +3
    -6
      src/Discord.Net/DiscordClient.Invites.cs
  27. +14
    -15
      src/Discord.Net/DiscordClient.Messages.cs
  28. +2
    -2
      src/Discord.Net/DiscordClient.Permissions.cs
  29. +3
    -4
      src/Discord.Net/DiscordClient.Roles.cs
  30. +3
    -4
      src/Discord.Net/DiscordClient.Servers.cs
  31. +24
    -26
      src/Discord.Net/DiscordClient.Users.cs
  32. +14
    -12
      src/Discord.Net/DiscordClient.cs
  33. +2
    -2
      src/Discord.Net/Helpers/Mention.cs
  34. +6
    -6
      src/Discord.Net/Helpers/Reference.cs
  35. +12
    -12
      src/Discord.Net/Models/Channel.cs
  36. +6
    -6
      src/Discord.Net/Models/GlobalUser.cs
  37. +13
    -15
      src/Discord.Net/Models/Invite.cs
  38. +6
    -6
      src/Discord.Net/Models/Message.cs
  39. +4
    -4
      src/Discord.Net/Models/Role.cs
  40. +18
    -18
      src/Discord.Net/Models/Server.cs
  41. +11
    -11
      src/Discord.Net/Models/User.cs
  42. +3
    -3
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs

+ 1
- 1
src/Discord.Net.Audio/API/Messages/GatewaySocket.cs View File

@@ -11,7 +11,7 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ServerId;
public ulong ServerId;
[JsonProperty("endpoint")] [JsonProperty("endpoint")]
public string Endpoint; public string Endpoint;
[JsonProperty("token")] [JsonProperty("token")]


+ 3
- 3
src/Discord.Net.Audio/API/Messages/VoiceSocket.cs View File

@@ -31,10 +31,10 @@ namespace Discord.API
{ {
[JsonProperty("server_id")] [JsonProperty("server_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ServerId;
public ulong ServerId;
[JsonProperty("user_id")] [JsonProperty("user_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long UserId;
public ulong UserId;
[JsonProperty("session_id")] [JsonProperty("session_id")]
public string SessionId; public string SessionId;
[JsonProperty("token")] [JsonProperty("token")]
@@ -102,7 +102,7 @@ namespace Discord.API
{ {
[JsonProperty("user_id")] [JsonProperty("user_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long UserId;
public ulong UserId;
[JsonProperty("ssrc")] [JsonProperty("ssrc")]
public uint SSRC; public uint SSRC;
[JsonProperty("speaking")] [JsonProperty("speaking")]


+ 8
- 8
src/Discord.Net.Audio/AudioService.cs View File

@@ -8,9 +8,9 @@ namespace Discord.Audio
{ {
public class VoiceDisconnectedEventArgs : DisconnectedEventArgs public class VoiceDisconnectedEventArgs : DisconnectedEventArgs
{ {
public readonly long ServerId;
public readonly ulong ServerId;


public VoiceDisconnectedEventArgs(long serverId, DisconnectedEventArgs e)
public VoiceDisconnectedEventArgs(ulong serverId, DisconnectedEventArgs e)
: base(e.WasUnexpected, e.Error) : base(e.WasUnexpected, e.Error)
{ {
ServerId = serverId; ServerId = serverId;
@@ -28,13 +28,13 @@ namespace Discord.Audio
} }
public class VoicePacketEventArgs : EventArgs public class VoicePacketEventArgs : EventArgs
{ {
public readonly long UserId;
public readonly long ChannelId;
public readonly ulong UserId;
public readonly ulong ChannelId;
public readonly byte[] Buffer; public readonly byte[] Buffer;
public readonly int Offset; public readonly int Offset;
public readonly int Count; public readonly int Count;


public VoicePacketEventArgs(long userId, long channelId, byte[] buffer, int offset, int count)
public VoicePacketEventArgs(ulong userId, ulong channelId, byte[] buffer, int offset, int count)
{ {
UserId = userId; UserId = userId;
ChannelId = channelId; ChannelId = channelId;
@@ -47,7 +47,7 @@ namespace Discord.Audio
public class AudioService : IService public class AudioService : IService
{ {
private DiscordAudioClient _defaultClient; private DiscordAudioClient _defaultClient;
private ConcurrentDictionary<long, DiscordAudioClient> _voiceClients;
private ConcurrentDictionary<ulong, DiscordAudioClient> _voiceClients;
private ConcurrentDictionary<User, bool> _talkingUsers; private ConcurrentDictionary<User, bool> _talkingUsers;
private int _nextClientId; private int _nextClientId;


@@ -64,7 +64,7 @@ namespace Discord.Audio
Connected(this, EventArgs.Empty); Connected(this, EventArgs.Empty);
} }
public event EventHandler<VoiceDisconnectedEventArgs> Disconnected; public event EventHandler<VoiceDisconnectedEventArgs> Disconnected;
private void RaiseDisconnected(long serverId, DisconnectedEventArgs e)
private void RaiseDisconnected(ulong serverId, DisconnectedEventArgs e)
{ {
if (Disconnected != null) if (Disconnected != null)
Disconnected(this, new VoiceDisconnectedEventArgs(serverId, e)); Disconnected(this, new VoiceDisconnectedEventArgs(serverId, e));
@@ -91,7 +91,7 @@ namespace Discord.Audio
{ {
_client = client; _client = client;
if (Config.EnableMultiserver) if (Config.EnableMultiserver)
_voiceClients = new ConcurrentDictionary<long, DiscordAudioClient>();
_voiceClients = new ConcurrentDictionary<ulong, DiscordAudioClient>();
else else
{ {
var logger = Client.Log().CreateLogger("Voice"); var logger = Client.Log().CreateLogger("Voice");


+ 5
- 5
src/Discord.Net.Audio/DiscordAudioClient.cs View File

@@ -22,8 +22,8 @@ namespace Discord.Audio
public string Token => _token; public string Token => _token;
private string _token; private string _token;


public long? ServerId => _voiceSocket.ServerId;
public long? ChannelId => _voiceSocket.ChannelId;
public ulong? ServerId => _voiceSocket.ServerId;
public ulong? ChannelId => _voiceSocket.ChannelId;


public DiscordAudioClient(AudioService service, int id, Logger logger, GatewaySocket gatewaySocket) public DiscordAudioClient(AudioService service, int id, Logger logger, GatewaySocket gatewaySocket)
{ {
@@ -76,7 +76,7 @@ namespace Discord.Audio
case "VOICE_SERVER_UPDATE": case "VOICE_SERVER_UPDATE":
{ {
var data = e.Payload.ToObject<VoiceServerUpdateEvent>(_gatewaySocket.Serializer); var data = e.Payload.ToObject<VoiceServerUpdateEvent>(_gatewaySocket.Serializer);
long serverId = data.ServerId;
var serverId = data.ServerId;


if (serverId == ServerId) if (serverId == ServerId)
{ {
@@ -101,14 +101,14 @@ namespace Discord.Audio
return _voiceSocket.Disconnect(); return _voiceSocket.Disconnect();
} }


internal void SetServerId(long serverId)
internal void SetServerId(ulong serverId)
{ {
_voiceSocket.ServerId = serverId; _voiceSocket.ServerId = serverId;
} }
public async Task Join(Channel channel) public async Task Join(Channel channel)
{ {
if (channel == null) throw new ArgumentNullException(nameof(channel)); if (channel == null) throw new ArgumentNullException(nameof(channel));
long? serverId = channel.Server?.Id;
ulong? serverId = channel.Server?.Id;
if (serverId != ServerId) if (serverId != ServerId)
throw new InvalidOperationException("Cannot join a channel on a different server than this voice client."); throw new InvalidOperationException("Cannot join a channel on a different server than this voice client.");
//CheckReady(checkVoice: true); //CheckReady(checkVoice: true);


+ 4
- 4
src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs View File

@@ -5,9 +5,9 @@ namespace Discord.Net.WebSockets
{ {
internal sealed class IsTalkingEventArgs : EventArgs internal sealed class IsTalkingEventArgs : EventArgs
{ {
public readonly long UserId;
public readonly ulong UserId;
public readonly bool IsSpeaking; public readonly bool IsSpeaking;
internal IsTalkingEventArgs(long userId, bool isTalking)
internal IsTalkingEventArgs(ulong userId, bool isTalking)
{ {
UserId = userId; UserId = userId;
IsSpeaking = isTalking; IsSpeaking = isTalking;
@@ -17,14 +17,14 @@ namespace Discord.Net.WebSockets
public partial class VoiceWebSocket public partial class VoiceWebSocket
{ {
internal event EventHandler<IsTalkingEventArgs> IsSpeaking; internal event EventHandler<IsTalkingEventArgs> IsSpeaking;
private void RaiseIsSpeaking(long userId, bool isSpeaking)
private void RaiseIsSpeaking(ulong userId, bool isSpeaking)
{ {
if (IsSpeaking != null) if (IsSpeaking != null)
IsSpeaking(this, new IsTalkingEventArgs(userId, isSpeaking)); IsSpeaking(this, new IsTalkingEventArgs(userId, isSpeaking));
} }


internal event EventHandler<VoicePacketEventArgs> OnPacket; internal event EventHandler<VoicePacketEventArgs> OnPacket;
internal void RaiseOnPacket(long userId, long channelId, byte[] buffer, int offset, int count)
internal void RaiseOnPacket(ulong userId, ulong channelId, byte[] buffer, int offset, int count)
{ {
if (OnPacket != null) if (OnPacket != null)
OnPacket(this, new VoicePacketEventArgs(userId, channelId, buffer, offset, count)); OnPacket(this, new VoicePacketEventArgs(userId, channelId, buffer, offset, count));


+ 7
- 7
src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs View File

@@ -30,7 +30,7 @@ namespace Discord.Net.WebSockets
private readonly AudioServiceConfig _config; private readonly AudioServiceConfig _config;
private OpusEncoder _encoder; private OpusEncoder _encoder;
private uint _ssrc; private uint _ssrc;
private ConcurrentDictionary<uint, long> _ssrcMapping;
private ConcurrentDictionary<uint, ulong> _ssrcMapping;


private VoiceBuffer _sendBuffer; private VoiceBuffer _sendBuffer;
private UdpClient _udp; private UdpClient _udp;
@@ -38,14 +38,14 @@ namespace Discord.Net.WebSockets
private bool _isEncrypted; private bool _isEncrypted;
private byte[] _secretKey, _encodingBuffer; private byte[] _secretKey, _encodingBuffer;
private ushort _sequence; private ushort _sequence;
private long? _serverId, _channelId;
private ulong? _serverId, _channelId;
private string _encryptionMode; private string _encryptionMode;
private int _ping; private int _ping;
private Thread _sendThread, _receiveThread; private Thread _sendThread, _receiveThread;
public long? ServerId { get { return _serverId; } internal set { _serverId = value; } }
public long? ChannelId { get { return _channelId; } internal set { _channelId = value; } }
public ulong? ServerId { get { return _serverId; } internal set { _serverId = value; } }
public ulong? ChannelId { get { return _channelId; } internal set { _channelId = value; } }
public int Ping => _ping; public int Ping => _ping;
internal VoiceBuffer OutputBuffer => _sendBuffer; internal VoiceBuffer OutputBuffer => _sendBuffer;


@@ -57,7 +57,7 @@ namespace Discord.Net.WebSockets
_decoders = new ConcurrentDictionary<uint, OpusDecoder>(); _decoders = new ConcurrentDictionary<uint, OpusDecoder>();
_targetAudioBufferLength = _config.BufferLength / 20; //20 ms frames _targetAudioBufferLength = _config.BufferLength / 20; //20 ms frames
_encodingBuffer = new byte[MaxOpusSize]; _encodingBuffer = new byte[MaxOpusSize];
_ssrcMapping = new ConcurrentDictionary<uint, long>();
_ssrcMapping = new ConcurrentDictionary<uint, ulong>();
_encoder = new OpusEncoder(48000, _config.Channels, 20, _config.Bitrate, OpusApplication.Audio); _encoder = new OpusEncoder(48000, _config.Channels, 20, _config.Bitrate, OpusApplication.Audio);
_sendBuffer = new VoiceBuffer((int)Math.Ceiling(_config.BufferLength / (double)_encoder.FrameLength), _encoder.FrameSize); _sendBuffer = new VoiceBuffer((int)Math.Ceiling(_config.BufferLength / (double)_encoder.FrameLength), _encoder.FrameSize);
} }
@@ -228,10 +228,10 @@ namespace Discord.Net.WebSockets
resultLength = packetLength - 12; resultLength = packetLength - 12;
} }


/*if (_logLevel >= LogMessageSeverity.Debug)
/*if (_logLevel >= LogMessageSeverity.Debug)
RaiseOnLog(LogMessageSeverity.Debug, $"Received {buffer.Length - 12} bytes.");*/ RaiseOnLog(LogMessageSeverity.Debug, $"Received {buffer.Length - 12} bytes.");*/


long userId;
ulong userId;
if (_ssrcMapping.TryGetValue(ssrc, out userId)) if (_ssrcMapping.TryGetValue(ssrc, out userId))
RaiseOnPacket(userId, _channelId.Value, result, resultOffset, resultLength); RaiseOnPacket(userId, _channelId.Value, result, resultOffset, resultLength);
} }


+ 1
- 1
src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs View File

@@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist
{ {
public class BlacklistService : UserlistService public class BlacklistService : UserlistService
{ {
public BlacklistService(IEnumerable<long> initialList = null)
public BlacklistService(IEnumerable<ulong> initialList = null)
: base(initialList) : base(initialList)
{ {
} }


+ 9
- 9
src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs View File

@@ -7,39 +7,39 @@ namespace Discord.Commands.Permissions.Userlist
{ {
public class UserlistService : IService public class UserlistService : IService
{ {
protected readonly ConcurrentDictionary<long, bool> _userList;
protected readonly ConcurrentDictionary<ulong, bool> _userList;
private DiscordClient _client; private DiscordClient _client;


public DiscordClient Client => _client; public DiscordClient Client => _client;
public IEnumerable<long> UserIds => _userList.Select(x => x.Key);
public IEnumerable<ulong> UserIds => _userList.Select(x => x.Key);


public UserlistService(IEnumerable<long> initialList = null)
public UserlistService(IEnumerable<ulong> initialList = null)
{ {
if (initialList != null) if (initialList != null)
_userList = new ConcurrentDictionary<long, bool>(initialList.Select(x => new KeyValuePair<long, bool>(x, true)));
_userList = new ConcurrentDictionary<ulong, bool>(initialList.Select(x => new KeyValuePair<ulong, bool>(x, true)));
else else
_userList = new ConcurrentDictionary<long, bool>();
_userList = new ConcurrentDictionary<ulong, bool>();
} }


public void Add(User user) public void Add(User user)
{ {
if (user == null) throw new ArgumentNullException(nameof(user)); if (user == null) throw new ArgumentNullException(nameof(user));

_userList[user.Id] = true; _userList[user.Id] = true;
} }
public void Add(long userId)
public void Add(ulong userId)
{ {
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
_userList[userId] = true; _userList[userId] = true;
} }
public bool Remove(User user) public bool Remove(User user)
{ {
if (user == null) throw new ArgumentNullException(nameof(user)); if (user == null) throw new ArgumentNullException(nameof(user));

bool ignored; bool ignored;
return _userList.TryRemove(user.Id, out ignored); return _userList.TryRemove(user.Id, out ignored);
} }
public bool Remove(long userId)
public bool Remove(ulong userId)
{ {
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
bool ignored; bool ignored;
return _userList.TryRemove(userId, out ignored); return _userList.TryRemove(userId, out ignored);
} }


+ 1
- 1
src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs View File

@@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist
{ {
public class WhitelistService : UserlistService public class WhitelistService : UserlistService
{ {
public WhitelistService(IEnumerable<long> initialList = null)
public WhitelistService(IEnumerable<ulong> initialList = null)
: base(initialList) : base(initialList)
{ {
} }


+ 6
- 6
src/Discord.Net.Modules/ModuleManager.cs View File

@@ -46,9 +46,9 @@ namespace Discord.Modules
private readonly string _name, _id; private readonly string _name, _id;
private readonly FilterType _filterType; private readonly FilterType _filterType;
private readonly bool _useServerWhitelist, _useChannelWhitelist, _allowAll, _allowPrivate; private readonly bool _useServerWhitelist, _useChannelWhitelist, _allowAll, _allowPrivate;
private readonly ConcurrentDictionary<long, Server> _enabledServers;
private readonly ConcurrentDictionary<long, Channel> _enabledChannels;
private readonly ConcurrentDictionary<long, int> _indirectServers;
private readonly ConcurrentDictionary<ulong, Server> _enabledServers;
private readonly ConcurrentDictionary<ulong, Channel> _enabledChannels;
private readonly ConcurrentDictionary<ulong, int> _indirectServers;


public DiscordClient Client => _client; public DiscordClient Client => _client;
public string Name => _name; public string Name => _name;
@@ -69,9 +69,9 @@ namespace Discord.Modules
_useChannelWhitelist = filterType.HasFlag(FilterType.ChannelWhitelist); _useChannelWhitelist = filterType.HasFlag(FilterType.ChannelWhitelist);
_allowPrivate = filterType.HasFlag(FilterType.AllowPrivate); _allowPrivate = filterType.HasFlag(FilterType.AllowPrivate);


_enabledServers = new ConcurrentDictionary<long, Server>();
_enabledChannels = new ConcurrentDictionary<long, Channel>();
_indirectServers = new ConcurrentDictionary<long, int>();
_enabledServers = new ConcurrentDictionary<ulong, Server>();
_enabledChannels = new ConcurrentDictionary<ulong, Channel>();
_indirectServers = new ConcurrentDictionary<ulong, int>();


if (_allowAll || _useServerWhitelist) //Server-only events if (_allowAll || _useServerWhitelist) //Server-only events
{ {


+ 6
- 6
src/Discord.Net.Shared/IdConvert.cs View File

@@ -7,14 +7,14 @@ namespace Discord
{ {
internal static readonly IFormatProvider _format = CultureInfo.InvariantCulture; internal static readonly IFormatProvider _format = CultureInfo.InvariantCulture;
public static long ToLong(string value)
=> long.Parse(value, NumberStyles.None, _format);
public static long? ToNullableLong(string value)
=> value == null ? (long?)null : long.Parse(value, NumberStyles.None, _format);
public static ulong ToLong(string value)
=> ulong.Parse(value, NumberStyles.None, _format);
public static ulong? ToNullableLong(string value)
=> value == null ? (ulong?)null : ulong.Parse(value, NumberStyles.None, _format);
public static string ToString(long value)
public static string ToString(ulong value)
=> value.ToString(_format); => value.ToString(_format);
public static string ToString(long? value)
public static string ToString(ulong? value)
=> value?.ToString(_format); => value?.ToString(_format);
} }
} }

+ 6
- 6
src/Discord.Net/API/Converters/LongStringCollectionConverter.cs View File

@@ -8,11 +8,11 @@ namespace Discord.API.Converters
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)
{ {
return objectType == typeof(IEnumerable<long>);
return objectType == typeof(IEnumerable<ulong>);
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
List<long> result = new List<long>();
List<ulong> result = new List<ulong>();
if (reader.TokenType == JsonToken.StartArray) if (reader.TokenType == JsonToken.StartArray)
{ {
reader.Read(); reader.Read();
@@ -31,7 +31,7 @@ namespace Discord.API.Converters
else else
{ {
writer.WriteStartArray(); writer.WriteStartArray();
foreach (var v in (IEnumerable<long>)value)
foreach (var v in (IEnumerable<ulong>)value)
writer.WriteValue(IdConvert.ToString(v)); writer.WriteValue(IdConvert.ToString(v));
writer.WriteEndArray(); writer.WriteEndArray();
} }
@@ -42,11 +42,11 @@ namespace Discord.API.Converters
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)
{ {
return objectType == typeof(IEnumerable<long[]>);
return objectType == typeof(IEnumerable<ulong[]>);
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
List<long> result = new List<long>();
var result = new List<ulong>();
if (reader.TokenType == JsonToken.StartArray) if (reader.TokenType == JsonToken.StartArray)
{ {
reader.Read(); reader.Read();
@@ -65,7 +65,7 @@ namespace Discord.API.Converters
else else
{ {
writer.WriteStartArray(); writer.WriteStartArray();
var a = (long[])value;
var a = (ulong[])value;
for (int i = 0; i < a.Length; i++) for (int i = 0; i < a.Length; i++)
writer.WriteValue(IdConvert.ToString(a[i])); writer.WriteValue(IdConvert.ToString(a[i]));
writer.WriteEndArray(); writer.WriteEndArray();


+ 4
- 4
src/Discord.Net/API/Converters/LongStringConverter.cs View File

@@ -7,7 +7,7 @@ namespace Discord.API.Converters
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)
{ {
return objectType == typeof(long);
return objectType == typeof(ulong);
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
@@ -15,7 +15,7 @@ namespace Discord.API.Converters
} }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
writer.WriteValue(IdConvert.ToString((long)value));
writer.WriteValue(IdConvert.ToString((ulong)value));
} }
} }


@@ -23,7 +23,7 @@ namespace Discord.API.Converters
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)
{ {
return objectType == typeof(long?);
return objectType == typeof(ulong?);
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
@@ -31,7 +31,7 @@ namespace Discord.API.Converters
} }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
writer.WriteValue(IdConvert.ToString((long?)value));
writer.WriteValue(IdConvert.ToString((ulong?)value));
} }
} }
} }

+ 22
- 22
src/Discord.Net/API/Endpoints.cs View File

@@ -13,37 +13,37 @@
public const string AuthLogout = "auth/logout"; public const string AuthLogout = "auth/logout";
public const string Channels = "channels"; public const string Channels = "channels";
public static string Channel(long channelId) => $"channels/{channelId}";
public static string ChannelInvites(long channelId) => $"channels/{channelId}/invites";
public static string ChannelMessages(long channelId) => $"channels/{channelId}/messages";
public static string ChannelMessages(long channelId, int limit) => $"channels/{channelId}/messages?limit={limit}";
public static string ChannelMessages(long channelId, int limit, long relativeId, string relativeDir) => $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}";
public static string ChannelMessage(long channelId, long msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessageAck(long channelId, long msgId) => $"channels/{channelId}/messages/{msgId}/ack";
public static string ChannelPermission(long channelId, long userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}";
public static string ChannelTyping(long channelId) => $"channels/{channelId}/typing";
public static string Channel(ulong channelId) => $"channels/{channelId}";
public static string ChannelInvites(ulong channelId) => $"channels/{channelId}/invites";
public static string ChannelMessages(ulong channelId) => $"channels/{channelId}/messages";
public static string ChannelMessages(ulong channelId, int limit) => $"channels/{channelId}/messages?limit={limit}";
public static string ChannelMessages(ulong channelId, int limit, ulong relativeId, string relativeDir) => $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}";
public static string ChannelMessage(ulong channelId, ulong msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessageAck(ulong channelId, ulong msgId) => $"channels/{channelId}/messages/{msgId}/ack";
public static string ChannelPermission(ulong channelId, ulong userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}";
public static string ChannelTyping(ulong channelId) => $"channels/{channelId}/typing";


public const string Servers = "guilds"; public const string Servers = "guilds";
public static string Server(long serverId) => $"guilds/{serverId}";
public static string ServerBan(long serverId, long userId) => $"guilds/{serverId}/bans/{userId}";
public static string ServerChannels(long serverId) => $"guilds/{serverId}/channels";
public static string ServerInvites(long serverId) => $"guilds/{serverId}/invites";
public static string ServerMember(long serverId, long userId) => $"guilds/{serverId}/members/{userId}";
public static string ServerPrune(long serverId, int days) => $"guilds/{serverId}/prune?days={days}";
public static string ServerRoles(long serverId) => $"guilds/{serverId}/roles";
public static string ServerRole(long serverId, long roleId) => $"guilds/{serverId}/roles/{roleId}";
public static string ServerIcon(long serverId, string iconId) => BaseCdn + $"icons/{serverId}/{iconId}.jpg";
public static string Server(ulong serverId) => $"guilds/{serverId}";
public static string ServerBan(ulong serverId, ulong userId) => $"guilds/{serverId}/bans/{userId}";
public static string ServerChannels(ulong serverId) => $"guilds/{serverId}/channels";
public static string ServerInvites(ulong serverId) => $"guilds/{serverId}/invites";
public static string ServerMember(ulong serverId, ulong userId) => $"guilds/{serverId}/members/{userId}";
public static string ServerPrune(ulong serverId, int days) => $"guilds/{serverId}/prune?days={days}";
public static string ServerRoles(ulong serverId) => $"guilds/{serverId}/roles";
public static string ServerRole(ulong serverId, ulong roleId) => $"guilds/{serverId}/roles/{roleId}";
public static string ServerIcon(ulong serverId, string iconId) => BaseCdn + $"icons/{serverId}/{iconId}.jpg";


public const string Invites = "invite"; public const string Invites = "invite";
public static string Invite(long inviteId) => $"invite/{inviteId}";
public static string Invite(ulong inviteId) => $"invite/{inviteId}";
public static string Invite(string inviteIdOrXkcd) => $"invite/{inviteIdOrXkcd}"; public static string Invite(string inviteIdOrXkcd) => $"invite/{inviteIdOrXkcd}";
public static string InviteUrl(long inviteId) => $"https://discord.gg/{inviteId}";
public static string InviteUrl(ulong inviteId) => $"https://discord.gg/{inviteId}";
public static string InviteUrl(string inviteIdOrXkcd) => $"https://discord.gg/{inviteIdOrXkcd}"; public static string InviteUrl(string inviteIdOrXkcd) => $"https://discord.gg/{inviteIdOrXkcd}";


public const string Users = "users"; public const string Users = "users";
public static string UserMe => $"users/@me"; public static string UserMe => $"users/@me";
public static string UserChannels(long userId) => $"users/{userId}/channels";
public static string UserAvatar(long serverId, string avatarId) => BaseCdn + $"avatars/{serverId}/{avatarId}.jpg";
public static string UserChannels(ulong userId) => $"users/{userId}/channels";
public static string UserAvatar(ulong serverId, string avatarId) => BaseCdn + $"avatars/{serverId}/{avatarId}.jpg";


public const string Voice = "voice"; public const string Voice = "voice";
public const string VoiceRegions = "voice/regions"; public const string VoiceRegions = "voice/regions";


+ 6
- 6
src/Discord.Net/API/Messages/Channels.cs View File

@@ -14,10 +14,10 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long GuildId;
public ulong GuildId;
[JsonProperty("name")] [JsonProperty("name")]
public string Name; public string Name;
[JsonProperty("type")] [JsonProperty("type")]
@@ -31,7 +31,7 @@ namespace Discord.API
public string Type; public string Type;
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("deny")] [JsonProperty("deny")]
public uint Deny; public uint Deny;
[JsonProperty("allow")] [JsonProperty("allow")]
@@ -40,7 +40,7 @@ namespace Discord.API


[JsonProperty("last_message_id")] [JsonProperty("last_message_id")]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? LastMessageId;
public ulong? LastMessageId;
[JsonProperty("is_private")] [JsonProperty("is_private")]
public bool IsPrivate; public bool IsPrivate;
[JsonProperty("position")] [JsonProperty("position")]
@@ -65,7 +65,7 @@ namespace Discord.API
{ {
[JsonProperty("recipient_id")] [JsonProperty("recipient_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long RecipientId;
public ulong RecipientId;
} }
public class CreateChannelResponse : ChannelInfo { } public class CreateChannelResponse : ChannelInfo { }


@@ -89,7 +89,7 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("position")] [JsonProperty("position")]
public uint Position; public uint Position;
} }


+ 2
- 2
src/Discord.Net/API/Messages/GatewaySocket.cs View File

@@ -108,10 +108,10 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ServerId;
public ulong ServerId;
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ChannelId;
public ulong ChannelId;
[JsonProperty("self_mute")] [JsonProperty("self_mute")]
public string SelfMute; public string SelfMute;
[JsonProperty("self_deaf")] [JsonProperty("self_deaf")]


+ 1
- 1
src/Discord.Net/API/Messages/Maintenance.cs View File

@@ -19,7 +19,7 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("name")] [JsonProperty("name")]
public string Name; public string Name;
[JsonProperty("url")] [JsonProperty("url")]


+ 7
- 7
src/Discord.Net/API/Messages/Members.cs View File

@@ -14,11 +14,11 @@ namespace Discord.API
{ {
[JsonProperty("user_id")] [JsonProperty("user_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long UserId; //Used in bans
public ulong UserId; //Used in bans


[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long GuildId;
public ulong GuildId;
private UserReference _user; private UserReference _user;
[JsonProperty("user")] [JsonProperty("user")]
@@ -38,7 +38,7 @@ namespace Discord.API
public DateTime? JoinedAt; public DateTime? JoinedAt;
[JsonProperty("roles")] [JsonProperty("roles")]
[JsonConverter(typeof(LongStringArrayConverter))] [JsonConverter(typeof(LongStringArrayConverter))]
public long[] Roles;
public ulong[] Roles;
} }
public class ExtendedMemberInfo : MemberInfo public class ExtendedMemberInfo : MemberInfo
{ {
@@ -55,13 +55,13 @@ namespace Discord.API
public string Status; public string Status;
[JsonProperty("roles")] //TODO: Might be temporary [JsonProperty("roles")] //TODO: Might be temporary
[JsonConverter(typeof(LongStringArrayConverter))] [JsonConverter(typeof(LongStringArrayConverter))]
public long[] Roles;
public ulong[] Roles;
} }
public class VoiceMemberInfo : MemberReference public class VoiceMemberInfo : MemberReference
{ {
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? ChannelId;
public ulong? ChannelId;
[JsonProperty("session_id")] [JsonProperty("session_id")]
public string SessionId; public string SessionId;
[JsonProperty("token")] [JsonProperty("token")]
@@ -87,10 +87,10 @@ namespace Discord.API
public bool? Deaf; public bool? Deaf;
[JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? ChannelId;
public ulong? ChannelId;
[JsonProperty("roles", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("roles", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(LongStringEnumerableConverter))] [JsonConverter(typeof(LongStringEnumerableConverter))]
public IEnumerable<long> Roles;
public IEnumerable<ulong> Roles;
} }


public class PruneUsersResponse public class PruneUsersResponse


+ 6
- 6
src/Discord.Net/API/Messages/Messages.cs View File

@@ -14,13 +14,13 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ChannelId;
public ulong ChannelId;
[JsonProperty("message_id")] [JsonProperty("message_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long MessageId { get { return Id; } set { Id = value; } }
public ulong MessageId { get { return Id; } set { Id = value; } }
} }
public class MessageInfo : MessageReference public class MessageInfo : MessageReference
{ {
@@ -109,7 +109,7 @@ namespace Discord.API
public string Content; public string Content;
[JsonProperty("mentions")] [JsonProperty("mentions")]
[JsonConverter(typeof(LongStringEnumerableConverter))] [JsonConverter(typeof(LongStringEnumerableConverter))]
public IEnumerable<long> Mentions;
public IEnumerable<ulong> Mentions;
[JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
public string Nonce; public string Nonce;
[JsonProperty("tts", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("tts", NullValueHandling = NullValueHandling.Ignore)]
@@ -124,7 +124,7 @@ namespace Discord.API
public string Content; public string Content;
[JsonProperty("mentions", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("mentions", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(LongStringEnumerableConverter))] [JsonConverter(typeof(LongStringEnumerableConverter))]
public IEnumerable<long> Mentions;
public IEnumerable<ulong> Mentions;
} }
public sealed class EditMessageResponse : MessageInfo { } public sealed class EditMessageResponse : MessageInfo { }


@@ -139,7 +139,7 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ServerId;
public ulong ServerId;
[JsonProperty("query")] [JsonProperty("query")]
public string Query; public string Query;
[JsonProperty("limit")] [JsonProperty("limit")]


+ 1
- 1
src/Discord.Net/API/Messages/Permissions.cs View File

@@ -12,7 +12,7 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("type")] [JsonProperty("type")]
public string Type; public string Type;
[JsonProperty("allow")] [JsonProperty("allow")]


+ 6
- 6
src/Discord.Net/API/Messages/Roles.cs View File

@@ -14,16 +14,16 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long GuildId;
public ulong GuildId;
[JsonProperty("role_id")] [JsonProperty("role_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long RoleId;
public ulong RoleId;
} }
public class RoleInfo public class RoleInfo
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("permissions")] [JsonProperty("permissions")]
public uint? Permissions; public uint? Permissions;
[JsonProperty("name")] [JsonProperty("name")]
@@ -62,7 +62,7 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("position")] [JsonProperty("position")]
public uint Position; public uint Position;
} }
@@ -78,7 +78,7 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long GuildId;
public ulong GuildId;
[JsonProperty("role")] [JsonProperty("role")]
public RoleInfo Data; public RoleInfo Data;
} }
@@ -86,7 +86,7 @@ namespace Discord.API
{ {
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long GuildId;
public ulong GuildId;
[JsonProperty("role")] [JsonProperty("role")]
public RoleInfo Data; public RoleInfo Data;
} }


+ 5
- 5
src/Discord.Net/API/Messages/Servers.cs View File

@@ -14,7 +14,7 @@ namespace Discord.API
{ {
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("name")] [JsonProperty("name")]
public string Name; public string Name;
} }
@@ -22,12 +22,12 @@ namespace Discord.API
{ {
[JsonProperty("afk_channel_id")] [JsonProperty("afk_channel_id")]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? AFKChannelId;
public ulong? AFKChannelId;
[JsonProperty("afk_timeout")] [JsonProperty("afk_timeout")]
public int? AFKTimeout; public int? AFKTimeout;
[JsonProperty("embed_channel_id")] [JsonProperty("embed_channel_id")]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? EmbedChannelId;
public ulong? EmbedChannelId;
[JsonProperty("embed_enabled")] [JsonProperty("embed_enabled")]
public bool EmbedEnabled; public bool EmbedEnabled;
[JsonProperty("icon")] [JsonProperty("icon")]
@@ -36,7 +36,7 @@ namespace Discord.API
public DateTime? JoinedAt; public DateTime? JoinedAt;
[JsonProperty("owner_id")] [JsonProperty("owner_id")]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? OwnerId;
public ulong? OwnerId;
[JsonProperty("region")] [JsonProperty("region")]
public string Region; public string Region;
[JsonProperty("roles")] [JsonProperty("roles")]
@@ -77,7 +77,7 @@ namespace Discord.API
public string Icon; public string Icon;
[JsonProperty("afk_channel_id", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("afk_channel_id", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(NullableLongStringConverter))] [JsonConverter(typeof(NullableLongStringConverter))]
public long? AFKChannelId;
public ulong? AFKChannelId;
[JsonProperty("afk_timeout", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("afk_timeout", NullValueHandling = NullValueHandling.Ignore)]
public int AFKTimeout; public int AFKTimeout;
} }


+ 4
- 4
src/Discord.Net/API/Messages/Users.cs View File

@@ -14,9 +14,9 @@ namespace Discord.API
public string Username; public string Username;
[JsonProperty("id")] [JsonProperty("id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long Id;
public ulong Id;
[JsonProperty("discriminator")] [JsonProperty("discriminator")]
public short? Discriminator;
public ushort? Discriminator;
[JsonProperty("avatar")] [JsonProperty("avatar")]
public string Avatar; public string Avatar;
} }
@@ -51,10 +51,10 @@ namespace Discord.API
{ {
[JsonProperty("user_id")] [JsonProperty("user_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long UserId;
public ulong UserId;
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
[JsonConverter(typeof(LongStringConverter))] [JsonConverter(typeof(LongStringConverter))]
public long ChannelId;
public ulong ChannelId;
[JsonProperty("timestamp")] [JsonProperty("timestamp")]
public int Timestamp; public int Timestamp;
} }


+ 30
- 91
src/Discord.Net/DiscordAPIClient.cs View File

@@ -55,39 +55,30 @@ namespace Discord
=> _rest.Post(Endpoints.AuthLogout); => _rest.Post(Endpoints.AuthLogout);


//Channels //Channels
public Task<CreateChannelResponse> CreateChannel(long serverId, string name, string channelType)
public Task<CreateChannelResponse> CreateChannel(ulong serverId, string name, string channelType)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(nameof(name));
if (channelType == null) throw new ArgumentNullException(nameof(channelType)); if (channelType == null) throw new ArgumentNullException(nameof(channelType));


var request = new CreateChannelRequest { Name = name, Type = channelType }; var request = new CreateChannelRequest { Name = name, Type = channelType };
return _rest.Post<CreateChannelResponse>(Endpoints.ServerChannels(serverId), request); return _rest.Post<CreateChannelResponse>(Endpoints.ServerChannels(serverId), request);
} }
public Task<CreateChannelResponse> CreatePMChannel(long myId, long recipientId)
public Task<CreateChannelResponse> CreatePMChannel(ulong myId, ulong recipientId)
{ {
if (myId <= 0) throw new ArgumentOutOfRangeException(nameof(myId));
if (recipientId <= 0) throw new ArgumentOutOfRangeException(nameof(recipientId));

var request = new CreatePMChannelRequest { RecipientId = recipientId }; var request = new CreatePMChannelRequest { RecipientId = recipientId };
return _rest.Post<CreateChannelResponse>(Endpoints.UserChannels(myId), request); return _rest.Post<CreateChannelResponse>(Endpoints.UserChannels(myId), request);
} }
public Task<DestroyChannelResponse> DestroyChannel(long channelId)
public Task<DestroyChannelResponse> DestroyChannel(ulong channelId)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

return _rest.Delete<DestroyChannelResponse>(Endpoints.Channel(channelId)); return _rest.Delete<DestroyChannelResponse>(Endpoints.Channel(channelId));
} }
public Task<EditChannelResponse> EditChannel(long channelId, string name = null, string topic = null)
public Task<EditChannelResponse> EditChannel(ulong channelId, string name = null, string topic = null)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

var request = new EditChannelRequest { Name = name, Topic = topic }; var request = new EditChannelRequest { Name = name, Topic = topic };
return _rest.Patch<EditChannelResponse>(Endpoints.Channel(channelId), request); return _rest.Patch<EditChannelResponse>(Endpoints.Channel(channelId), request);
} }
public Task ReorderChannels(long serverId, IEnumerable<long> channelIds, int startPos = 0)
public Task ReorderChannels(ulong serverId, IEnumerable<ulong> channelIds, int startPos = 0)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (channelIds == null) throw new ArgumentNullException(nameof(channelIds)); if (channelIds == null) throw new ArgumentNullException(nameof(channelIds));
if (startPos < 0) throw new ArgumentOutOfRangeException(nameof(startPos), "startPos must be a positive integer."); if (startPos < 0) throw new ArgumentOutOfRangeException(nameof(startPos), "startPos must be a positive integer.");


@@ -96,10 +87,8 @@ namespace Discord
var request = new ReorderChannelsRequest(channels); var request = new ReorderChannelsRequest(channels);
return _rest.Patch(Endpoints.ServerChannels(serverId), request); return _rest.Patch(Endpoints.ServerChannels(serverId), request);
} }
public Task<GetMessagesResponse> GetMessages(long channelId, int count, long? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before)
public Task<GetMessagesResponse> GetMessages(ulong channelId, int count, ulong? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

if (relativeMessageId != null) if (relativeMessageId != null)
return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count, relativeMessageId.Value, relativeDir == RelativeDirection.Before ? "before" : "after")); return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count, relativeMessageId.Value, relativeDir == RelativeDirection.Before ? "before" : "after"));
else else
@@ -117,10 +106,8 @@ namespace Discord
} }


//Invites //Invites
public Task<CreateInviteResponse> CreateInvite(long channelId, int maxAge, int maxUses, bool tempMembership, bool hasXkcd)
public Task<CreateInviteResponse> CreateInvite(ulong channelId, int maxAge, int maxUses, bool tempMembership, bool hasXkcd)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

var request = new CreateInviteRequest { MaxAge = maxAge, MaxUses = maxUses, IsTemporary = tempMembership, WithXkcdPass = hasXkcd }; var request = new CreateInviteRequest { MaxAge = maxAge, MaxUses = maxUses, IsTemporary = tempMembership, WithXkcdPass = hasXkcd };
return _rest.Post<CreateInviteResponse>(Endpoints.ChannelInvites(channelId), request); return _rest.Post<CreateInviteResponse>(Endpoints.ChannelInvites(channelId), request);
} }
@@ -130,10 +117,8 @@ namespace Discord


return _rest.Get<GetInviteResponse>(Endpoints.Invite(inviteIdOrXkcd)); return _rest.Get<GetInviteResponse>(Endpoints.Invite(inviteIdOrXkcd));
} }
public Task<GetInvitesResponse> GetInvites(long serverId)
public Task<GetInvitesResponse> GetInvites(ulong serverId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));

return _rest.Get<GetInvitesResponse>(Endpoints.ServerInvites(serverId)); return _rest.Get<GetInvitesResponse>(Endpoints.ServerInvites(serverId));
} }
public Task<AcceptInviteResponse> AcceptInvite(string inviteId) public Task<AcceptInviteResponse> AcceptInvite(string inviteId)
@@ -150,40 +135,25 @@ namespace Discord
} }


//Users //Users
public Task EditUser(long serverId, long userId, bool? mute = null, bool? deaf = null, long? voiceChannelId = null, IEnumerable<long> roleIds = null)
public Task EditUser(ulong serverId, ulong userId, bool? mute = null, bool? deaf = null, ulong? voiceChannelId = null, IEnumerable<ulong> roleIds = null)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));

var request = new EditMemberRequest { Mute = mute, Deaf = deaf, ChannelId = voiceChannelId, Roles = roleIds }; var request = new EditMemberRequest { Mute = mute, Deaf = deaf, ChannelId = voiceChannelId, Roles = roleIds };
return _rest.Patch(Endpoints.ServerMember(serverId, userId), request); return _rest.Patch(Endpoints.ServerMember(serverId, userId), request);
} }
public Task KickUser(long serverId, long userId)
public Task KickUser(ulong serverId, ulong userId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));

return _rest.Delete(Endpoints.ServerMember(serverId, userId)); return _rest.Delete(Endpoints.ServerMember(serverId, userId));
} }
public Task BanUser(long serverId, long userId)
public Task BanUser(ulong serverId, ulong userId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));

return _rest.Put(Endpoints.ServerBan(serverId, userId)); return _rest.Put(Endpoints.ServerBan(serverId, userId));
} }
public Task UnbanUser(long serverId, long userId)
public Task UnbanUser(ulong serverId, ulong userId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));

return _rest.Delete(Endpoints.ServerBan(serverId, userId)); return _rest.Delete(Endpoints.ServerBan(serverId, userId));
} }
public Task<PruneUsersResponse> PruneUsers(long serverId, int days, bool simulate)
{
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (days <= 0) throw new ArgumentOutOfRangeException(nameof(days));
public Task<PruneUsersResponse> PruneUsers(ulong serverId, int days, bool simulate)
{
if (simulate) if (simulate)
return _rest.Get<PruneUsersResponse>(Endpoints.ServerPrune(serverId, days)); return _rest.Get<PruneUsersResponse>(Endpoints.ServerPrune(serverId, days));
else else
@@ -191,94 +161,67 @@ namespace Discord
} }


//Messages //Messages
public Task<SendMessageResponse> SendMessage(long channelId, string message, IEnumerable<long> mentionedUserIds = null, string nonce = null, bool isTTS = false)
public Task<SendMessageResponse> SendMessage(ulong channelId, string message, IEnumerable<ulong> mentionedUserIds = null, string nonce = null, bool isTTS = false)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));
if (message == null) throw new ArgumentNullException(nameof(message)); if (message == null) throw new ArgumentNullException(nameof(message));


var request = new SendMessageRequest { Content = message, Mentions = mentionedUserIds ?? new long[0], Nonce = nonce, IsTTS = isTTS ? true : false };
var request = new SendMessageRequest { Content = message, Mentions = mentionedUserIds ?? new ulong[0], Nonce = nonce, IsTTS = isTTS ? true : false };
return _rest.Post<SendMessageResponse>(Endpoints.ChannelMessages(channelId), request); return _rest.Post<SendMessageResponse>(Endpoints.ChannelMessages(channelId), request);
} }
public Task<SendMessageResponse> SendFile(long channelId, string filename, Stream stream)
public Task<SendMessageResponse> SendFile(ulong channelId, string filename, Stream stream)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));
if (filename == null) throw new ArgumentNullException(nameof(filename)); if (filename == null) throw new ArgumentNullException(nameof(filename));
if (stream == null) throw new ArgumentNullException(nameof(stream)); if (stream == null) throw new ArgumentNullException(nameof(stream));


return _rest.PostFile<SendMessageResponse>(Endpoints.ChannelMessages(channelId), filename, stream); return _rest.PostFile<SendMessageResponse>(Endpoints.ChannelMessages(channelId), filename, stream);
} }
public Task DeleteMessage(long messageId, long channelId)
public Task DeleteMessage(ulong messageId, ulong channelId)
{ {
if (messageId <= 0) throw new ArgumentOutOfRangeException(nameof(messageId));
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

return _rest.Delete(Endpoints.ChannelMessage(channelId, messageId)); return _rest.Delete(Endpoints.ChannelMessage(channelId, messageId));
} }
public Task<EditMessageResponse> EditMessage(long messageId, long channelId, string message = null, IEnumerable<long> mentionedUserIds = null)
public Task<EditMessageResponse> EditMessage(ulong messageId, ulong channelId, string message = null, IEnumerable<ulong> mentionedUserIds = null)
{ {
if (messageId <= 0) throw new ArgumentOutOfRangeException(nameof(messageId));
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

var request = new EditMessageRequest { Content = message, Mentions = mentionedUserIds }; var request = new EditMessageRequest { Content = message, Mentions = mentionedUserIds };
return _rest.Patch<EditMessageResponse>(Endpoints.ChannelMessage(channelId, messageId), request); return _rest.Patch<EditMessageResponse>(Endpoints.ChannelMessage(channelId, messageId), request);
} }
public Task AckMessage(long messageId, long channelId)
public Task AckMessage(ulong messageId, ulong channelId)
{ {
if (messageId <= 0) throw new ArgumentOutOfRangeException(nameof(messageId));
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

return _rest.Post(Endpoints.ChannelMessageAck(channelId, messageId)); return _rest.Post(Endpoints.ChannelMessageAck(channelId, messageId));
} }
public Task SendIsTyping(long channelId)
public Task SendIsTyping(ulong channelId)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));

return _rest.Post(Endpoints.ChannelTyping(channelId)); return _rest.Post(Endpoints.ChannelTyping(channelId));
} }


//Permissions //Permissions
public Task SetChannelPermissions(long channelId, long userOrRoleId, string idType, uint allow = 0, uint deny = 0)
public Task SetChannelPermissions(ulong channelId, ulong userOrRoleId, string idType, uint allow = 0, uint deny = 0)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));
if (userOrRoleId <= 0) throw new ArgumentOutOfRangeException(nameof(userOrRoleId));
if (idType == null) throw new ArgumentNullException(nameof(idType)); if (idType == null) throw new ArgumentNullException(nameof(idType));


var request = new SetChannelPermissionsRequest { Id = userOrRoleId, Type = idType, Allow = allow, Deny = deny }; var request = new SetChannelPermissionsRequest { Id = userOrRoleId, Type = idType, Allow = allow, Deny = deny };
return _rest.Put(Endpoints.ChannelPermission(channelId, userOrRoleId), request); return _rest.Put(Endpoints.ChannelPermission(channelId, userOrRoleId), request);
} }
public Task DeleteChannelPermissions(long channelId, long userOrRoleId)
public Task DeleteChannelPermissions(ulong channelId, ulong userOrRoleId)
{ {
if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId));
if (userOrRoleId <= 0) throw new ArgumentOutOfRangeException(nameof(userOrRoleId));

return _rest.Delete(Endpoints.ChannelPermission(channelId, userOrRoleId), null); return _rest.Delete(Endpoints.ChannelPermission(channelId, userOrRoleId), null);
} }


//Roles //Roles
public Task<RoleInfo> CreateRole(long serverId)
{
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
public Task<RoleInfo> CreateRole(ulong serverId)
{
return _rest.Post<RoleInfo>(Endpoints.ServerRoles(serverId)); return _rest.Post<RoleInfo>(Endpoints.ServerRoles(serverId));
} }
public Task DeleteRole(long serverId, long roleId)
public Task DeleteRole(ulong serverId, ulong roleId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (roleId <= 0) throw new ArgumentOutOfRangeException(nameof(roleId));

return _rest.Delete(Endpoints.ServerRole(serverId, roleId)); return _rest.Delete(Endpoints.ServerRole(serverId, roleId));
} }
public Task<RoleInfo> EditRole(long serverId, long roleId, string name = null, uint? permissions = null, uint? color = null, bool? hoist = null)
public Task<RoleInfo> EditRole(ulong serverId, ulong roleId, string name = null, uint? permissions = null, uint? color = null, bool? hoist = null)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (roleId <= 0) throw new ArgumentOutOfRangeException(nameof(roleId));

var request = new EditRoleRequest { Name = name, Permissions = permissions, Hoist = hoist, Color = color }; var request = new EditRoleRequest { Name = name, Permissions = permissions, Hoist = hoist, Color = color };
return _rest.Patch<RoleInfo>(Endpoints.ServerRole(serverId, roleId), request); return _rest.Patch<RoleInfo>(Endpoints.ServerRole(serverId, roleId), request);
} }
public Task ReorderRoles(long serverId, IEnumerable<long> roleIds, int startPos = 0)
public Task ReorderRoles(ulong serverId, IEnumerable<ulong> roleIds, int startPos = 0)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));
if (roleIds == null) throw new ArgumentNullException(nameof(roleIds)); if (roleIds == null) throw new ArgumentNullException(nameof(roleIds));
if (startPos < 0) throw new ArgumentOutOfRangeException(nameof(startPos), "startPos must be a positive integer."); if (startPos < 0) throw new ArgumentOutOfRangeException(nameof(startPos), "startPos must be a positive integer.");


@@ -297,17 +240,13 @@ namespace Discord
var request = new CreateServerRequest { Name = name, Region = region }; var request = new CreateServerRequest { Name = name, Region = region };
return _rest.Post<CreateServerResponse>(Endpoints.Servers, request); return _rest.Post<CreateServerResponse>(Endpoints.Servers, request);
} }
public Task LeaveServer(long serverId)
public Task LeaveServer(ulong serverId)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));

return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId)); return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId));
} }
public Task<EditServerResponse> EditServer(long serverId, string name = null, string region = null,
public Task<EditServerResponse> EditServer(ulong serverId, string name = null, string region = null,
Stream icon = null, ImageType iconType = ImageType.Png, string existingIcon = null) Stream icon = null, ImageType iconType = ImageType.Png, string existingIcon = null)
{ {
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));

var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(icon, iconType, existingIcon) }; var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(icon, iconType, existingIcon) };
return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request); return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request);
} }


+ 7
- 8
src/Discord.Net/DiscordClient.Channels.cs View File

@@ -8,15 +8,15 @@ using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
internal sealed class Channels : AsyncCollection<long, Channel>
internal sealed class Channels : AsyncCollection<ulong, Channel>
{ {
public IEnumerable<Channel> PrivateChannels => _privateChannels.Select(x => x.Value); public IEnumerable<Channel> PrivateChannels => _privateChannels.Select(x => x.Value);
private ConcurrentDictionary<long, Channel> _privateChannels;
private ConcurrentDictionary<ulong, Channel> _privateChannels;


public Channels(DiscordClient client, object writerLock) public Channels(DiscordClient client, object writerLock)
: base(client, writerLock) : base(client, writerLock)
{ {
_privateChannels = new ConcurrentDictionary<long, Channel>();
_privateChannels = new ConcurrentDictionary<ulong, Channel>();
ItemCreated += (s, e) => ItemCreated += (s, e) =>
{ {
if (e.Item.IsPrivate) if (e.Item.IsPrivate)
@@ -33,7 +33,7 @@ namespace Discord
Cleared += (s, e) => _privateChannels.Clear(); Cleared += (s, e) => _privateChannels.Clear();
} }
public Channel GetOrAdd(long id, long? serverId, long? recipientId = null)
public Channel GetOrAdd(ulong id, ulong? serverId, ulong? recipientId = null)
=> GetOrAdd(id, () => new Channel(_client, id, serverId, recipientId)); => GetOrAdd(id, () => new Channel(_client, id, serverId, recipientId));
} }


@@ -72,9 +72,8 @@ namespace Discord
private readonly Channels _channels; private readonly Channels _channels;


/// <summary> Returns the channel with the specified id, or null if none was found. </summary> /// <summary> Returns the channel with the specified id, or null if none was found. </summary>
public Channel GetChannel(long id)
public Channel GetChannel(ulong id)
{ {
if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id));
CheckReady(); CheckReady();


return _channels[id]; return _channels[id];
@@ -94,7 +93,7 @@ namespace Discord
{ {
if (name[0] == '<' && name[1] == '#' && name[name.Length - 1] == '>') //Parse mention if (name[0] == '<' && name[1] == '#' && name[name.Length - 1] == '>') //Parse mention
{ {
long id = IdConvert.ToLong(name.Substring(2, name.Length - 3));
var id = IdConvert.ToLong(name.Substring(2, name.Length - 3));
var channel = _channels[id]; var channel = _channels[id];
if (channel != null) if (channel != null)
query = query.Concat(new Channel[] { channel }); query = query.Concat(new Channel[] { channel });
@@ -136,7 +135,7 @@ namespace Discord
channel = user.Global.PrivateChannel; channel = user.Global.PrivateChannel;
if (channel == null) if (channel == null)
{ {
var response = await _api.CreatePMChannel(_privateUser.Id, user.Id).ConfigureAwait(false);
var response = await _api.CreatePMChannel(_currentUser.Id, user.Id).ConfigureAwait(false);
var recipient = _users.GetOrAdd(response.Recipient.Id, null); var recipient = _users.GetOrAdd(response.Recipient.Id, null);
recipient.Update(response.Recipient); recipient.Update(response.Recipient);
channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient.Id); channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient.Id);


+ 3
- 6
src/Discord.Net/DiscordClient.Invites.cs View File

@@ -24,8 +24,7 @@ namespace Discord
inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1);


var response = await _api.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); var response = await _api.GetInvite(inviteIdOrXkcd).ConfigureAwait(false);
var invite = new Invite(this, response.Code, response.XkcdPass);
invite.Cache(); //Builds references
var invite = new Invite(response.Code, response.XkcdPass);
invite.Update(response); invite.Update(response);
return invite; return invite;
} }
@@ -39,8 +38,7 @@ namespace Discord
var response = await _api.GetInvites(server.Id).ConfigureAwait(false); var response = await _api.GetInvites(server.Id).ConfigureAwait(false);
return response.Select(x => return response.Select(x =>
{ {
var invite = new Invite(this, x.Code, x.XkcdPass);
invite.Cache(); //Builds references
var invite = new Invite(x.Code, x.XkcdPass);
invite.Update(x); invite.Update(x);
return invite; return invite;
}).ToArray(); }).ToArray();
@@ -72,8 +70,7 @@ namespace Discord


var response = await _api.CreateInvite(channel.Id, maxAge: maxAge, maxUses: maxUses, var response = await _api.CreateInvite(channel.Id, maxAge: maxAge, maxUses: maxUses,
tempMembership: tempMembership, hasXkcd: hasXkcd).ConfigureAwait(false); tempMembership: tempMembership, hasXkcd: hasXkcd).ConfigureAwait(false);
var invite = new Invite(this, response.Code, response.XkcdPass);
invite.Cache(); //Builds references
var invite = new Invite(response.Code, response.XkcdPass);
return invite; return invite;
} }




+ 14
- 15
src/Discord.Net/DiscordClient.Messages.cs View File

@@ -12,7 +12,7 @@ using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
internal sealed class Messages : AsyncCollection<long, Message>
internal sealed class Messages : AsyncCollection<ulong, Message>
{ {
private bool _isEnabled; private bool _isEnabled;


@@ -22,7 +22,7 @@ namespace Discord
_isEnabled = isEnabled; _isEnabled = isEnabled;
} }
public Message GetOrAdd(long id, long channelId, long userId)
public Message GetOrAdd(ulong id, ulong channelId, ulong userId)
{ {
if (_isEnabled) if (_isEnabled)
return GetOrAdd(id, () => new Message(_client, id, channelId, userId)); return GetOrAdd(id, () => new Message(_client, id, channelId, userId));
@@ -33,7 +33,7 @@ namespace Discord
return msg; return msg;
} }
} }
public void Import(Dictionary<long, Message> messages)
public void Import(Dictionary<ulong, Message> messages)
=> base.Import(messages); => base.Import(messages);
} }


@@ -41,8 +41,8 @@ namespace Discord
{ {
public readonly Message Message; public readonly Message Message;
public readonly string Text; public readonly string Text;
public readonly long[] MentionedUsers;
public MessageQueueItem(Message msg, string text, long[] userIds)
public readonly ulong[] MentionedUsers;
public MessageQueueItem(Message msg, string text, ulong[] userIds)
{ {
Message = msg; Message = msg;
Text = text; Text = text;
@@ -102,7 +102,7 @@ namespace Discord
private readonly ConcurrentQueue<MessageQueueItem> _pendingMessages; private readonly ConcurrentQueue<MessageQueueItem> _pendingMessages;


/// <summary> Returns the message with the specified id, or null if none was found. </summary> /// <summary> Returns the message with the specified id, or null if none was found. </summary>
public Message GetMessage(long id)
public Message GetMessage(ulong id)
{ {
if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id)); if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id));
CheckReady(); CheckReady();
@@ -195,13 +195,13 @@ namespace Discord
if (Config.UseMessageQueue) if (Config.UseMessageQueue)
{ {
var nonce = GenerateNonce(); var nonce = GenerateNonce();
msg = _messages.GetOrAdd(nonce, channel.Id, _privateUser.Id);
msg = new Message(this, 0, channel.Id, _currentUser.Id); //_messages.GetOrAdd(nonce, channel.Id, _privateUser.Id);
var currentUser = msg.User; var currentUser = msg.User;
msg.Update(new MessageInfo msg.Update(new MessageInfo
{ {
Content = text, Content = text,
Timestamp = DateTime.UtcNow, Timestamp = DateTime.UtcNow,
Author = new UserReference { Avatar = currentUser.AvatarId, Discriminator = currentUser.Discriminator, Id = _privateUser.Id, Username = currentUser.Name },
Author = new UserReference { Avatar = currentUser.AvatarId, Discriminator = currentUser.Discriminator, Id = _currentUser.Id, Username = currentUser.Name },
ChannelId = channel.Id, ChannelId = channel.Id,
Nonce = IdConvert.ToString(nonce), Nonce = IdConvert.ToString(nonce),
IsTextToSpeech = isTextToSpeech IsTextToSpeech = isTextToSpeech
@@ -270,7 +270,7 @@ namespace Discord
} }


/// <summary> Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. </summary> /// <summary> Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. </summary>
public async Task<Message[]> DownloadMessages(Channel channel, int count, long? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool useCache = true)
public async Task<Message[]> DownloadMessages(Channel channel, int count, ulong? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool useCache = true)
{ {
if (channel == null) throw new ArgumentNullException(nameof(channel)); if (channel == null) throw new ArgumentNullException(nameof(channel));
if (count < 0) throw new ArgumentNullException(nameof(count)); if (count < 0) throw new ArgumentNullException(nameof(count));
@@ -322,9 +322,9 @@ namespace Discord
.Select(x => .Select(x =>
{ {
var msg = new Message(this, var msg = new Message(this,
x["Id"].Value<long>(),
x["Id"].Value<ulong>(),
channel.Id, channel.Id,
x["UserId"].Value<long>());
x["UserId"].Value<ulong>());


var reader = x.CreateReader(); var reader = x.CreateReader();
_messageImporter.Populate(reader, msg); _messageImporter.Populate(reader, msg);
@@ -366,7 +366,7 @@ namespace Discord
var msg = queuedMessage.Message; var msg = queuedMessage.Message;
try try
{ {
if (msg.Id < 0)
if (msg.Id == 0)
{ {
await _api.SendMessage( await _api.SendMessage(
msg.Channel.Id, msg.Channel.Id,
@@ -375,7 +375,6 @@ namespace Discord
IdConvert.ToString(msg.Id), //Nonce IdConvert.ToString(msg.Id), //Nonce
msg.IsTTS) msg.IsTTS)
.ConfigureAwait(false); .ConfigureAwait(false);
RaiseMessageSent(msg);
} }
else else
{ {
@@ -394,10 +393,10 @@ namespace Discord
} }
}); });
} }
private long GenerateNonce()
private ulong GenerateNonce()
{ {
lock (_nonceRand) lock (_nonceRand)
return -_nonceRand.Next(1, int.MaxValue - 1);
return (ulong)_nonceRand.Next(1, int.MaxValue);
} }
} }
} }

+ 2
- 2
src/Discord.Net/DiscordClient.Permissions.cs View File

@@ -63,7 +63,7 @@ namespace Discord


return SetChannelPermissions(channel, role.Id, PermissionTarget.Role, permissions?.Allow, permissions?.Deny); return SetChannelPermissions(channel, role.Id, PermissionTarget.Role, permissions?.Allow, permissions?.Deny);
} }
private Task SetChannelPermissions(Channel channel, long targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
private Task SetChannelPermissions(Channel channel, ulong targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
=> _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0); => _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0);


public Task RemoveChannelPermissions(Channel channel, User user) public Task RemoveChannelPermissions(Channel channel, User user)
@@ -82,7 +82,7 @@ namespace Discord


return RemoveChannelPermissions(channel, role.Id, PermissionTarget.Role); return RemoveChannelPermissions(channel, role.Id, PermissionTarget.Role);
} }
private async Task RemoveChannelPermissions(Channel channel, long userOrRoleId, PermissionTarget targetType)
private async Task RemoveChannelPermissions(Channel channel, ulong userOrRoleId, PermissionTarget targetType)
{ {
try try
{ {


+ 3
- 4
src/Discord.Net/DiscordClient.Roles.cs View File

@@ -7,12 +7,12 @@ using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
internal sealed class Roles : AsyncCollection<long, Role>
internal sealed class Roles : AsyncCollection<ulong, Role>
{ {
public Roles(DiscordClient client, object writerLock) public Roles(DiscordClient client, object writerLock)
: base(client, writerLock) { } : base(client, writerLock) { }
public Role GetOrAdd(long id, long serverId)
public Role GetOrAdd(ulong id, ulong serverId)
=> GetOrAdd(id, () => new Role(_client, id, serverId)); => GetOrAdd(id, () => new Role(_client, id, serverId));
} }


@@ -49,9 +49,8 @@ namespace Discord
private readonly Roles _roles; private readonly Roles _roles;


/// <summary> Returns the role with the specified id, or null if none was found. </summary> /// <summary> Returns the role with the specified id, or null if none was found. </summary>
public Role GetRole(long id)
public Role GetRole(ulong id)
{ {
if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id));
CheckReady(); CheckReady();


return _roles[id]; return _roles[id];


+ 3
- 4
src/Discord.Net/DiscordClient.Servers.cs View File

@@ -8,12 +8,12 @@ using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
internal sealed class Servers : AsyncCollection<long, Server>
internal sealed class Servers : AsyncCollection<ulong, Server>
{ {
public Servers(DiscordClient client, object writerLock) public Servers(DiscordClient client, object writerLock)
: base(client, writerLock) { } : base(client, writerLock) { }
public Server GetOrAdd(long id)
public Server GetOrAdd(ulong id)
=> GetOrAdd(id, () => new Server(_client, id)); => GetOrAdd(id, () => new Server(_client, id));
} }


@@ -63,9 +63,8 @@ namespace Discord
private readonly Servers _servers; private readonly Servers _servers;


/// <summary> Returns the server with the specified id, or null if none was found. </summary> /// <summary> Returns the server with the specified id, or null if none was found. </summary>
public Server GetServer(long id)
public Server GetServer(ulong id)
{ {
if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id));
CheckReady(); CheckReady();


return _servers[id]; return _servers[id];


+ 24
- 26
src/Discord.Net/DiscordClient.Users.cs View File

@@ -8,12 +8,12 @@ using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
internal sealed class GlobalUsers : AsyncCollection<long, GlobalUser>
internal sealed class GlobalUsers : AsyncCollection<ulong, GlobalUser>
{ {
public GlobalUsers(DiscordClient client, object writerLock) public GlobalUsers(DiscordClient client, object writerLock)
: base(client, writerLock) { } : base(client, writerLock) { }


public GlobalUser GetOrAdd(long id) => GetOrAdd(id, () => new GlobalUser(_client, id));
public GlobalUser GetOrAdd(ulong id) => GetOrAdd(id, () => new GlobalUser(_client, id));
} }
internal sealed class Users : AsyncCollection<User.CompositeKey, User> internal sealed class Users : AsyncCollection<User.CompositeKey, User>
{ {
@@ -21,11 +21,11 @@ namespace Discord
: base(client, writerLock) : base(client, writerLock)
{ } { }


public User this[long userId, long? serverId]
public User this[ulong userId, ulong? serverId]
=> base[new User.CompositeKey(userId, serverId)]; => base[new User.CompositeKey(userId, serverId)];
public User GetOrAdd(long userId, long? serverId)
public User GetOrAdd(ulong userId, ulong? serverId)
=> GetOrAdd(new User.CompositeKey(userId, serverId), () => new User(_client, userId, serverId)); => GetOrAdd(new User.CompositeKey(userId, serverId), () => new User(_client, userId, serverId));
public User TryRemove(long userId, long? serverId)
public User TryRemove(ulong userId, ulong? serverId)
=> TryRemove(new User.CompositeKey(userId, serverId)); => TryRemove(new User.CompositeKey(userId, serverId));
} }


@@ -48,10 +48,10 @@ namespace Discord
} }
public class BanEventArgs : EventArgs public class BanEventArgs : EventArgs
{ {
public long UserId { get; }
public ulong UserId { get; }
public Server Server { get; } public Server Server { get; }


public BanEventArgs(long userId, Server server)
public BanEventArgs(ulong userId, Server server)
{ {
UserId = userId; UserId = userId;
Server = server; Server = server;
@@ -103,13 +103,13 @@ namespace Discord
EventHelper.Raise(_logger, nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty)); EventHelper.Raise(_logger, nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty));
} }
public event EventHandler<BanEventArgs> UserBanned; public event EventHandler<BanEventArgs> UserBanned;
private void RaiseUserBanned(long userId, Server server)
private void RaiseUserBanned(ulong userId, Server server)
{ {
if (UserBanned != null) if (UserBanned != null)
EventHelper.Raise(_logger, nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server))); EventHelper.Raise(_logger, nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server)));
} }
public event EventHandler<BanEventArgs> UserUnbanned; public event EventHandler<BanEventArgs> UserUnbanned;
private void RaiseUserUnbanned(long userId, Server server)
private void RaiseUserUnbanned(ulong userId, Server server)
{ {
if (UserUnbanned != null) if (UserUnbanned != null)
EventHelper.Raise(_logger, nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server))); EventHelper.Raise(_logger, nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server)));
@@ -119,39 +119,37 @@ namespace Discord
internal User PrivateUser => _privateUser; internal User PrivateUser => _privateUser;
private User _privateUser; private User _privateUser;


/// <summary> Returns information about the currently logged-in account. </summary>
public GlobalUser CurrentUser => _privateUser?.Global;
/// <summary> Returns information about the currently logged-in account. </summary>
public GlobalUser CurrentUser => _currentUser;
private GlobalUser _currentUser;


/// <summary> Returns a collection of all unique users this client can currently see. </summary>
public IEnumerable<GlobalUser> AllUsers { get { CheckReady(); return _globalUsers; } }
/// <summary> Returns a collection of all unique users this client can currently see. </summary>
public IEnumerable<GlobalUser> AllUsers { get { CheckReady(); return _globalUsers; } }
internal GlobalUsers GlobalUsers => _globalUsers; internal GlobalUsers GlobalUsers => _globalUsers;
private readonly GlobalUsers _globalUsers; private readonly GlobalUsers _globalUsers;


internal Users Users => _users; internal Users Users => _users;
private readonly Users _users; private readonly Users _users;


public GlobalUser GetUser(long userId)
public GlobalUser GetUser(ulong userId)
{ {
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
CheckReady(); CheckReady();


return _globalUsers[userId]; return _globalUsers[userId];
} }
/// <summary> Returns the user with the specified id, along with their server-specific data, or null if none was found. </summary> /// <summary> Returns the user with the specified id, along with their server-specific data, or null if none was found. </summary>
public User GetUser(Server server, long userId)
public User GetUser(Server server, ulong userId)
{ {
if (server == null) throw new ArgumentNullException(nameof(server)); if (server == null) throw new ArgumentNullException(nameof(server));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
CheckReady(); CheckReady();


return _users[userId, server.Id]; return _users[userId, server.Id];
} }
/// <summary> Returns the user with the specified name and discriminator, along withtheir server-specific data, or null if they couldn't be found. </summary> /// <summary> Returns the user with the specified name and discriminator, along withtheir server-specific data, or null if they couldn't be found. </summary>
public User GetUser(Server server, string username, short discriminator)
public User GetUser(Server server, string username, ushort discriminator)
{ {
if (server == null) throw new ArgumentNullException(nameof(server)); if (server == null) throw new ArgumentNullException(nameof(server));
if (username == null) throw new ArgumentNullException(nameof(username)); if (username == null) throw new ArgumentNullException(nameof(username));
if (discriminator <= 0) throw new ArgumentOutOfRangeException(nameof(discriminator));
CheckReady(); CheckReady();


return FindUsers(server.Members, server.Id, username, discriminator, true).FirstOrDefault(); return FindUsers(server.Members, server.Id, username, discriminator, true).FirstOrDefault();
@@ -175,10 +173,10 @@ namespace Discord
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(nameof(name));
CheckReady(); CheckReady();


return FindUsers(channel.Members, channel.IsPrivate ? (long?)null : channel.Server.Id, name, exactMatch: exactMatch);
return FindUsers(channel.Members, channel.IsPrivate ? (ulong?)null : channel.Server.Id, name, exactMatch: exactMatch);
} }


private IEnumerable<User> FindUsers(IEnumerable<User> users, long? serverId, string name, short? discriminator = null, bool exactMatch = false)
private IEnumerable<User> FindUsers(IEnumerable<User> users, ulong? serverId, string name, ushort? discriminator = null, bool exactMatch = false)
{ {
var query = users.Where(x => string.Equals(x.Name, name, exactMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)); var query = users.Where(x => string.Equals(x.Name, name, exactMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase));


@@ -186,7 +184,7 @@ namespace Discord
{ {
if (name[0] == '<' && name[1] == '@' && name[name.Length - 1] == '>') //Parse mention if (name[0] == '<' && name[1] == '@' && name[name.Length - 1] == '>') //Parse mention
{ {
long id = IdConvert.ToLong(name.Substring(2, name.Length - 3));
ulong id = IdConvert.ToLong(name.Substring(2, name.Length - 3));
var user = _users[id, serverId]; var user = _users[id, serverId];
if (user != null) if (user != null)
query = query.Concat(new User[] { user }); query = query.Concat(new User[] { user });
@@ -210,7 +208,7 @@ namespace Discord
CheckReady(); CheckReady();


//Modify the roles collection and filter out the everyone role //Modify the roles collection and filter out the everyone role
IEnumerable<long> roleIds = roles == null ? null : user.Roles
IEnumerable<ulong> roleIds = roles == null ? null : user.Roles
.Modify(roles, rolesMode) .Modify(roles, rolesMode)
.Where(x => !x.IsEveryone) .Where(x => !x.IsEveryone)
.Select(x => x.Id); .Select(x => x.Id);
@@ -238,7 +236,7 @@ namespace Discord


return _api.BanUser(user.Server.Id, user.Id); return _api.BanUser(user.Server.Id, user.Id);
} }
public async Task UnbanUser(Server server, long userId)
public async Task UnbanUser(Server server, ulong userId)
{ {
if (server == null) throw new ArgumentNullException(nameof(server)); if (server == null) throw new ArgumentNullException(nameof(server));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId)); if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
@@ -274,12 +272,12 @@ namespace Discord
CheckReady(); CheckReady();


await _api.EditProfile(currentPassword: currentPassword, await _api.EditProfile(currentPassword: currentPassword,
username: username ?? _privateUser?.Name, email: email ?? _privateUser?.Global.Email, password: password,
username: username ?? _privateUser?.Name, email: email ?? _currentUser?.Email, password: password,
avatar: avatar, avatarType: avatarType, existingAvatar: _privateUser?.AvatarId).ConfigureAwait(false); avatar: avatar, avatarType: avatarType, existingAvatar: _privateUser?.AvatarId).ConfigureAwait(false);


if (password != null) if (password != null)
{ {
var loginResponse = await _api.Login(_privateUser.Global.Email, password).ConfigureAwait(false);
var loginResponse = await _api.Login(_currentUser.Email, password).ConfigureAwait(false);
_api.Token = loginResponse.Token; _api.Token = loginResponse.Token;
} }
} }


+ 14
- 12
src/Discord.Net/DiscordClient.cs View File

@@ -92,7 +92,7 @@ namespace Discord
public string SessionId => _sessionId; public string SessionId => _sessionId;
private string _sessionId; private string _sessionId;


public long? UserId => _privateUser?.Id;
public ulong? UserId => _currentUser?.Id;


/// <summary> Returns a cancellation token that triggers when the client is manually disconnected. </summary> /// <summary> Returns a cancellation token that triggers when the client is manually disconnected. </summary>
public CancellationToken CancelToken => _cancelToken; public CancellationToken CancelToken => _cancelToken;
@@ -408,7 +408,7 @@ namespace Discord
_servers.Clear(); _servers.Clear();
_globalUsers.Clear(); _globalUsers.Clear();


_privateUser = null;
_currentUser = null;
_gateway = null; _gateway = null;
_token = null; _token = null;
@@ -429,8 +429,9 @@ namespace Discord
var data = e.Payload.ToObject<ReadyEvent>(_webSocket.Serializer); var data = e.Payload.ToObject<ReadyEvent>(_webSocket.Serializer);
_sessionId = data.SessionId; _sessionId = data.SessionId;
_privateUser = _users.GetOrAdd(data.User.Id, null); _privateUser = _users.GetOrAdd(data.User.Id, null);
_privateUser.Update(data.User);
_privateUser.Global.Update(data.User);
_privateUser.Update(data.User);
_currentUser = _privateUser.Global;
_currentUser.Update(data.User);
foreach (var model in data.Guilds) foreach (var model in data.Guilds)
{ {
if (model.Unavailable != true) if (model.Unavailable != true)
@@ -634,18 +635,18 @@ namespace Discord
var data = e.Payload.ToObject<MessageCreateEvent>(_webSocket.Serializer); var data = e.Payload.ToObject<MessageCreateEvent>(_webSocket.Serializer);
Message msg = null; Message msg = null;


bool isAuthor = data.Author.Id == _privateUser.Id;
int nonce = 0;
bool isAuthor = data.Author.Id == _currentUser.Id;
//ulong nonce = 0;


if (data.Author.Id == _privateUser.Id && Config.UseMessageQueue)
/*if (data.Author.Id == _privateUser.Id && Config.UseMessageQueue)
{ {
if (data.Nonce != null && int.TryParse(data.Nonce, out nonce))
if (data.Nonce != null && ulong.TryParse(data.Nonce, out nonce))
msg = _messages[nonce]; msg = _messages[nonce];
}
}*/
if (msg == null) if (msg == null)
{ {
msg = _messages.GetOrAdd(data.Id, data.ChannelId, data.Author.Id); msg = _messages.GetOrAdd(data.Id, data.ChannelId, data.Author.Id);
nonce = 0;
//nonce = 0;
} }


msg.Update(data); msg.Update(data);
@@ -654,11 +655,12 @@ namespace Discord
user.UpdateActivity();// data.Timestamp); user.UpdateActivity();// data.Timestamp);


//Remapped queued message //Remapped queued message
if (nonce != 0)
/*if (nonce != 0)
{ {
msg = _messages.Remap(nonce, data.Id); msg = _messages.Remap(nonce, data.Id);
msg.Id = data.Id; msg.Id = data.Id;
}
RaiseMessageSent(msg);
}*/


msg.State = MessageState.Normal; msg.State = MessageState.Normal;
RaiseMessageReceived(msg); RaiseMessageReceived(msg);


+ 2
- 2
src/Discord.Net/Helpers/Mention.cs View File

@@ -31,7 +31,7 @@ namespace Discord
{ {
return _userRegex.Replace(text, new MatchEvaluator(e => return _userRegex.Replace(text, new MatchEvaluator(e =>
{ {
long id = IdConvert.ToLong(e.Value.Substring(2, e.Value.Length - 3));
var id = IdConvert.ToLong(e.Value.Substring(2, e.Value.Length - 3));
var user = client.Users[id, server?.Id]; var user = client.Users[id, server?.Id];
if (user != null) if (user != null)
{ {
@@ -47,7 +47,7 @@ namespace Discord
{ {
return _channelRegex.Replace(text, new MatchEvaluator(e => return _channelRegex.Replace(text, new MatchEvaluator(e =>
{ {
long id = IdConvert.ToLong(e.Value.Substring(2, e.Value.Length - 3));
var id = IdConvert.ToLong(e.Value.Substring(2, e.Value.Length - 3));
var channel = client.Channels[id]; var channel = client.Channels[id];
if (channel != null && channel.Server.Id == server.Id) if (channel != null && channel.Server.Id == server.Id)
{ {


+ 6
- 6
src/Discord.Net/Helpers/Reference.cs View File

@@ -3,12 +3,12 @@
namespace Discord namespace Discord
{ {
internal class Reference<T> internal class Reference<T>
where T : CachedObject<long>
where T : CachedObject<ulong>
{ {
private Action<T> _onCache, _onUncache; private Action<T> _onCache, _onUncache;
private Func<long, T> _getItem;
private long? _id;
public long? Id
private Func<ulong, T> _getItem;
private ulong? _id;
public ulong? Id
{ {
get { return _id; } get { return _id; }
set set
@@ -56,9 +56,9 @@ namespace Discord
} }
} }


public Reference(Func<long, T> onUpdate, Action<T> onCache = null, Action<T> onUncache = null)
public Reference(Func<ulong, T> onUpdate, Action<T> onCache = null, Action<T> onUncache = null)
: this(null, onUpdate, onCache, onUncache) { } : this(null, onUpdate, onCache, onUncache) { }
public Reference(long? id, Func<long, T> getItem, Action<T> onCache = null, Action<T> onUncache = null)
public Reference(ulong? id, Func<ulong, T> getItem, Action<T> onCache = null, Action<T> onUncache = null)
{ {
_id = id; _id = id;
_getItem = getItem; _getItem = getItem;


+ 12
- 12
src/Discord.Net/Models/Channel.cs View File

@@ -6,7 +6,7 @@ using System.Linq;


namespace Discord namespace Discord
{ {
public sealed class Channel : CachedObject<long>
public sealed class Channel : CachedObject<ulong>
{ {
private struct ChannelMember private struct ChannelMember
{ {
@@ -24,10 +24,10 @@ namespace Discord
public sealed class PermissionOverwrite public sealed class PermissionOverwrite
{ {
public PermissionTarget TargetType { get; } public PermissionTarget TargetType { get; }
public long TargetId { get; }
public ulong TargetId { get; }
public DualChannelPermissions Permissions { get; } public DualChannelPermissions Permissions { get; }


internal PermissionOverwrite(PermissionTarget targetType, long targetId, uint allow, uint deny)
internal PermissionOverwrite(PermissionTarget targetType, ulong targetId, uint allow, uint deny)
{ {
TargetType = targetType; TargetType = targetType;
TargetId = targetId; TargetId = targetId;
@@ -51,14 +51,14 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public Server Server => _server.Value; public Server Server => _server.Value;
[JsonProperty] [JsonProperty]
private long? ServerId { get { return _server.Id; } set { _server.Id = value; } }
private ulong? ServerId { get { return _server.Id; } set { _server.Id = value; } }
private readonly Reference<Server> _server; private readonly Reference<Server> _server;


/// For private chats, returns the target user, otherwise null. /// For private chats, returns the target user, otherwise null.
[JsonIgnore] [JsonIgnore]
public User Recipient => _recipient.Value; public User Recipient => _recipient.Value;
[JsonProperty] [JsonProperty]
private long? RecipientId { get { return _recipient.Id; } set { _recipient.Id = value; } }
private ulong? RecipientId { get { return _recipient.Id; } set { _recipient.Id = value; } }
private readonly Reference<User> _recipient; private readonly Reference<User> _recipient;


//Collections //Collections
@@ -95,15 +95,15 @@ namespace Discord
} }
} }
[JsonProperty] [JsonProperty]
private IEnumerable<long> MemberIds => Members.Select(x => x.Id);
private ConcurrentDictionary<long, ChannelMember> _members;
private IEnumerable<ulong> MemberIds => Members.Select(x => x.Id);
private ConcurrentDictionary<ulong, ChannelMember> _members;


/// <summary> Returns a collection of all messages the client has seen posted in this channel. This collection does not guarantee any ordering. </summary> /// <summary> Returns a collection of all messages the client has seen posted in this channel. This collection does not guarantee any ordering. </summary>
[JsonIgnore] [JsonIgnore]
public IEnumerable<Message> Messages => _messages?.Values ?? Enumerable.Empty<Message>(); public IEnumerable<Message> Messages => _messages?.Values ?? Enumerable.Empty<Message>();
[JsonProperty] [JsonProperty]
private IEnumerable<long> MessageIds => Messages.Select(x => x.Id);
private readonly ConcurrentDictionary<long, Message> _messages;
private IEnumerable<ulong> MessageIds => Messages.Select(x => x.Id);
private readonly ConcurrentDictionary<ulong, Message> _messages;


/// <summary> Returns a collection of all custom permissions used for this channel. </summary> /// <summary> Returns a collection of all custom permissions used for this channel. </summary>
private PermissionOverwrite[] _permissionOverwrites; private PermissionOverwrite[] _permissionOverwrites;
@@ -112,7 +112,7 @@ namespace Discord
/// <summary> Returns the string used to mention this channel. </summary> /// <summary> Returns the string used to mention this channel. </summary>
public string Mention => $"<#{Id}>"; public string Mention => $"<#{Id}>";


internal Channel(DiscordClient client, long id, long? serverId, long? recipientId)
internal Channel(DiscordClient client, ulong id, ulong? serverId, ulong? recipientId)
: base(client, id) : base(client, id)
{ {
_server = new Reference<Server>(serverId, _server = new Reference<Server>(serverId,
@@ -133,7 +133,7 @@ namespace Discord
x.Global.PrivateChannel = null; x.Global.PrivateChannel = null;
}); });
_permissionOverwrites = new PermissionOverwrite[0]; _permissionOverwrites = new PermissionOverwrite[0];
_members = new ConcurrentDictionary<long, ChannelMember>();
_members = new ConcurrentDictionary<ulong, ChannelMember>();


if (recipientId != null) if (recipientId != null)
{ {
@@ -143,7 +143,7 @@ namespace Discord


//Local Cache //Local Cache
if (client.Config.MessageCacheSize > 0) if (client.Config.MessageCacheSize > 0)
_messages = new ConcurrentDictionary<long, Message>();
_messages = new ConcurrentDictionary<ulong, Message>();
} }
internal override bool LoadReferences() internal override bool LoadReferences()
{ {


+ 6
- 6
src/Discord.Net/Models/GlobalUser.cs View File

@@ -6,7 +6,7 @@ using System.Linq;


namespace Discord namespace Discord
{ {
public sealed class GlobalUser : CachedObject<long>
public sealed class GlobalUser : CachedObject<ulong>
{ {
/// <summary> Returns the email for this user. Note: this field is only ever populated for the current logged in user. </summary> /// <summary> Returns the email for this user. Note: this field is only ever populated for the current logged in user. </summary>
[JsonIgnore] [JsonIgnore]
@@ -28,23 +28,23 @@ namespace Discord
} }
} }
[JsonProperty] [JsonProperty]
private long? PrivateChannelId => _privateChannel?.Id;
private ulong? PrivateChannelId => _privateChannel?.Id;
private Channel _privateChannel; private Channel _privateChannel;


/// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary> /// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary>
[JsonIgnore] [JsonIgnore]
public IEnumerable<User> Memberships => _users.Select(x => x.Value); public IEnumerable<User> Memberships => _users.Select(x => x.Value);
[JsonProperty] [JsonProperty]
private IEnumerable<long> ServerIds => _users.Select(x => x.Key);
private readonly ConcurrentDictionary<long, User> _users;
private IEnumerable<ulong> ServerIds => _users.Select(x => x.Key);
private readonly ConcurrentDictionary<ulong, User> _users;


/// <summary> Returns the string used to mention this user. </summary> /// <summary> Returns the string used to mention this user. </summary>
public string Mention => $"<@{Id}>"; public string Mention => $"<@{Id}>";


internal GlobalUser(DiscordClient client, long id)
internal GlobalUser(DiscordClient client, ulong id)
: base(client, id) : base(client, id)
{ {
_users = new ConcurrentDictionary<long, User>();
_users = new ConcurrentDictionary<ulong, User>();
} }
internal override bool LoadReferences() { return true; } internal override bool LoadReferences() { return true; }
internal override void UnloadReferences() internal override void UnloadReferences()


+ 13
- 15
src/Discord.Net/Models/Invite.cs View File

@@ -3,16 +3,16 @@ using Discord.API;


namespace Discord namespace Discord
{ {
public sealed class Invite : CachedObject<string>
public sealed class Invite
{ {
public sealed class ServerInfo public sealed class ServerInfo
{ {
/// <summary> Returns the unique identifier of this server. </summary> /// <summary> Returns the unique identifier of this server. </summary>
public long Id { get; }
public ulong Id { get; }
/// <summary> Returns the name of this server. </summary> /// <summary> Returns the name of this server. </summary>
public string Name { get; } public string Name { get; }


internal ServerInfo(long id, string name)
internal ServerInfo(ulong id, string name)
{ {
Id = id; Id = id;
Name = name; Name = name;
@@ -21,11 +21,11 @@ namespace Discord
public sealed class ChannelInfo public sealed class ChannelInfo
{ {
/// <summary> Returns the unique identifier of this channel. </summary> /// <summary> Returns the unique identifier of this channel. </summary>
public long Id { get; }
public ulong Id { get; }
/// <summary> Returns the name of this channel. </summary> /// <summary> Returns the name of this channel. </summary>
public string Name { get; } public string Name { get; }


internal ChannelInfo(long id, string name)
internal ChannelInfo(ulong id, string name)
{ {
Id = id; Id = id;
Name = name; Name = name;
@@ -34,17 +34,17 @@ namespace Discord
public sealed class InviterInfo public sealed class InviterInfo
{ {
/// <summary> Returns the unique identifier for this user. </summary> /// <summary> Returns the unique identifier for this user. </summary>
public long Id { get; }
public ulong Id { get; }
/// <summary> Returns the name of this user. </summary> /// <summary> Returns the name of this user. </summary>
public string Name { get; } public string Name { get; }
/// <summary> Returns the by-name unique identifier for this user. </summary> /// <summary> Returns the by-name unique identifier for this user. </summary>
public int Discriminator { get; }
public ushort Discriminator { get; }
/// <summary> Returns the unique identifier for this user's avatar. </summary> /// <summary> Returns the unique identifier for this user's avatar. </summary>
public string AvatarId { get; } public string AvatarId { get; }
/// <summary> Returns the full path to this user's avatar. </summary> /// <summary> Returns the full path to this user's avatar. </summary>
public string AvatarUrl => AvatarId != null ? Endpoints.UserAvatar(Id, AvatarId) : null; public string AvatarUrl => AvatarId != null ? Endpoints.UserAvatar(Id, AvatarId) : null;


internal InviterInfo(long id, string name, int discriminator, string avatarId)
internal InviterInfo(ulong id, string name, ushort discriminator, string avatarId)
{ {
Id = id; Id = id;
Name = name; Name = name;
@@ -59,9 +59,10 @@ namespace Discord
public ChannelInfo Channel { get; private set; } public ChannelInfo Channel { get; private set; }
/// <summary> Returns information about the user that created this invite. </summary> /// <summary> Returns information about the user that created this invite. </summary>
public InviterInfo Inviter { get; private set; } public InviterInfo Inviter { get; private set; }

/// <summary> Returns, if enabled, an alternative human-readable code for URLs. </summary>
public string XkcdCode { get; }
public string Id { get; }
/// <summary> Returns, if enabled, an alternative human-readable code for URLs. </summary>
public string XkcdCode { get; }
/// <summary> Time (in seconds) until the invite expires. Set to 0 to never expire. </summary> /// <summary> Time (in seconds) until the invite expires. Set to 0 to never expire. </summary>
public int MaxAge { get; private set; } public int MaxAge { get; private set; }
/// <summary> The amount of times this invite has been used. </summary> /// <summary> The amount of times this invite has been used. </summary>
@@ -77,13 +78,10 @@ namespace Discord
/// <summary> Returns a URL for this invite using XkcdCode if available or Id if not. </summary> /// <summary> Returns a URL for this invite using XkcdCode if available or Id if not. </summary>
public string Url => API.Endpoints.InviteUrl(XkcdCode ?? Id.ToString()); public string Url => API.Endpoints.InviteUrl(XkcdCode ?? Id.ToString());


internal Invite(DiscordClient client, string code, string xkcdPass)
: base(client, code)
internal Invite(string code, string xkcdPass)
{ {
XkcdCode = xkcdPass; XkcdCode = xkcdPass;
} }
internal override bool LoadReferences() { return true; }
internal override void UnloadReferences() { }


internal void Update(InviteReference model) internal void Update(InviteReference model)
{ {


+ 6
- 6
src/Discord.Net/Models/Message.cs View File

@@ -118,7 +118,7 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<User> MentionedUsers { get; internal set; } public IEnumerable<User> MentionedUsers { get; internal set; }
[JsonProperty] [JsonProperty]
private IEnumerable<long> MentionedUserIds
private IEnumerable<ulong> MentionedUserIds
{ {
get { return MentionedUsers?.Select(x => x.Id); } get { return MentionedUsers?.Select(x => x.Id); }
set { MentionedUsers = value.Select(x => _client.GetUser(Server, x)).Where(x => x != null); } set { MentionedUsers = value.Select(x => _client.GetUser(Server, x)).Where(x => x != null); }
@@ -128,7 +128,7 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<Channel> MentionedChannels { get; internal set; } public IEnumerable<Channel> MentionedChannels { get; internal set; }
[JsonProperty] [JsonProperty]
private IEnumerable<long> MentionedChannelIds
private IEnumerable<ulong> MentionedChannelIds
{ {
get { return MentionedChannels?.Select(x => x.Id); } get { return MentionedChannels?.Select(x => x.Id); }
set { MentionedChannels = value.Select(x => _client.GetChannel(x)).Where(x => x != null); } set { MentionedChannels = value.Select(x => _client.GetChannel(x)).Where(x => x != null); }
@@ -138,7 +138,7 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<Role> MentionedRoles { get; internal set; } public IEnumerable<Role> MentionedRoles { get; internal set; }
[JsonProperty] [JsonProperty]
private IEnumerable<long> MentionedRoleIds
private IEnumerable<ulong> MentionedRoleIds
{ {
get { return MentionedRoles?.Select(x => x.Id); } get { return MentionedRoles?.Select(x => x.Id); }
set { MentionedRoles = value.Select(x => _client.GetRole(x)).Where(x => x != null); } set { MentionedRoles = value.Select(x => _client.GetRole(x)).Where(x => x != null); }
@@ -152,17 +152,17 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public Channel Channel => _channel.Value; public Channel Channel => _channel.Value;
[JsonProperty] [JsonProperty]
private long? ChannelId => _channel.Id;
private ulong? ChannelId => _channel.Id;
private readonly Reference<Channel> _channel; private readonly Reference<Channel> _channel;


/// <summary> Returns the author of this message. </summary> /// <summary> Returns the author of this message. </summary>
[JsonIgnore] [JsonIgnore]
public User User => _user.Value; public User User => _user.Value;
[JsonProperty] [JsonProperty]
private long? UserId => _user.Id;
private ulong? UserId => _user.Id;
private readonly Reference<User> _user; private readonly Reference<User> _user;


internal Message(DiscordClient client, long id, long channelId, long userId)
internal Message(DiscordClient client, ulong id, ulong channelId, ulong userId)
: base(client, id) : base(client, id)
{ {
_channel = new Reference<Channel>(channelId, _channel = new Reference<Channel>(channelId,


+ 4
- 4
src/Discord.Net/Models/Role.cs View File

@@ -6,7 +6,7 @@ using System.Linq;


namespace Discord namespace Discord
{ {
public sealed class Role : CachedObject<long>
public sealed class Role : CachedObject<ulong>
{ {
/// <summary> Returns the name of this role. </summary> /// <summary> Returns the name of this role. </summary>
public string Name { get; private set; } public string Name { get; private set; }
@@ -26,7 +26,7 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public Server Server => _server.Value; public Server Server => _server.Value;
[JsonProperty] [JsonProperty]
private long? ServerId { get { return _server.Id; } set { _server.Id = value; } }
private ulong? ServerId { get { return _server.Id; } set { _server.Id = value; } }
private readonly Reference<Server> _server; private readonly Reference<Server> _server;


/// <summary> Returns true if this is the role representing all users in a server. </summary> /// <summary> Returns true if this is the role representing all users in a server. </summary>
@@ -36,13 +36,13 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<User> Members => _server.Id != null ? (IsEveryone ? Server.Members : Server.Members.Where(x => x.HasRole(this))) : new User[0]; public IEnumerable<User> Members => _server.Id != null ? (IsEveryone ? Server.Members : Server.Members.Where(x => x.HasRole(this))) : new User[0];
[JsonProperty] [JsonProperty]
private IEnumerable<long> MemberIds => Members.Select(x => x.Id);
private IEnumerable<ulong> MemberIds => Members.Select(x => x.Id);
//TODO: Add local members cache //TODO: Add local members cache


/// <summary> Returns the string used to mention this role. </summary> /// <summary> Returns the string used to mention this role. </summary>
public string Mention { get { if (IsEveryone) return "@everyone"; else throw new InvalidOperationException("Discord currently only supports mentioning the everyone role"); } } public string Mention { get { if (IsEveryone) return "@everyone"; else throw new InvalidOperationException("Discord currently only supports mentioning the everyone role"); } }


internal Role(DiscordClient client, long id, long serverId)
internal Role(DiscordClient client, ulong id, ulong serverId)
: base(client, id) : base(client, id)
{ {
_server = new Reference<Server>(serverId, x => _client.Servers[x], x => x.AddRole(this), x => x.RemoveRole(this)); _server = new Reference<Server>(serverId, x => _client.Servers[x], x => x.AddRole(this), x => x.RemoveRole(this));


+ 18
- 18
src/Discord.Net/Models/Server.cs View File

@@ -7,7 +7,7 @@ using System.Linq;


namespace Discord namespace Discord
{ {
public sealed class Server : CachedObject<long>
public sealed class Server : CachedObject<ulong>
{ {
private struct ServerMember private struct ServerMember
{ {
@@ -42,14 +42,14 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public User Owner => _owner.Value; public User Owner => _owner.Value;
[JsonProperty] [JsonProperty]
internal long? OwnerId => _owner.Id;
internal ulong? OwnerId => _owner.Id;
private Reference<User> _owner; private Reference<User> _owner;


/// <summary> Returns the AFK voice channel for this server (see AFKTimeout). </summary> /// <summary> Returns the AFK voice channel for this server (see AFKTimeout). </summary>
[JsonIgnore] [JsonIgnore]
public Channel AFKChannel => _afkChannel.Value; public Channel AFKChannel => _afkChannel.Value;
[JsonProperty] [JsonProperty]
private long? AFKChannelId => _afkChannel.Id;
private ulong? AFKChannelId => _afkChannel.Id;
private Reference<Channel> _afkChannel; private Reference<Channel> _afkChannel;


/// <summary> Returns the default channel for this server. </summary> /// <summary> Returns the default channel for this server. </summary>
@@ -57,8 +57,8 @@ namespace Discord
public Channel DefaultChannel { get; private set; } public Channel DefaultChannel { get; private set; }


/// <summary> Returns a collection of the ids of all users banned on this server. </summary> /// <summary> Returns a collection of the ids of all users banned on this server. </summary>
public IEnumerable<long> BannedUsers => _bans.Select(x => x.Key);
private ConcurrentDictionary<long, bool> _bans;
public IEnumerable<ulong> BannedUserIds => _bans.Select(x => x.Key);
private ConcurrentDictionary<ulong, bool> _bans;
/// <summary> Returns a collection of all channels within this server. </summary> /// <summary> Returns a collection of all channels within this server. </summary>
[JsonIgnore] [JsonIgnore]
@@ -70,15 +70,15 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<Channel> VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice); public IEnumerable<Channel> VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice);
[JsonProperty] [JsonProperty]
private IEnumerable<long> ChannelIds => Channels.Select(x => x.Id);
private ConcurrentDictionary<long, Channel> _channels;
private IEnumerable<ulong> ChannelIds => Channels.Select(x => x.Id);
private ConcurrentDictionary<ulong, Channel> _channels;


/// <summary> Returns a collection of all users within this server with their server-specific data. </summary> /// <summary> Returns a collection of all users within this server with their server-specific data. </summary>
[JsonIgnore] [JsonIgnore]
public IEnumerable<User> Members => _members.Select(x => x.Value.User); public IEnumerable<User> Members => _members.Select(x => x.Value.User);
[JsonProperty] [JsonProperty]
private IEnumerable<long> MemberIds => Members.Select(x => x.Id);
private ConcurrentDictionary<long, ServerMember> _members;
private IEnumerable<ulong> MemberIds => Members.Select(x => x.Id);
private ConcurrentDictionary<ulong, ServerMember> _members;


/// <summary> Return the the role representing all users in a server. </summary> /// <summary> Return the the role representing all users in a server. </summary>
[JsonIgnore] [JsonIgnore]
@@ -87,22 +87,22 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public IEnumerable<Role> Roles => _roles.Select(x => x.Value); public IEnumerable<Role> Roles => _roles.Select(x => x.Value);
[JsonProperty] [JsonProperty]
private IEnumerable<long> RoleIds => Roles.Select(x => x.Id);
private ConcurrentDictionary<long, Role> _roles;
private IEnumerable<ulong> RoleIds => Roles.Select(x => x.Id);
private ConcurrentDictionary<ulong, Role> _roles;


internal Server(DiscordClient client, long id)
internal Server(DiscordClient client, ulong id)
: base(client, id) : base(client, id)
{ {
_owner = new Reference<User>(x => _client.Users[x, Id]); _owner = new Reference<User>(x => _client.Users[x, Id]);
_afkChannel = new Reference<Channel>(x => _client.Channels[x]); _afkChannel = new Reference<Channel>(x => _client.Channels[x]);


//Global Cache //Global Cache
_channels = new ConcurrentDictionary<long, Channel>();
_roles = new ConcurrentDictionary<long, Role>();
_members = new ConcurrentDictionary<long, ServerMember>();
_channels = new ConcurrentDictionary<ulong, Channel>();
_roles = new ConcurrentDictionary<ulong, Role>();
_members = new ConcurrentDictionary<ulong, ServerMember>();


//Local Cache //Local Cache
_bans = new ConcurrentDictionary<long, bool>();
_bans = new ConcurrentDictionary<ulong, bool>();
EveryoneRole = _client.Roles.GetOrAdd(id, id); EveryoneRole = _client.Roles.GetOrAdd(id, id);
} }
internal override bool LoadReferences() internal override bool LoadReferences()
@@ -203,11 +203,11 @@ namespace Discord
} }
} }


internal void AddBan(long banId)
internal void AddBan(ulong banId)
{ {
_bans.TryAdd(banId, true); _bans.TryAdd(banId, true);
} }
internal bool RemoveBan(long banId)
internal bool RemoveBan(ulong banId)
{ {
bool ignored; bool ignored;
return _bans.TryRemove(banId, out ignored); return _bans.TryRemove(banId, out ignored);


+ 11
- 11
src/Discord.Net/Models/User.cs View File

@@ -6,12 +6,12 @@ using System.Linq;


namespace Discord namespace Discord
{ {
public class User : CachedObject<long>
public class User : CachedObject<ulong>
{ {
internal struct CompositeKey : IEquatable<CompositeKey> internal struct CompositeKey : IEquatable<CompositeKey>
{ {
public long ServerId, UserId;
public CompositeKey(long userId, long? serverId)
public ulong ServerId, UserId;
public CompositeKey(ulong userId, ulong? serverId)
{ {
ServerId = serverId ?? 0; ServerId = serverId ?? 0;
UserId = userId; UserId = userId;
@@ -28,7 +28,7 @@ namespace Discord
/// <summary> Returns the name of this user on this server. </summary> /// <summary> Returns the name of this user on this server. </summary>
public string Name { get; private set; } public string Name { get; private set; }
/// <summary> Returns a by-name unique identifier separating this user from others with the same name. </summary> /// <summary> Returns a by-name unique identifier separating this user from others with the same name. </summary>
public short Discriminator { get; private set; }
public ushort Discriminator { get; private set; }
/// <summary> Returns the unique identifier for this user's current avatar. </summary> /// <summary> Returns the unique identifier for this user's current avatar. </summary>
public string AvatarId { get; private set; } public string AvatarId { get; private set; }
/// <summary> Returns the URL to this user's current avatar. </summary> /// <summary> Returns the URL to this user's current avatar. </summary>
@@ -66,20 +66,20 @@ namespace Discord
public Server Server => _server.Value; public Server Server => _server.Value;
private readonly Reference<Server> _server; private readonly Reference<Server> _server;
[JsonProperty] [JsonProperty]
private long? ServerId { get { return _server.Id; } set { _server.Id = value; } }
private ulong? ServerId { get { return _server.Id; } set { _server.Id = value; } }


[JsonIgnore] [JsonIgnore]
public Channel VoiceChannel => _voiceChannel.Value; public Channel VoiceChannel => _voiceChannel.Value;
private Reference<Channel> _voiceChannel; private Reference<Channel> _voiceChannel;
[JsonProperty] [JsonProperty]
private long? VoiceChannelId { get { return _voiceChannel.Id; } set { _voiceChannel.Id = value; } }
private ulong? VoiceChannelId { get { return _voiceChannel.Id; } set { _voiceChannel.Id = value; } }


//Collections //Collections
[JsonIgnore] [JsonIgnore]
public IEnumerable<Role> Roles => _roles.Select(x => x.Value); public IEnumerable<Role> Roles => _roles.Select(x => x.Value);
private Dictionary<long, Role> _roles;
private Dictionary<ulong, Role> _roles;
[JsonProperty] [JsonProperty]
private IEnumerable<long> RoleIds => _roles.Select(x => x.Key);
private IEnumerable<ulong> RoleIds => _roles.Select(x => x.Key);


/// <summary> Returns a collection of all messages this user has sent on this server that are still in cache. </summary> /// <summary> Returns a collection of all messages this user has sent on this server that are still in cache. </summary>
[JsonIgnore] [JsonIgnore]
@@ -134,7 +134,7 @@ namespace Discord
/// <summary> Returns the string used to mention this user. </summary> /// <summary> Returns the string used to mention this user. </summary>
public string Mention => $"<@{Id}>"; public string Mention => $"<@{Id}>";


internal User(DiscordClient client, long id, long? serverId)
internal User(DiscordClient client, ulong id, ulong? serverId)
: base(client, id) : base(client, id)
{ {
_globalUser = new Reference<GlobalUser>(id, _globalUser = new Reference<GlobalUser>(id,
@@ -156,7 +156,7 @@ namespace Discord
x.CurrentUser = null; x.CurrentUser = null;
}); });
_voiceChannel = new Reference<Channel>(x => _client.Channels[x]); _voiceChannel = new Reference<Channel>(x => _client.Channels[x]);
_roles = new Dictionary<long, Role>();
_roles = new Dictionary<ulong, Role>();


Status = UserStatus.Offline; Status = UserStatus.Offline;


@@ -240,7 +240,7 @@ namespace Discord
} }
private void UpdateRoles(IEnumerable<Role> roles) private void UpdateRoles(IEnumerable<Role> roles)
{ {
Dictionary<long, Role> newRoles = new Dictionary<long, Role>();
var newRoles = new Dictionary<ulong, Role>();
if (roles != null) if (roles != null)
{ {
foreach (var r in roles) foreach (var r in roles)


+ 3
- 3
src/Discord.Net/Net/WebSockets/GatewaySocket.cs View File

@@ -149,21 +149,21 @@ namespace Discord.Net.WebSockets
QueueMessage(msg); QueueMessage(msg);
} }


public void SendJoinVoice(long serverId, long channelId)
public void SendJoinVoice(ulong serverId, ulong channelId)
{ {
var msg = new JoinVoiceCommand(); var msg = new JoinVoiceCommand();
msg.Payload.ServerId = serverId; msg.Payload.ServerId = serverId;
msg.Payload.ChannelId = channelId; msg.Payload.ChannelId = channelId;
QueueMessage(msg); QueueMessage(msg);
} }
public void SendLeaveVoice(long serverId)
public void SendLeaveVoice(ulong serverId)
{ {
var msg = new JoinVoiceCommand(); var msg = new JoinVoiceCommand();
msg.Payload.ServerId = serverId; msg.Payload.ServerId = serverId;
QueueMessage(msg); QueueMessage(msg);
} }


public void SendRequestUsers(long serverId, string query = "", int limit = 0)
public void SendRequestUsers(ulong serverId, string query = "", int limit = 0)
{ {
var msg = new GetUsersCommand(); var msg = new GetUsersCommand();
msg.Payload.ServerId = serverId; msg.Payload.ServerId = serverId;


Loading…
Cancel
Save