diff --git a/src/Discord.Net.Audio/API/Messages/GatewaySocket.cs b/src/Discord.Net.Audio/API/Messages/GatewaySocket.cs index 072521155..fadb94f0c 100644 --- a/src/Discord.Net.Audio/API/Messages/GatewaySocket.cs +++ b/src/Discord.Net.Audio/API/Messages/GatewaySocket.cs @@ -11,7 +11,7 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long ServerId; + public ulong ServerId; [JsonProperty("endpoint")] public string Endpoint; [JsonProperty("token")] diff --git a/src/Discord.Net.Audio/API/Messages/VoiceSocket.cs b/src/Discord.Net.Audio/API/Messages/VoiceSocket.cs index bf6d57ca3..01f4d50b2 100644 --- a/src/Discord.Net.Audio/API/Messages/VoiceSocket.cs +++ b/src/Discord.Net.Audio/API/Messages/VoiceSocket.cs @@ -31,10 +31,10 @@ namespace Discord.API { [JsonProperty("server_id")] [JsonConverter(typeof(LongStringConverter))] - public long ServerId; + public ulong ServerId; [JsonProperty("user_id")] [JsonConverter(typeof(LongStringConverter))] - public long UserId; + public ulong UserId; [JsonProperty("session_id")] public string SessionId; [JsonProperty("token")] @@ -102,7 +102,7 @@ namespace Discord.API { [JsonProperty("user_id")] [JsonConverter(typeof(LongStringConverter))] - public long UserId; + public ulong UserId; [JsonProperty("ssrc")] public uint SSRC; [JsonProperty("speaking")] diff --git a/src/Discord.Net.Audio/AudioService.cs b/src/Discord.Net.Audio/AudioService.cs index a2762f860..30511ffc5 100644 --- a/src/Discord.Net.Audio/AudioService.cs +++ b/src/Discord.Net.Audio/AudioService.cs @@ -8,9 +8,9 @@ namespace Discord.Audio { 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) { ServerId = serverId; @@ -28,13 +28,13 @@ namespace Discord.Audio } 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 int Offset; 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; ChannelId = channelId; @@ -47,7 +47,7 @@ namespace Discord.Audio public class AudioService : IService { private DiscordAudioClient _defaultClient; - private ConcurrentDictionary _voiceClients; + private ConcurrentDictionary _voiceClients; private ConcurrentDictionary _talkingUsers; private int _nextClientId; @@ -64,7 +64,7 @@ namespace Discord.Audio Connected(this, EventArgs.Empty); } public event EventHandler Disconnected; - private void RaiseDisconnected(long serverId, DisconnectedEventArgs e) + private void RaiseDisconnected(ulong serverId, DisconnectedEventArgs e) { if (Disconnected != null) Disconnected(this, new VoiceDisconnectedEventArgs(serverId, e)); @@ -91,7 +91,7 @@ namespace Discord.Audio { _client = client; if (Config.EnableMultiserver) - _voiceClients = new ConcurrentDictionary(); + _voiceClients = new ConcurrentDictionary(); else { var logger = Client.Log().CreateLogger("Voice"); diff --git a/src/Discord.Net.Audio/DiscordAudioClient.cs b/src/Discord.Net.Audio/DiscordAudioClient.cs index ccb9d6f9c..6ec8f9d1e 100644 --- a/src/Discord.Net.Audio/DiscordAudioClient.cs +++ b/src/Discord.Net.Audio/DiscordAudioClient.cs @@ -22,8 +22,8 @@ namespace Discord.Audio public string Token => _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) { @@ -76,7 +76,7 @@ namespace Discord.Audio case "VOICE_SERVER_UPDATE": { var data = e.Payload.ToObject(_gatewaySocket.Serializer); - long serverId = data.ServerId; + var serverId = data.ServerId; if (serverId == ServerId) { @@ -101,14 +101,14 @@ namespace Discord.Audio return _voiceSocket.Disconnect(); } - internal void SetServerId(long serverId) + internal void SetServerId(ulong serverId) { _voiceSocket.ServerId = serverId; } public async Task Join(Channel channel) { if (channel == null) throw new ArgumentNullException(nameof(channel)); - long? serverId = channel.Server?.Id; + ulong? serverId = channel.Server?.Id; if (serverId != ServerId) throw new InvalidOperationException("Cannot join a channel on a different server than this voice client."); //CheckReady(checkVoice: true); diff --git a/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs b/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs index 9145505c8..c218c7b29 100644 --- a/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs +++ b/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.Events.cs @@ -5,9 +5,9 @@ namespace Discord.Net.WebSockets { internal sealed class IsTalkingEventArgs : EventArgs { - public readonly long UserId; + public readonly ulong UserId; public readonly bool IsSpeaking; - internal IsTalkingEventArgs(long userId, bool isTalking) + internal IsTalkingEventArgs(ulong userId, bool isTalking) { UserId = userId; IsSpeaking = isTalking; @@ -17,14 +17,14 @@ namespace Discord.Net.WebSockets public partial class VoiceWebSocket { internal event EventHandler IsSpeaking; - private void RaiseIsSpeaking(long userId, bool isSpeaking) + private void RaiseIsSpeaking(ulong userId, bool isSpeaking) { if (IsSpeaking != null) IsSpeaking(this, new IsTalkingEventArgs(userId, isSpeaking)); } internal event EventHandler 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) OnPacket(this, new VoicePacketEventArgs(userId, channelId, buffer, offset, count)); diff --git a/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs b/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs index 96c5b962e..717822e73 100644 --- a/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs +++ b/src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs @@ -30,7 +30,7 @@ namespace Discord.Net.WebSockets private readonly AudioServiceConfig _config; private OpusEncoder _encoder; private uint _ssrc; - private ConcurrentDictionary _ssrcMapping; + private ConcurrentDictionary _ssrcMapping; private VoiceBuffer _sendBuffer; private UdpClient _udp; @@ -38,14 +38,14 @@ namespace Discord.Net.WebSockets private bool _isEncrypted; private byte[] _secretKey, _encodingBuffer; private ushort _sequence; - private long? _serverId, _channelId; + private ulong? _serverId, _channelId; private string _encryptionMode; private int _ping; 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; internal VoiceBuffer OutputBuffer => _sendBuffer; @@ -57,7 +57,7 @@ namespace Discord.Net.WebSockets _decoders = new ConcurrentDictionary(); _targetAudioBufferLength = _config.BufferLength / 20; //20 ms frames _encodingBuffer = new byte[MaxOpusSize]; - _ssrcMapping = new ConcurrentDictionary(); + _ssrcMapping = new ConcurrentDictionary(); _encoder = new OpusEncoder(48000, _config.Channels, 20, _config.Bitrate, OpusApplication.Audio); _sendBuffer = new VoiceBuffer((int)Math.Ceiling(_config.BufferLength / (double)_encoder.FrameLength), _encoder.FrameSize); } @@ -228,10 +228,10 @@ namespace Discord.Net.WebSockets resultLength = packetLength - 12; } - /*if (_logLevel >= LogMessageSeverity.Debug) + /*if (_logLevel >= LogMessageSeverity.Debug) RaiseOnLog(LogMessageSeverity.Debug, $"Received {buffer.Length - 12} bytes.");*/ - long userId; + ulong userId; if (_ssrcMapping.TryGetValue(ssrc, out userId)) RaiseOnPacket(userId, _channelId.Value, result, resultOffset, resultLength); } diff --git a/src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs b/src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs index df1868862..1bf376fc2 100644 --- a/src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs +++ b/src/Discord.Net.Commands/Permissions/Userlist/BlacklistService.cs @@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist { public class BlacklistService : UserlistService { - public BlacklistService(IEnumerable initialList = null) + public BlacklistService(IEnumerable initialList = null) : base(initialList) { } diff --git a/src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs b/src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs index edfbb5e7d..dfdd82db4 100644 --- a/src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs +++ b/src/Discord.Net.Commands/Permissions/Userlist/UserlistService.cs @@ -7,39 +7,39 @@ namespace Discord.Commands.Permissions.Userlist { public class UserlistService : IService { - protected readonly ConcurrentDictionary _userList; + protected readonly ConcurrentDictionary _userList; private DiscordClient _client; public DiscordClient Client => _client; - public IEnumerable UserIds => _userList.Select(x => x.Key); + public IEnumerable UserIds => _userList.Select(x => x.Key); - public UserlistService(IEnumerable initialList = null) + public UserlistService(IEnumerable initialList = null) { if (initialList != null) - _userList = new ConcurrentDictionary(initialList.Select(x => new KeyValuePair(x, true))); + _userList = new ConcurrentDictionary(initialList.Select(x => new KeyValuePair(x, true))); else - _userList = new ConcurrentDictionary(); + _userList = new ConcurrentDictionary(); } public void Add(User user) { if (user == null) throw new ArgumentNullException(nameof(user)); + _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; } public bool Remove(User user) { if (user == null) throw new ArgumentNullException(nameof(user)); + bool 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; return _userList.TryRemove(userId, out ignored); } diff --git a/src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs b/src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs index 7b078a915..bdf3bcad6 100644 --- a/src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs +++ b/src/Discord.Net.Commands/Permissions/Userlist/WhitelistService.cs @@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist { public class WhitelistService : UserlistService { - public WhitelistService(IEnumerable initialList = null) + public WhitelistService(IEnumerable initialList = null) : base(initialList) { } diff --git a/src/Discord.Net.Modules/ModuleManager.cs b/src/Discord.Net.Modules/ModuleManager.cs index 0a9022efa..25692705d 100644 --- a/src/Discord.Net.Modules/ModuleManager.cs +++ b/src/Discord.Net.Modules/ModuleManager.cs @@ -46,9 +46,9 @@ namespace Discord.Modules private readonly string _name, _id; private readonly FilterType _filterType; private readonly bool _useServerWhitelist, _useChannelWhitelist, _allowAll, _allowPrivate; - private readonly ConcurrentDictionary _enabledServers; - private readonly ConcurrentDictionary _enabledChannels; - private readonly ConcurrentDictionary _indirectServers; + private readonly ConcurrentDictionary _enabledServers; + private readonly ConcurrentDictionary _enabledChannels; + private readonly ConcurrentDictionary _indirectServers; public DiscordClient Client => _client; public string Name => _name; @@ -69,9 +69,9 @@ namespace Discord.Modules _useChannelWhitelist = filterType.HasFlag(FilterType.ChannelWhitelist); _allowPrivate = filterType.HasFlag(FilterType.AllowPrivate); - _enabledServers = new ConcurrentDictionary(); - _enabledChannels = new ConcurrentDictionary(); - _indirectServers = new ConcurrentDictionary(); + _enabledServers = new ConcurrentDictionary(); + _enabledChannels = new ConcurrentDictionary(); + _indirectServers = new ConcurrentDictionary(); if (_allowAll || _useServerWhitelist) //Server-only events { diff --git a/src/Discord.Net.Shared/IdConvert.cs b/src/Discord.Net.Shared/IdConvert.cs index 81343662b..e4d67b063 100644 --- a/src/Discord.Net.Shared/IdConvert.cs +++ b/src/Discord.Net.Shared/IdConvert.cs @@ -7,14 +7,14 @@ namespace Discord { 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); - public static string ToString(long? value) + public static string ToString(ulong? value) => value?.ToString(_format); } } diff --git a/src/Discord.Net/API/Converters/LongStringCollectionConverter.cs b/src/Discord.Net/API/Converters/LongStringCollectionConverter.cs index 253d964fe..722364ed6 100644 --- a/src/Discord.Net/API/Converters/LongStringCollectionConverter.cs +++ b/src/Discord.Net/API/Converters/LongStringCollectionConverter.cs @@ -8,11 +8,11 @@ namespace Discord.API.Converters { public override bool CanConvert(Type objectType) { - return objectType == typeof(IEnumerable); + return objectType == typeof(IEnumerable); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - List result = new List(); + List result = new List(); if (reader.TokenType == JsonToken.StartArray) { reader.Read(); @@ -31,7 +31,7 @@ namespace Discord.API.Converters else { writer.WriteStartArray(); - foreach (var v in (IEnumerable)value) + foreach (var v in (IEnumerable)value) writer.WriteValue(IdConvert.ToString(v)); writer.WriteEndArray(); } @@ -42,11 +42,11 @@ namespace Discord.API.Converters { public override bool CanConvert(Type objectType) { - return objectType == typeof(IEnumerable); + return objectType == typeof(IEnumerable); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - List result = new List(); + var result = new List(); if (reader.TokenType == JsonToken.StartArray) { reader.Read(); @@ -65,7 +65,7 @@ namespace Discord.API.Converters else { writer.WriteStartArray(); - var a = (long[])value; + var a = (ulong[])value; for (int i = 0; i < a.Length; i++) writer.WriteValue(IdConvert.ToString(a[i])); writer.WriteEndArray(); diff --git a/src/Discord.Net/API/Converters/LongStringConverter.cs b/src/Discord.Net/API/Converters/LongStringConverter.cs index ede01bb68..b32180bb0 100644 --- a/src/Discord.Net/API/Converters/LongStringConverter.cs +++ b/src/Discord.Net/API/Converters/LongStringConverter.cs @@ -7,7 +7,7 @@ namespace Discord.API.Converters { 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) { @@ -15,7 +15,7 @@ namespace Discord.API.Converters } 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) { - return objectType == typeof(long?); + return objectType == typeof(ulong?); } 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) { - writer.WriteValue(IdConvert.ToString((long?)value)); + writer.WriteValue(IdConvert.ToString((ulong?)value)); } } } diff --git a/src/Discord.Net/API/Endpoints.cs b/src/Discord.Net/API/Endpoints.cs index 7d36e7eb3..6a485e26a 100644 --- a/src/Discord.Net/API/Endpoints.cs +++ b/src/Discord.Net/API/Endpoints.cs @@ -13,37 +13,37 @@ public const string AuthLogout = "auth/logout"; 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 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 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 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 const string Users = "users"; 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 VoiceRegions = "voice/regions"; diff --git a/src/Discord.Net/API/Messages/Channels.cs b/src/Discord.Net/API/Messages/Channels.cs index 383ee2f83..31c9a8398 100644 --- a/src/Discord.Net/API/Messages/Channels.cs +++ b/src/Discord.Net/API/Messages/Channels.cs @@ -14,10 +14,10 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long GuildId; + public ulong GuildId; [JsonProperty("name")] public string Name; [JsonProperty("type")] @@ -31,7 +31,7 @@ namespace Discord.API public string Type; [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("deny")] public uint Deny; [JsonProperty("allow")] @@ -40,7 +40,7 @@ namespace Discord.API [JsonProperty("last_message_id")] [JsonConverter(typeof(NullableLongStringConverter))] - public long? LastMessageId; + public ulong? LastMessageId; [JsonProperty("is_private")] public bool IsPrivate; [JsonProperty("position")] @@ -65,7 +65,7 @@ namespace Discord.API { [JsonProperty("recipient_id")] [JsonConverter(typeof(LongStringConverter))] - public long RecipientId; + public ulong RecipientId; } public class CreateChannelResponse : ChannelInfo { } @@ -89,7 +89,7 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("position")] public uint Position; } diff --git a/src/Discord.Net/API/Messages/GatewaySocket.cs b/src/Discord.Net/API/Messages/GatewaySocket.cs index f890db0e9..45d3704e4 100644 --- a/src/Discord.Net/API/Messages/GatewaySocket.cs +++ b/src/Discord.Net/API/Messages/GatewaySocket.cs @@ -108,10 +108,10 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long ServerId; + public ulong ServerId; [JsonProperty("channel_id")] [JsonConverter(typeof(LongStringConverter))] - public long ChannelId; + public ulong ChannelId; [JsonProperty("self_mute")] public string SelfMute; [JsonProperty("self_deaf")] diff --git a/src/Discord.Net/API/Messages/Maintenance.cs b/src/Discord.Net/API/Messages/Maintenance.cs index 0fc91bb96..78c0928cc 100644 --- a/src/Discord.Net/API/Messages/Maintenance.cs +++ b/src/Discord.Net/API/Messages/Maintenance.cs @@ -19,7 +19,7 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("name")] public string Name; [JsonProperty("url")] diff --git a/src/Discord.Net/API/Messages/Members.cs b/src/Discord.Net/API/Messages/Members.cs index 158573dd0..df7fa4501 100644 --- a/src/Discord.Net/API/Messages/Members.cs +++ b/src/Discord.Net/API/Messages/Members.cs @@ -14,11 +14,11 @@ namespace Discord.API { [JsonProperty("user_id")] [JsonConverter(typeof(LongStringConverter))] - public long UserId; //Used in bans + public ulong UserId; //Used in bans [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long GuildId; + public ulong GuildId; private UserReference _user; [JsonProperty("user")] @@ -38,7 +38,7 @@ namespace Discord.API public DateTime? JoinedAt; [JsonProperty("roles")] [JsonConverter(typeof(LongStringArrayConverter))] - public long[] Roles; + public ulong[] Roles; } public class ExtendedMemberInfo : MemberInfo { @@ -55,13 +55,13 @@ namespace Discord.API public string Status; [JsonProperty("roles")] //TODO: Might be temporary [JsonConverter(typeof(LongStringArrayConverter))] - public long[] Roles; + public ulong[] Roles; } public class VoiceMemberInfo : MemberReference { [JsonProperty("channel_id")] [JsonConverter(typeof(NullableLongStringConverter))] - public long? ChannelId; + public ulong? ChannelId; [JsonProperty("session_id")] public string SessionId; [JsonProperty("token")] @@ -87,10 +87,10 @@ namespace Discord.API public bool? Deaf; [JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(NullableLongStringConverter))] - public long? ChannelId; + public ulong? ChannelId; [JsonProperty("roles", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(LongStringEnumerableConverter))] - public IEnumerable Roles; + public IEnumerable Roles; } public class PruneUsersResponse diff --git a/src/Discord.Net/API/Messages/Messages.cs b/src/Discord.Net/API/Messages/Messages.cs index 6dd4a54ef..88e50ed74 100644 --- a/src/Discord.Net/API/Messages/Messages.cs +++ b/src/Discord.Net/API/Messages/Messages.cs @@ -14,13 +14,13 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("channel_id")] [JsonConverter(typeof(LongStringConverter))] - public long ChannelId; + public ulong ChannelId; [JsonProperty("message_id")] [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 { @@ -109,7 +109,7 @@ namespace Discord.API public string Content; [JsonProperty("mentions")] [JsonConverter(typeof(LongStringEnumerableConverter))] - public IEnumerable Mentions; + public IEnumerable Mentions; [JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)] public string Nonce; [JsonProperty("tts", NullValueHandling = NullValueHandling.Ignore)] @@ -124,7 +124,7 @@ namespace Discord.API public string Content; [JsonProperty("mentions", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(LongStringEnumerableConverter))] - public IEnumerable Mentions; + public IEnumerable Mentions; } public sealed class EditMessageResponse : MessageInfo { } @@ -139,7 +139,7 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long ServerId; + public ulong ServerId; [JsonProperty("query")] public string Query; [JsonProperty("limit")] diff --git a/src/Discord.Net/API/Messages/Permissions.cs b/src/Discord.Net/API/Messages/Permissions.cs index 73a7c6d5a..60ad362f9 100644 --- a/src/Discord.Net/API/Messages/Permissions.cs +++ b/src/Discord.Net/API/Messages/Permissions.cs @@ -12,7 +12,7 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("type")] public string Type; [JsonProperty("allow")] diff --git a/src/Discord.Net/API/Messages/Roles.cs b/src/Discord.Net/API/Messages/Roles.cs index e6d4572c4..82a3d615f 100644 --- a/src/Discord.Net/API/Messages/Roles.cs +++ b/src/Discord.Net/API/Messages/Roles.cs @@ -14,16 +14,16 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long GuildId; + public ulong GuildId; [JsonProperty("role_id")] [JsonConverter(typeof(LongStringConverter))] - public long RoleId; + public ulong RoleId; } public class RoleInfo { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("permissions")] public uint? Permissions; [JsonProperty("name")] @@ -62,7 +62,7 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("position")] public uint Position; } @@ -78,7 +78,7 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long GuildId; + public ulong GuildId; [JsonProperty("role")] public RoleInfo Data; } @@ -86,7 +86,7 @@ namespace Discord.API { [JsonProperty("guild_id")] [JsonConverter(typeof(LongStringConverter))] - public long GuildId; + public ulong GuildId; [JsonProperty("role")] public RoleInfo Data; } diff --git a/src/Discord.Net/API/Messages/Servers.cs b/src/Discord.Net/API/Messages/Servers.cs index 9eeaad688..518e34886 100644 --- a/src/Discord.Net/API/Messages/Servers.cs +++ b/src/Discord.Net/API/Messages/Servers.cs @@ -14,7 +14,7 @@ namespace Discord.API { [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("name")] public string Name; } @@ -22,12 +22,12 @@ namespace Discord.API { [JsonProperty("afk_channel_id")] [JsonConverter(typeof(NullableLongStringConverter))] - public long? AFKChannelId; + public ulong? AFKChannelId; [JsonProperty("afk_timeout")] public int? AFKTimeout; [JsonProperty("embed_channel_id")] [JsonConverter(typeof(NullableLongStringConverter))] - public long? EmbedChannelId; + public ulong? EmbedChannelId; [JsonProperty("embed_enabled")] public bool EmbedEnabled; [JsonProperty("icon")] @@ -36,7 +36,7 @@ namespace Discord.API public DateTime? JoinedAt; [JsonProperty("owner_id")] [JsonConverter(typeof(NullableLongStringConverter))] - public long? OwnerId; + public ulong? OwnerId; [JsonProperty("region")] public string Region; [JsonProperty("roles")] @@ -77,7 +77,7 @@ namespace Discord.API public string Icon; [JsonProperty("afk_channel_id", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(NullableLongStringConverter))] - public long? AFKChannelId; + public ulong? AFKChannelId; [JsonProperty("afk_timeout", NullValueHandling = NullValueHandling.Ignore)] public int AFKTimeout; } diff --git a/src/Discord.Net/API/Messages/Users.cs b/src/Discord.Net/API/Messages/Users.cs index 57c19c707..76ef48fc8 100644 --- a/src/Discord.Net/API/Messages/Users.cs +++ b/src/Discord.Net/API/Messages/Users.cs @@ -14,9 +14,9 @@ namespace Discord.API public string Username; [JsonProperty("id")] [JsonConverter(typeof(LongStringConverter))] - public long Id; + public ulong Id; [JsonProperty("discriminator")] - public short? Discriminator; + public ushort? Discriminator; [JsonProperty("avatar")] public string Avatar; } @@ -51,10 +51,10 @@ namespace Discord.API { [JsonProperty("user_id")] [JsonConverter(typeof(LongStringConverter))] - public long UserId; + public ulong UserId; [JsonProperty("channel_id")] [JsonConverter(typeof(LongStringConverter))] - public long ChannelId; + public ulong ChannelId; [JsonProperty("timestamp")] public int Timestamp; } diff --git a/src/Discord.Net/DiscordAPIClient.cs b/src/Discord.Net/DiscordAPIClient.cs index df90374ec..681c23f56 100644 --- a/src/Discord.Net/DiscordAPIClient.cs +++ b/src/Discord.Net/DiscordAPIClient.cs @@ -55,39 +55,30 @@ namespace Discord => _rest.Post(Endpoints.AuthLogout); //Channels - public Task CreateChannel(long serverId, string name, string channelType) + public Task CreateChannel(ulong serverId, string name, string channelType) { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); if (name == null) throw new ArgumentNullException(nameof(name)); if (channelType == null) throw new ArgumentNullException(nameof(channelType)); var request = new CreateChannelRequest { Name = name, Type = channelType }; return _rest.Post(Endpoints.ServerChannels(serverId), request); } - public Task CreatePMChannel(long myId, long recipientId) + public Task 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 }; return _rest.Post(Endpoints.UserChannels(myId), request); } - public Task DestroyChannel(long channelId) + public Task DestroyChannel(ulong channelId) { - if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId)); - return _rest.Delete(Endpoints.Channel(channelId)); } - public Task EditChannel(long channelId, string name = null, string topic = null) + public Task 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 }; return _rest.Patch(Endpoints.Channel(channelId), request); } - public Task ReorderChannels(long serverId, IEnumerable channelIds, int startPos = 0) + public Task ReorderChannels(ulong serverId, IEnumerable channelIds, int startPos = 0) { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); if (channelIds == null) throw new ArgumentNullException(nameof(channelIds)); 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); return _rest.Patch(Endpoints.ServerChannels(serverId), request); } - public Task GetMessages(long channelId, int count, long? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before) + public Task GetMessages(ulong channelId, int count, ulong? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before) { - if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId)); - if (relativeMessageId != null) return _rest.Get(Endpoints.ChannelMessages(channelId, count, relativeMessageId.Value, relativeDir == RelativeDirection.Before ? "before" : "after")); else @@ -117,10 +106,8 @@ namespace Discord } //Invites - public Task CreateInvite(long channelId, int maxAge, int maxUses, bool tempMembership, bool hasXkcd) + public Task 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 }; return _rest.Post(Endpoints.ChannelInvites(channelId), request); } @@ -130,10 +117,8 @@ namespace Discord return _rest.Get(Endpoints.Invite(inviteIdOrXkcd)); } - public Task GetInvites(long serverId) + public Task GetInvites(ulong serverId) { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); - return _rest.Get(Endpoints.ServerInvites(serverId)); } public Task AcceptInvite(string inviteId) @@ -150,40 +135,25 @@ namespace Discord } //Users - public Task EditUser(long serverId, long userId, bool? mute = null, bool? deaf = null, long? voiceChannelId = null, IEnumerable roleIds = null) + public Task EditUser(ulong serverId, ulong userId, bool? mute = null, bool? deaf = null, ulong? voiceChannelId = null, IEnumerable 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 }; 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)); } - 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)); } - 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)); } - public Task 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 PruneUsers(ulong serverId, int days, bool simulate) + { if (simulate) return _rest.Get(Endpoints.ServerPrune(serverId, days)); else @@ -191,94 +161,67 @@ namespace Discord } //Messages - public Task SendMessage(long channelId, string message, IEnumerable mentionedUserIds = null, string nonce = null, bool isTTS = false) + public Task SendMessage(ulong channelId, string message, IEnumerable mentionedUserIds = null, string nonce = null, bool isTTS = false) { - if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId)); 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(Endpoints.ChannelMessages(channelId), request); } - public Task SendFile(long channelId, string filename, Stream stream) + public Task SendFile(ulong channelId, string filename, Stream stream) { - if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId)); if (filename == null) throw new ArgumentNullException(nameof(filename)); if (stream == null) throw new ArgumentNullException(nameof(stream)); return _rest.PostFile(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)); } - public Task EditMessage(long messageId, long channelId, string message = null, IEnumerable mentionedUserIds = null) + public Task EditMessage(ulong messageId, ulong channelId, string message = null, IEnumerable 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 }; return _rest.Patch(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)); } - public Task SendIsTyping(long channelId) + public Task SendIsTyping(ulong channelId) { - if (channelId <= 0) throw new ArgumentOutOfRangeException(nameof(channelId)); - return _rest.Post(Endpoints.ChannelTyping(channelId)); } //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)); var request = new SetChannelPermissionsRequest { Id = userOrRoleId, Type = idType, Allow = allow, Deny = deny }; 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); } //Roles - public Task CreateRole(long serverId) - { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); - + public Task CreateRole(ulong serverId) + { return _rest.Post(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)); } - public Task EditRole(long serverId, long roleId, string name = null, uint? permissions = null, uint? color = null, bool? hoist = null) + public Task 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 }; return _rest.Patch(Endpoints.ServerRole(serverId, roleId), request); } - public Task ReorderRoles(long serverId, IEnumerable roleIds, int startPos = 0) + public Task ReorderRoles(ulong serverId, IEnumerable roleIds, int startPos = 0) { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); if (roleIds == null) throw new ArgumentNullException(nameof(roleIds)); 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 }; return _rest.Post(Endpoints.Servers, request); } - public Task LeaveServer(long serverId) + public Task LeaveServer(ulong serverId) { - if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); - return _rest.Delete(Endpoints.Server(serverId)); } - public Task EditServer(long serverId, string name = null, string region = null, + public Task EditServer(ulong serverId, string name = null, string region = 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) }; return _rest.Patch(Endpoints.Server(serverId), request); } diff --git a/src/Discord.Net/DiscordClient.Channels.cs b/src/Discord.Net/DiscordClient.Channels.cs index 7863148ba..30b5f6a0d 100644 --- a/src/Discord.Net/DiscordClient.Channels.cs +++ b/src/Discord.Net/DiscordClient.Channels.cs @@ -8,15 +8,15 @@ using System.Threading.Tasks; namespace Discord { - internal sealed class Channels : AsyncCollection + internal sealed class Channels : AsyncCollection { public IEnumerable PrivateChannels => _privateChannels.Select(x => x.Value); - private ConcurrentDictionary _privateChannels; + private ConcurrentDictionary _privateChannels; public Channels(DiscordClient client, object writerLock) : base(client, writerLock) { - _privateChannels = new ConcurrentDictionary(); + _privateChannels = new ConcurrentDictionary(); ItemCreated += (s, e) => { if (e.Item.IsPrivate) @@ -33,7 +33,7 @@ namespace Discord 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)); } @@ -72,9 +72,8 @@ namespace Discord private readonly Channels _channels; /// Returns the channel with the specified id, or null if none was found. - public Channel GetChannel(long id) + public Channel GetChannel(ulong id) { - if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id)); CheckReady(); return _channels[id]; @@ -94,7 +93,7 @@ namespace Discord { 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]; if (channel != null) query = query.Concat(new Channel[] { channel }); @@ -136,7 +135,7 @@ namespace Discord channel = user.Global.PrivateChannel; 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); recipient.Update(response.Recipient); channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient.Id); diff --git a/src/Discord.Net/DiscordClient.Invites.cs b/src/Discord.Net/DiscordClient.Invites.cs index 1e91390fa..9b3ca65a8 100644 --- a/src/Discord.Net/DiscordClient.Invites.cs +++ b/src/Discord.Net/DiscordClient.Invites.cs @@ -24,8 +24,7 @@ namespace Discord inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); 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); return invite; } @@ -39,8 +38,7 @@ namespace Discord var response = await _api.GetInvites(server.Id).ConfigureAwait(false); 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); return invite; }).ToArray(); @@ -72,8 +70,7 @@ namespace Discord var response = await _api.CreateInvite(channel.Id, maxAge: maxAge, maxUses: maxUses, 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; } diff --git a/src/Discord.Net/DiscordClient.Messages.cs b/src/Discord.Net/DiscordClient.Messages.cs index d109c8f17..c67f6e980 100644 --- a/src/Discord.Net/DiscordClient.Messages.cs +++ b/src/Discord.Net/DiscordClient.Messages.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace Discord { - internal sealed class Messages : AsyncCollection + internal sealed class Messages : AsyncCollection { private bool _isEnabled; @@ -22,7 +22,7 @@ namespace Discord _isEnabled = isEnabled; } - public Message GetOrAdd(long id, long channelId, long userId) + public Message GetOrAdd(ulong id, ulong channelId, ulong userId) { if (_isEnabled) return GetOrAdd(id, () => new Message(_client, id, channelId, userId)); @@ -33,7 +33,7 @@ namespace Discord return msg; } } - public void Import(Dictionary messages) + public void Import(Dictionary messages) => base.Import(messages); } @@ -41,8 +41,8 @@ namespace Discord { public readonly Message Message; 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; Text = text; @@ -102,7 +102,7 @@ namespace Discord private readonly ConcurrentQueue _pendingMessages; /// Returns the message with the specified id, or null if none was found. - public Message GetMessage(long id) + public Message GetMessage(ulong id) { if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id)); CheckReady(); @@ -195,13 +195,13 @@ namespace Discord if (Config.UseMessageQueue) { 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; msg.Update(new MessageInfo { Content = text, 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, Nonce = IdConvert.ToString(nonce), IsTextToSpeech = isTextToSpeech @@ -270,7 +270,7 @@ namespace Discord } /// Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. - public async Task DownloadMessages(Channel channel, int count, long? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool useCache = true) + public async Task DownloadMessages(Channel channel, int count, ulong? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool useCache = true) { if (channel == null) throw new ArgumentNullException(nameof(channel)); if (count < 0) throw new ArgumentNullException(nameof(count)); @@ -322,9 +322,9 @@ namespace Discord .Select(x => { var msg = new Message(this, - x["Id"].Value(), + x["Id"].Value(), channel.Id, - x["UserId"].Value()); + x["UserId"].Value()); var reader = x.CreateReader(); _messageImporter.Populate(reader, msg); @@ -366,7 +366,7 @@ namespace Discord var msg = queuedMessage.Message; try { - if (msg.Id < 0) + if (msg.Id == 0) { await _api.SendMessage( msg.Channel.Id, @@ -375,7 +375,6 @@ namespace Discord IdConvert.ToString(msg.Id), //Nonce msg.IsTTS) .ConfigureAwait(false); - RaiseMessageSent(msg); } else { @@ -394,10 +393,10 @@ namespace Discord } }); } - private long GenerateNonce() + private ulong GenerateNonce() { lock (_nonceRand) - return -_nonceRand.Next(1, int.MaxValue - 1); + return (ulong)_nonceRand.Next(1, int.MaxValue); } } } \ No newline at end of file diff --git a/src/Discord.Net/DiscordClient.Permissions.cs b/src/Discord.Net/DiscordClient.Permissions.cs index 7a10179c9..132f6b47e 100644 --- a/src/Discord.Net/DiscordClient.Permissions.cs +++ b/src/Discord.Net/DiscordClient.Permissions.cs @@ -63,7 +63,7 @@ namespace Discord 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); public Task RemoveChannelPermissions(Channel channel, User user) @@ -82,7 +82,7 @@ namespace Discord 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 { diff --git a/src/Discord.Net/DiscordClient.Roles.cs b/src/Discord.Net/DiscordClient.Roles.cs index 7554d288f..03d06ce6e 100644 --- a/src/Discord.Net/DiscordClient.Roles.cs +++ b/src/Discord.Net/DiscordClient.Roles.cs @@ -7,12 +7,12 @@ using System.Threading.Tasks; namespace Discord { - internal sealed class Roles : AsyncCollection + internal sealed class Roles : AsyncCollection { public Roles(DiscordClient client, object 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)); } @@ -49,9 +49,8 @@ namespace Discord private readonly Roles _roles; /// Returns the role with the specified id, or null if none was found. - public Role GetRole(long id) + public Role GetRole(ulong id) { - if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id)); CheckReady(); return _roles[id]; diff --git a/src/Discord.Net/DiscordClient.Servers.cs b/src/Discord.Net/DiscordClient.Servers.cs index 160cb3509..34e976e39 100644 --- a/src/Discord.Net/DiscordClient.Servers.cs +++ b/src/Discord.Net/DiscordClient.Servers.cs @@ -8,12 +8,12 @@ using System.Threading.Tasks; namespace Discord { - internal sealed class Servers : AsyncCollection + internal sealed class Servers : AsyncCollection { public Servers(DiscordClient client, object writerLock) : base(client, writerLock) { } - public Server GetOrAdd(long id) + public Server GetOrAdd(ulong id) => GetOrAdd(id, () => new Server(_client, id)); } @@ -63,9 +63,8 @@ namespace Discord private readonly Servers _servers; /// Returns the server with the specified id, or null if none was found. - public Server GetServer(long id) + public Server GetServer(ulong id) { - if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id)); CheckReady(); return _servers[id]; diff --git a/src/Discord.Net/DiscordClient.Users.cs b/src/Discord.Net/DiscordClient.Users.cs index d221028a3..91f8f5a7c 100644 --- a/src/Discord.Net/DiscordClient.Users.cs +++ b/src/Discord.Net/DiscordClient.Users.cs @@ -8,12 +8,12 @@ using System.Threading.Tasks; namespace Discord { - internal sealed class GlobalUsers : AsyncCollection + internal sealed class GlobalUsers : AsyncCollection { public GlobalUsers(DiscordClient client, object 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 { @@ -21,11 +21,11 @@ namespace Discord : base(client, writerLock) { } - public User this[long userId, long? serverId] + public User this[ulong userId, ulong? 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)); - public User TryRemove(long userId, long? serverId) + public User TryRemove(ulong userId, ulong? serverId) => TryRemove(new User.CompositeKey(userId, serverId)); } @@ -48,10 +48,10 @@ namespace Discord } public class BanEventArgs : EventArgs { - public long UserId { get; } + public ulong UserId { get; } public Server Server { get; } - public BanEventArgs(long userId, Server server) + public BanEventArgs(ulong userId, Server server) { UserId = userId; Server = server; @@ -103,13 +103,13 @@ namespace Discord EventHelper.Raise(_logger, nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty)); } public event EventHandler UserBanned; - private void RaiseUserBanned(long userId, Server server) + private void RaiseUserBanned(ulong userId, Server server) { if (UserBanned != null) EventHelper.Raise(_logger, nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server))); } public event EventHandler UserUnbanned; - private void RaiseUserUnbanned(long userId, Server server) + private void RaiseUserUnbanned(ulong userId, Server server) { if (UserUnbanned != null) EventHelper.Raise(_logger, nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server))); @@ -119,39 +119,37 @@ namespace Discord internal User PrivateUser => _privateUser; private User _privateUser; - /// Returns information about the currently logged-in account. - public GlobalUser CurrentUser => _privateUser?.Global; + /// Returns information about the currently logged-in account. + public GlobalUser CurrentUser => _currentUser; + private GlobalUser _currentUser; - /// Returns a collection of all unique users this client can currently see. - public IEnumerable AllUsers { get { CheckReady(); return _globalUsers; } } + /// Returns a collection of all unique users this client can currently see. + public IEnumerable AllUsers { get { CheckReady(); return _globalUsers; } } internal GlobalUsers GlobalUsers => _globalUsers; private readonly GlobalUsers _globalUsers; internal Users 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(); return _globalUsers[userId]; } /// Returns the user with the specified id, along with their server-specific data, or null if none was found. - public User GetUser(Server server, long userId) + public User GetUser(Server server, ulong userId) { if (server == null) throw new ArgumentNullException(nameof(server)); - if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId)); CheckReady(); return _users[userId, server.Id]; } /// Returns the user with the specified name and discriminator, along withtheir server-specific data, or null if they couldn't be found. - 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 (username == null) throw new ArgumentNullException(nameof(username)); - if (discriminator <= 0) throw new ArgumentOutOfRangeException(nameof(discriminator)); CheckReady(); return FindUsers(server.Members, server.Id, username, discriminator, true).FirstOrDefault(); @@ -175,10 +173,10 @@ namespace Discord if (name == null) throw new ArgumentNullException(nameof(name)); 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 FindUsers(IEnumerable users, long? serverId, string name, short? discriminator = null, bool exactMatch = false) + private IEnumerable FindUsers(IEnumerable 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)); @@ -186,7 +184,7 @@ namespace Discord { 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]; if (user != null) query = query.Concat(new User[] { user }); @@ -210,7 +208,7 @@ namespace Discord CheckReady(); //Modify the roles collection and filter out the everyone role - IEnumerable roleIds = roles == null ? null : user.Roles + IEnumerable roleIds = roles == null ? null : user.Roles .Modify(roles, rolesMode) .Where(x => !x.IsEveryone) .Select(x => x.Id); @@ -238,7 +236,7 @@ namespace Discord 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 (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId)); @@ -274,12 +272,12 @@ namespace Discord CheckReady(); 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); 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; } } diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index 7a40ad9f3..fa880d13c 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -92,7 +92,7 @@ namespace Discord public string SessionId => _sessionId; private string _sessionId; - public long? UserId => _privateUser?.Id; + public ulong? UserId => _currentUser?.Id; /// Returns a cancellation token that triggers when the client is manually disconnected. public CancellationToken CancelToken => _cancelToken; @@ -408,7 +408,7 @@ namespace Discord _servers.Clear(); _globalUsers.Clear(); - _privateUser = null; + _currentUser = null; _gateway = null; _token = null; @@ -429,8 +429,9 @@ namespace Discord var data = e.Payload.ToObject(_webSocket.Serializer); _sessionId = data.SessionId; _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) { if (model.Unavailable != true) @@ -634,18 +635,18 @@ namespace Discord var data = e.Payload.ToObject(_webSocket.Serializer); 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]; - } + }*/ if (msg == null) { msg = _messages.GetOrAdd(data.Id, data.ChannelId, data.Author.Id); - nonce = 0; + //nonce = 0; } msg.Update(data); @@ -654,11 +655,12 @@ namespace Discord user.UpdateActivity();// data.Timestamp); //Remapped queued message - if (nonce != 0) + /*if (nonce != 0) { msg = _messages.Remap(nonce, data.Id); msg.Id = data.Id; - } + RaiseMessageSent(msg); + }*/ msg.State = MessageState.Normal; RaiseMessageReceived(msg); diff --git a/src/Discord.Net/Helpers/Mention.cs b/src/Discord.Net/Helpers/Mention.cs index a3bdfd5df..986d9b549 100644 --- a/src/Discord.Net/Helpers/Mention.cs +++ b/src/Discord.Net/Helpers/Mention.cs @@ -31,7 +31,7 @@ namespace Discord { 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]; if (user != null) { @@ -47,7 +47,7 @@ namespace Discord { 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]; if (channel != null && channel.Server.Id == server.Id) { diff --git a/src/Discord.Net/Helpers/Reference.cs b/src/Discord.Net/Helpers/Reference.cs index 3ea7705e8..988ab7919 100644 --- a/src/Discord.Net/Helpers/Reference.cs +++ b/src/Discord.Net/Helpers/Reference.cs @@ -3,12 +3,12 @@ namespace Discord { internal class Reference - where T : CachedObject + where T : CachedObject { private Action _onCache, _onUncache; - private Func _getItem; - private long? _id; - public long? Id + private Func _getItem; + private ulong? _id; + public ulong? Id { get { return _id; } set @@ -56,9 +56,9 @@ namespace Discord } } - public Reference(Func onUpdate, Action onCache = null, Action onUncache = null) + public Reference(Func onUpdate, Action onCache = null, Action onUncache = null) : this(null, onUpdate, onCache, onUncache) { } - public Reference(long? id, Func getItem, Action onCache = null, Action onUncache = null) + public Reference(ulong? id, Func getItem, Action onCache = null, Action onUncache = null) { _id = id; _getItem = getItem; diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index 02ca9d7c1..eeb32d5c7 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -6,7 +6,7 @@ using System.Linq; namespace Discord { - public sealed class Channel : CachedObject + public sealed class Channel : CachedObject { private struct ChannelMember { @@ -24,10 +24,10 @@ namespace Discord public sealed class PermissionOverwrite { public PermissionTarget TargetType { get; } - public long TargetId { get; } + public ulong TargetId { 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; TargetId = targetId; @@ -51,14 +51,14 @@ namespace Discord [JsonIgnore] public Server Server => _server.Value; [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; /// For private chats, returns the target user, otherwise null. [JsonIgnore] public User Recipient => _recipient.Value; [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 _recipient; //Collections @@ -95,15 +95,15 @@ namespace Discord } } [JsonProperty] - private IEnumerable MemberIds => Members.Select(x => x.Id); - private ConcurrentDictionary _members; + private IEnumerable MemberIds => Members.Select(x => x.Id); + private ConcurrentDictionary _members; /// Returns a collection of all messages the client has seen posted in this channel. This collection does not guarantee any ordering. [JsonIgnore] public IEnumerable Messages => _messages?.Values ?? Enumerable.Empty(); [JsonProperty] - private IEnumerable MessageIds => Messages.Select(x => x.Id); - private readonly ConcurrentDictionary _messages; + private IEnumerable MessageIds => Messages.Select(x => x.Id); + private readonly ConcurrentDictionary _messages; /// Returns a collection of all custom permissions used for this channel. private PermissionOverwrite[] _permissionOverwrites; @@ -112,7 +112,7 @@ namespace Discord /// Returns the string used to mention this channel. 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) { _server = new Reference(serverId, @@ -133,7 +133,7 @@ namespace Discord x.Global.PrivateChannel = null; }); _permissionOverwrites = new PermissionOverwrite[0]; - _members = new ConcurrentDictionary(); + _members = new ConcurrentDictionary(); if (recipientId != null) { @@ -143,7 +143,7 @@ namespace Discord //Local Cache if (client.Config.MessageCacheSize > 0) - _messages = new ConcurrentDictionary(); + _messages = new ConcurrentDictionary(); } internal override bool LoadReferences() { diff --git a/src/Discord.Net/Models/GlobalUser.cs b/src/Discord.Net/Models/GlobalUser.cs index edc08b988..11e870b32 100644 --- a/src/Discord.Net/Models/GlobalUser.cs +++ b/src/Discord.Net/Models/GlobalUser.cs @@ -6,7 +6,7 @@ using System.Linq; namespace Discord { - public sealed class GlobalUser : CachedObject + public sealed class GlobalUser : CachedObject { /// Returns the email for this user. Note: this field is only ever populated for the current logged in user. [JsonIgnore] @@ -28,23 +28,23 @@ namespace Discord } } [JsonProperty] - private long? PrivateChannelId => _privateChannel?.Id; + private ulong? PrivateChannelId => _privateChannel?.Id; private Channel _privateChannel; /// Returns a collection of all server-specific data for every server this user is a member of. [JsonIgnore] public IEnumerable Memberships => _users.Select(x => x.Value); [JsonProperty] - private IEnumerable ServerIds => _users.Select(x => x.Key); - private readonly ConcurrentDictionary _users; + private IEnumerable ServerIds => _users.Select(x => x.Key); + private readonly ConcurrentDictionary _users; /// Returns the string used to mention this user. public string Mention => $"<@{Id}>"; - internal GlobalUser(DiscordClient client, long id) + internal GlobalUser(DiscordClient client, ulong id) : base(client, id) { - _users = new ConcurrentDictionary(); + _users = new ConcurrentDictionary(); } internal override bool LoadReferences() { return true; } internal override void UnloadReferences() diff --git a/src/Discord.Net/Models/Invite.cs b/src/Discord.Net/Models/Invite.cs index 373ec5042..78b96d64f 100644 --- a/src/Discord.Net/Models/Invite.cs +++ b/src/Discord.Net/Models/Invite.cs @@ -3,16 +3,16 @@ using Discord.API; namespace Discord { - public sealed class Invite : CachedObject + public sealed class Invite { public sealed class ServerInfo { /// Returns the unique identifier of this server. - public long Id { get; } + public ulong Id { get; } /// Returns the name of this server. public string Name { get; } - internal ServerInfo(long id, string name) + internal ServerInfo(ulong id, string name) { Id = id; Name = name; @@ -21,11 +21,11 @@ namespace Discord public sealed class ChannelInfo { /// Returns the unique identifier of this channel. - public long Id { get; } + public ulong Id { get; } /// Returns the name of this channel. public string Name { get; } - internal ChannelInfo(long id, string name) + internal ChannelInfo(ulong id, string name) { Id = id; Name = name; @@ -34,17 +34,17 @@ namespace Discord public sealed class InviterInfo { /// Returns the unique identifier for this user. - public long Id { get; } + public ulong Id { get; } /// Returns the name of this user. public string Name { get; } /// Returns the by-name unique identifier for this user. - public int Discriminator { get; } + public ushort Discriminator { get; } /// Returns the unique identifier for this user's avatar. public string AvatarId { get; } /// Returns the full path to this user's avatar. 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; Name = name; @@ -59,9 +59,10 @@ namespace Discord public ChannelInfo Channel { get; private set; } /// Returns information about the user that created this invite. public InviterInfo Inviter { get; private set; } - - /// Returns, if enabled, an alternative human-readable code for URLs. - public string XkcdCode { get; } + + public string Id { get; } + /// Returns, if enabled, an alternative human-readable code for URLs. + public string XkcdCode { get; } /// Time (in seconds) until the invite expires. Set to 0 to never expire. public int MaxAge { get; private set; } /// The amount of times this invite has been used. @@ -77,13 +78,10 @@ namespace Discord /// Returns a URL for this invite using XkcdCode if available or Id if not. 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; } - internal override bool LoadReferences() { return true; } - internal override void UnloadReferences() { } internal void Update(InviteReference model) { diff --git a/src/Discord.Net/Models/Message.cs b/src/Discord.Net/Models/Message.cs index ac87463d9..62b56d073 100644 --- a/src/Discord.Net/Models/Message.cs +++ b/src/Discord.Net/Models/Message.cs @@ -118,7 +118,7 @@ namespace Discord [JsonIgnore] public IEnumerable MentionedUsers { get; internal set; } [JsonProperty] - private IEnumerable MentionedUserIds + private IEnumerable MentionedUserIds { get { return MentionedUsers?.Select(x => x.Id); } set { MentionedUsers = value.Select(x => _client.GetUser(Server, x)).Where(x => x != null); } @@ -128,7 +128,7 @@ namespace Discord [JsonIgnore] public IEnumerable MentionedChannels { get; internal set; } [JsonProperty] - private IEnumerable MentionedChannelIds + private IEnumerable MentionedChannelIds { get { return MentionedChannels?.Select(x => x.Id); } set { MentionedChannels = value.Select(x => _client.GetChannel(x)).Where(x => x != null); } @@ -138,7 +138,7 @@ namespace Discord [JsonIgnore] public IEnumerable MentionedRoles { get; internal set; } [JsonProperty] - private IEnumerable MentionedRoleIds + private IEnumerable MentionedRoleIds { get { return MentionedRoles?.Select(x => x.Id); } set { MentionedRoles = value.Select(x => _client.GetRole(x)).Where(x => x != null); } @@ -152,17 +152,17 @@ namespace Discord [JsonIgnore] public Channel Channel => _channel.Value; [JsonProperty] - private long? ChannelId => _channel.Id; + private ulong? ChannelId => _channel.Id; private readonly Reference _channel; /// Returns the author of this message. [JsonIgnore] public User User => _user.Value; [JsonProperty] - private long? UserId => _user.Id; + private ulong? UserId => _user.Id; private readonly Reference _user; - internal Message(DiscordClient client, long id, long channelId, long userId) + internal Message(DiscordClient client, ulong id, ulong channelId, ulong userId) : base(client, id) { _channel = new Reference(channelId, diff --git a/src/Discord.Net/Models/Role.cs b/src/Discord.Net/Models/Role.cs index bd355725e..b9cf8fb19 100644 --- a/src/Discord.Net/Models/Role.cs +++ b/src/Discord.Net/Models/Role.cs @@ -6,7 +6,7 @@ using System.Linq; namespace Discord { - public sealed class Role : CachedObject + public sealed class Role : CachedObject { /// Returns the name of this role. public string Name { get; private set; } @@ -26,7 +26,7 @@ namespace Discord [JsonIgnore] public Server Server => _server.Value; [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; /// Returns true if this is the role representing all users in a server. @@ -36,13 +36,13 @@ namespace Discord [JsonIgnore] public IEnumerable Members => _server.Id != null ? (IsEveryone ? Server.Members : Server.Members.Where(x => x.HasRole(this))) : new User[0]; [JsonProperty] - private IEnumerable MemberIds => Members.Select(x => x.Id); + private IEnumerable MemberIds => Members.Select(x => x.Id); //TODO: Add local members cache /// Returns the string used to mention this 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) { _server = new Reference(serverId, x => _client.Servers[x], x => x.AddRole(this), x => x.RemoveRole(this)); diff --git a/src/Discord.Net/Models/Server.cs b/src/Discord.Net/Models/Server.cs index 257b36bbf..b326f0f06 100644 --- a/src/Discord.Net/Models/Server.cs +++ b/src/Discord.Net/Models/Server.cs @@ -7,7 +7,7 @@ using System.Linq; namespace Discord { - public sealed class Server : CachedObject + public sealed class Server : CachedObject { private struct ServerMember { @@ -42,14 +42,14 @@ namespace Discord [JsonIgnore] public User Owner => _owner.Value; [JsonProperty] - internal long? OwnerId => _owner.Id; + internal ulong? OwnerId => _owner.Id; private Reference _owner; /// Returns the AFK voice channel for this server (see AFKTimeout). [JsonIgnore] public Channel AFKChannel => _afkChannel.Value; [JsonProperty] - private long? AFKChannelId => _afkChannel.Id; + private ulong? AFKChannelId => _afkChannel.Id; private Reference _afkChannel; /// Returns the default channel for this server. @@ -57,8 +57,8 @@ namespace Discord public Channel DefaultChannel { get; private set; } /// Returns a collection of the ids of all users banned on this server. - public IEnumerable BannedUsers => _bans.Select(x => x.Key); - private ConcurrentDictionary _bans; + public IEnumerable BannedUserIds => _bans.Select(x => x.Key); + private ConcurrentDictionary _bans; /// Returns a collection of all channels within this server. [JsonIgnore] @@ -70,15 +70,15 @@ namespace Discord [JsonIgnore] public IEnumerable VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice); [JsonProperty] - private IEnumerable ChannelIds => Channels.Select(x => x.Id); - private ConcurrentDictionary _channels; + private IEnumerable ChannelIds => Channels.Select(x => x.Id); + private ConcurrentDictionary _channels; /// Returns a collection of all users within this server with their server-specific data. [JsonIgnore] public IEnumerable Members => _members.Select(x => x.Value.User); [JsonProperty] - private IEnumerable MemberIds => Members.Select(x => x.Id); - private ConcurrentDictionary _members; + private IEnumerable MemberIds => Members.Select(x => x.Id); + private ConcurrentDictionary _members; /// Return the the role representing all users in a server. [JsonIgnore] @@ -87,22 +87,22 @@ namespace Discord [JsonIgnore] public IEnumerable Roles => _roles.Select(x => x.Value); [JsonProperty] - private IEnumerable RoleIds => Roles.Select(x => x.Id); - private ConcurrentDictionary _roles; + private IEnumerable RoleIds => Roles.Select(x => x.Id); + private ConcurrentDictionary _roles; - internal Server(DiscordClient client, long id) + internal Server(DiscordClient client, ulong id) : base(client, id) { _owner = new Reference(x => _client.Users[x, Id]); _afkChannel = new Reference(x => _client.Channels[x]); //Global Cache - _channels = new ConcurrentDictionary(); - _roles = new ConcurrentDictionary(); - _members = new ConcurrentDictionary(); + _channels = new ConcurrentDictionary(); + _roles = new ConcurrentDictionary(); + _members = new ConcurrentDictionary(); //Local Cache - _bans = new ConcurrentDictionary(); + _bans = new ConcurrentDictionary(); EveryoneRole = _client.Roles.GetOrAdd(id, id); } internal override bool LoadReferences() @@ -203,11 +203,11 @@ namespace Discord } } - internal void AddBan(long banId) + internal void AddBan(ulong banId) { _bans.TryAdd(banId, true); } - internal bool RemoveBan(long banId) + internal bool RemoveBan(ulong banId) { bool ignored; return _bans.TryRemove(banId, out ignored); diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs index 924166529..3790b516a 100644 --- a/src/Discord.Net/Models/User.cs +++ b/src/Discord.Net/Models/User.cs @@ -6,12 +6,12 @@ using System.Linq; namespace Discord { - public class User : CachedObject + public class User : CachedObject { internal struct CompositeKey : IEquatable { - public long ServerId, UserId; - public CompositeKey(long userId, long? serverId) + public ulong ServerId, UserId; + public CompositeKey(ulong userId, ulong? serverId) { ServerId = serverId ?? 0; UserId = userId; @@ -28,7 +28,7 @@ namespace Discord /// Returns the name of this user on this server. public string Name { get; private set; } /// Returns a by-name unique identifier separating this user from others with the same name. - public short Discriminator { get; private set; } + public ushort Discriminator { get; private set; } /// Returns the unique identifier for this user's current avatar. public string AvatarId { get; private set; } /// Returns the URL to this user's current avatar. @@ -66,20 +66,20 @@ namespace Discord public Server Server => _server.Value; private readonly Reference _server; [JsonProperty] - private long? ServerId { get { return _server.Id; } set { _server.Id = value; } } + private ulong? ServerId { get { return _server.Id; } set { _server.Id = value; } } [JsonIgnore] public Channel VoiceChannel => _voiceChannel.Value; private Reference _voiceChannel; [JsonProperty] - private long? VoiceChannelId { get { return _voiceChannel.Id; } set { _voiceChannel.Id = value; } } + private ulong? VoiceChannelId { get { return _voiceChannel.Id; } set { _voiceChannel.Id = value; } } //Collections [JsonIgnore] public IEnumerable Roles => _roles.Select(x => x.Value); - private Dictionary _roles; + private Dictionary _roles; [JsonProperty] - private IEnumerable RoleIds => _roles.Select(x => x.Key); + private IEnumerable RoleIds => _roles.Select(x => x.Key); /// Returns a collection of all messages this user has sent on this server that are still in cache. [JsonIgnore] @@ -134,7 +134,7 @@ namespace Discord /// Returns the string used to mention this user. public string Mention => $"<@{Id}>"; - internal User(DiscordClient client, long id, long? serverId) + internal User(DiscordClient client, ulong id, ulong? serverId) : base(client, id) { _globalUser = new Reference(id, @@ -156,7 +156,7 @@ namespace Discord x.CurrentUser = null; }); _voiceChannel = new Reference(x => _client.Channels[x]); - _roles = new Dictionary(); + _roles = new Dictionary(); Status = UserStatus.Offline; @@ -240,7 +240,7 @@ namespace Discord } private void UpdateRoles(IEnumerable roles) { - Dictionary newRoles = new Dictionary(); + var newRoles = new Dictionary(); if (roles != null) { foreach (var r in roles) diff --git a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs index d9e7a64e1..e2b44a5fd 100644 --- a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs +++ b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs @@ -149,21 +149,21 @@ namespace Discord.Net.WebSockets QueueMessage(msg); } - public void SendJoinVoice(long serverId, long channelId) + public void SendJoinVoice(ulong serverId, ulong channelId) { var msg = new JoinVoiceCommand(); msg.Payload.ServerId = serverId; msg.Payload.ChannelId = channelId; QueueMessage(msg); } - public void SendLeaveVoice(long serverId) + public void SendLeaveVoice(ulong serverId) { var msg = new JoinVoiceCommand(); msg.Payload.ServerId = serverId; 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(); msg.Payload.ServerId = serverId;