@@ -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")] | |||
@@ -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")] | |||
@@ -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<long, DiscordAudioClient> _voiceClients; | |||
private ConcurrentDictionary<ulong, DiscordAudioClient> _voiceClients; | |||
private ConcurrentDictionary<User, bool> _talkingUsers; | |||
private int _nextClientId; | |||
@@ -64,7 +64,7 @@ namespace Discord.Audio | |||
Connected(this, EventArgs.Empty); | |||
} | |||
public event EventHandler<VoiceDisconnectedEventArgs> 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<long, DiscordAudioClient>(); | |||
_voiceClients = new ConcurrentDictionary<ulong, DiscordAudioClient>(); | |||
else | |||
{ | |||
var logger = Client.Log().CreateLogger("Voice"); | |||
@@ -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<VoiceServerUpdateEvent>(_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); | |||
@@ -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<IsTalkingEventArgs> 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<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) | |||
OnPacket(this, new VoicePacketEventArgs(userId, channelId, buffer, offset, count)); | |||
@@ -30,7 +30,7 @@ namespace Discord.Net.WebSockets | |||
private readonly AudioServiceConfig _config; | |||
private OpusEncoder _encoder; | |||
private uint _ssrc; | |||
private ConcurrentDictionary<uint, long> _ssrcMapping; | |||
private ConcurrentDictionary<uint, ulong> _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<uint, OpusDecoder>(); | |||
_targetAudioBufferLength = _config.BufferLength / 20; //20 ms frames | |||
_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); | |||
_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); | |||
} | |||
@@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist | |||
{ | |||
public class BlacklistService : UserlistService | |||
{ | |||
public BlacklistService(IEnumerable<long> initialList = null) | |||
public BlacklistService(IEnumerable<ulong> initialList = null) | |||
: base(initialList) | |||
{ | |||
} | |||
@@ -7,39 +7,39 @@ namespace Discord.Commands.Permissions.Userlist | |||
{ | |||
public class UserlistService : IService | |||
{ | |||
protected readonly ConcurrentDictionary<long, bool> _userList; | |||
protected readonly ConcurrentDictionary<ulong, bool> _userList; | |||
private DiscordClient _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) | |||
_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 | |||
_userList = new ConcurrentDictionary<long, bool>(); | |||
_userList = new ConcurrentDictionary<ulong, bool>(); | |||
} | |||
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); | |||
} | |||
@@ -4,7 +4,7 @@ namespace Discord.Commands.Permissions.Userlist | |||
{ | |||
public class WhitelistService : UserlistService | |||
{ | |||
public WhitelistService(IEnumerable<long> initialList = null) | |||
public WhitelistService(IEnumerable<ulong> initialList = null) | |||
: base(initialList) | |||
{ | |||
} | |||
@@ -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<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 string Name => _name; | |||
@@ -69,9 +69,9 @@ namespace Discord.Modules | |||
_useChannelWhitelist = filterType.HasFlag(FilterType.ChannelWhitelist); | |||
_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 | |||
{ | |||
@@ -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); | |||
} | |||
} |
@@ -8,11 +8,11 @@ namespace Discord.API.Converters | |||
{ | |||
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) | |||
{ | |||
List<long> result = new List<long>(); | |||
List<ulong> result = new List<ulong>(); | |||
if (reader.TokenType == JsonToken.StartArray) | |||
{ | |||
reader.Read(); | |||
@@ -31,7 +31,7 @@ namespace Discord.API.Converters | |||
else | |||
{ | |||
writer.WriteStartArray(); | |||
foreach (var v in (IEnumerable<long>)value) | |||
foreach (var v in (IEnumerable<ulong>)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<long[]>); | |||
return objectType == typeof(IEnumerable<ulong[]>); | |||
} | |||
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) | |||
{ | |||
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(); | |||
@@ -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)); | |||
} | |||
} | |||
} |
@@ -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"; | |||
@@ -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; | |||
} | |||
@@ -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")] | |||
@@ -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")] | |||
@@ -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<long> Roles; | |||
public IEnumerable<ulong> Roles; | |||
} | |||
public class PruneUsersResponse | |||
@@ -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<long> Mentions; | |||
public IEnumerable<ulong> 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<long> Mentions; | |||
public IEnumerable<ulong> 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")] | |||
@@ -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")] | |||
@@ -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; | |||
} | |||
@@ -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; | |||
} | |||
@@ -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; | |||
} | |||
@@ -55,39 +55,30 @@ namespace Discord | |||
=> _rest.Post(Endpoints.AuthLogout); | |||
//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 (channelType == null) throw new ArgumentNullException(nameof(channelType)); | |||
var request = new CreateChannelRequest { Name = name, Type = channelType }; | |||
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 }; | |||
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)); | |||
} | |||
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 }; | |||
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 (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<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) | |||
return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count, relativeMessageId.Value, relativeDir == RelativeDirection.Before ? "before" : "after")); | |||
else | |||
@@ -117,10 +106,8 @@ namespace Discord | |||
} | |||
//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 }; | |||
return _rest.Post<CreateInviteResponse>(Endpoints.ChannelInvites(channelId), request); | |||
} | |||
@@ -130,10 +117,8 @@ namespace Discord | |||
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)); | |||
} | |||
public Task<AcceptInviteResponse> 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<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 }; | |||
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<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) | |||
return _rest.Get<PruneUsersResponse>(Endpoints.ServerPrune(serverId, days)); | |||
else | |||
@@ -191,94 +161,67 @@ namespace Discord | |||
} | |||
//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)); | |||
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); | |||
} | |||
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 (stream == null) throw new ArgumentNullException(nameof(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)); | |||
} | |||
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 }; | |||
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)); | |||
} | |||
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<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)); | |||
} | |||
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<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 }; | |||
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 (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<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)); | |||
} | |||
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) | |||
{ | |||
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId)); | |||
var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(icon, iconType, existingIcon) }; | |||
return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request); | |||
} | |||
@@ -8,15 +8,15 @@ using System.Threading.Tasks; | |||
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); | |||
private ConcurrentDictionary<long, Channel> _privateChannels; | |||
private ConcurrentDictionary<ulong, Channel> _privateChannels; | |||
public Channels(DiscordClient client, object writerLock) | |||
: base(client, writerLock) | |||
{ | |||
_privateChannels = new ConcurrentDictionary<long, Channel>(); | |||
_privateChannels = new ConcurrentDictionary<ulong, Channel>(); | |||
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; | |||
/// <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(); | |||
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); | |||
@@ -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; | |||
} | |||
@@ -12,7 +12,7 @@ using System.Threading.Tasks; | |||
namespace Discord | |||
{ | |||
internal sealed class Messages : AsyncCollection<long, Message> | |||
internal sealed class Messages : AsyncCollection<ulong, Message> | |||
{ | |||
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<long, Message> messages) | |||
public void Import(Dictionary<ulong, Message> 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<MessageQueueItem> _pendingMessages; | |||
/// <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)); | |||
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 | |||
} | |||
/// <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 (count < 0) throw new ArgumentNullException(nameof(count)); | |||
@@ -322,9 +322,9 @@ namespace Discord | |||
.Select(x => | |||
{ | |||
var msg = new Message(this, | |||
x["Id"].Value<long>(), | |||
x["Id"].Value<ulong>(), | |||
channel.Id, | |||
x["UserId"].Value<long>()); | |||
x["UserId"].Value<ulong>()); | |||
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); | |||
} | |||
} | |||
} |
@@ -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 | |||
{ | |||
@@ -7,12 +7,12 @@ using System.Threading.Tasks; | |||
namespace Discord | |||
{ | |||
internal sealed class Roles : AsyncCollection<long, Role> | |||
internal sealed class Roles : AsyncCollection<ulong, Role> | |||
{ | |||
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; | |||
/// <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(); | |||
return _roles[id]; | |||
@@ -8,12 +8,12 @@ using System.Threading.Tasks; | |||
namespace Discord | |||
{ | |||
internal sealed class Servers : AsyncCollection<long, Server> | |||
internal sealed class Servers : AsyncCollection<ulong, Server> | |||
{ | |||
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; | |||
/// <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(); | |||
return _servers[id]; | |||
@@ -8,12 +8,12 @@ using System.Threading.Tasks; | |||
namespace Discord | |||
{ | |||
internal sealed class GlobalUsers : AsyncCollection<long, GlobalUser> | |||
internal sealed class GlobalUsers : AsyncCollection<ulong, GlobalUser> | |||
{ | |||
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<User.CompositeKey, User> | |||
{ | |||
@@ -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<BanEventArgs> 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<BanEventArgs> 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; | |||
/// <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; | |||
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]; | |||
} | |||
/// <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 (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId)); | |||
CheckReady(); | |||
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> | |||
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<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)); | |||
@@ -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<long> roleIds = roles == null ? null : user.Roles | |||
IEnumerable<ulong> 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; | |||
} | |||
} | |||
@@ -92,7 +92,7 @@ namespace Discord | |||
public string SessionId => _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> | |||
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<ReadyEvent>(_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<MessageCreateEvent>(_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); | |||
@@ -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) | |||
{ | |||
@@ -3,12 +3,12 @@ | |||
namespace Discord | |||
{ | |||
internal class Reference<T> | |||
where T : CachedObject<long> | |||
where T : CachedObject<ulong> | |||
{ | |||
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; } | |||
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) { } | |||
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; | |||
_getItem = getItem; | |||
@@ -6,7 +6,7 @@ using System.Linq; | |||
namespace Discord | |||
{ | |||
public sealed class Channel : CachedObject<long> | |||
public sealed class Channel : CachedObject<ulong> | |||
{ | |||
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> _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<User> _recipient; | |||
//Collections | |||
@@ -95,15 +95,15 @@ namespace Discord | |||
} | |||
} | |||
[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> | |||
[JsonIgnore] | |||
public IEnumerable<Message> Messages => _messages?.Values ?? Enumerable.Empty<Message>(); | |||
[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> | |||
private PermissionOverwrite[] _permissionOverwrites; | |||
@@ -112,7 +112,7 @@ namespace Discord | |||
/// <summary> Returns the string used to mention this channel. </summary> | |||
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<Server>(serverId, | |||
@@ -133,7 +133,7 @@ namespace Discord | |||
x.Global.PrivateChannel = null; | |||
}); | |||
_permissionOverwrites = new PermissionOverwrite[0]; | |||
_members = new ConcurrentDictionary<long, ChannelMember>(); | |||
_members = new ConcurrentDictionary<ulong, ChannelMember>(); | |||
if (recipientId != null) | |||
{ | |||
@@ -143,7 +143,7 @@ namespace Discord | |||
//Local Cache | |||
if (client.Config.MessageCacheSize > 0) | |||
_messages = new ConcurrentDictionary<long, Message>(); | |||
_messages = new ConcurrentDictionary<ulong, Message>(); | |||
} | |||
internal override bool LoadReferences() | |||
{ | |||
@@ -6,7 +6,7 @@ using System.Linq; | |||
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> | |||
[JsonIgnore] | |||
@@ -28,23 +28,23 @@ namespace Discord | |||
} | |||
} | |||
[JsonProperty] | |||
private long? PrivateChannelId => _privateChannel?.Id; | |||
private ulong? PrivateChannelId => _privateChannel?.Id; | |||
private Channel _privateChannel; | |||
/// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary> | |||
[JsonIgnore] | |||
public IEnumerable<User> Memberships => _users.Select(x => x.Value); | |||
[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> | |||
public string Mention => $"<@{Id}>"; | |||
internal GlobalUser(DiscordClient client, long id) | |||
internal GlobalUser(DiscordClient client, ulong id) | |||
: base(client, id) | |||
{ | |||
_users = new ConcurrentDictionary<long, User>(); | |||
_users = new ConcurrentDictionary<ulong, User>(); | |||
} | |||
internal override bool LoadReferences() { return true; } | |||
internal override void UnloadReferences() | |||
@@ -3,16 +3,16 @@ using Discord.API; | |||
namespace Discord | |||
{ | |||
public sealed class Invite : CachedObject<string> | |||
public sealed class Invite | |||
{ | |||
public sealed class ServerInfo | |||
{ | |||
/// <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> | |||
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 | |||
{ | |||
/// <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> | |||
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 | |||
{ | |||
/// <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> | |||
public string Name { get; } | |||
/// <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> | |||
public string AvatarId { get; } | |||
/// <summary> Returns the full path to this user's avatar. </summary> | |||
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; } | |||
/// <summary> Returns information about the user that created this invite. </summary> | |||
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> | |||
public int MaxAge { get; private set; } | |||
/// <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> | |||
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) | |||
{ | |||
@@ -118,7 +118,7 @@ namespace Discord | |||
[JsonIgnore] | |||
public IEnumerable<User> MentionedUsers { get; internal set; } | |||
[JsonProperty] | |||
private IEnumerable<long> MentionedUserIds | |||
private IEnumerable<ulong> 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<Channel> MentionedChannels { get; internal set; } | |||
[JsonProperty] | |||
private IEnumerable<long> MentionedChannelIds | |||
private IEnumerable<ulong> 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<Role> MentionedRoles { get; internal set; } | |||
[JsonProperty] | |||
private IEnumerable<long> MentionedRoleIds | |||
private IEnumerable<ulong> 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> _channel; | |||
/// <summary> Returns the author of this message. </summary> | |||
[JsonIgnore] | |||
public User User => _user.Value; | |||
[JsonProperty] | |||
private long? UserId => _user.Id; | |||
private ulong? UserId => _user.Id; | |||
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) | |||
{ | |||
_channel = new Reference<Channel>(channelId, | |||
@@ -6,7 +6,7 @@ using System.Linq; | |||
namespace Discord | |||
{ | |||
public sealed class Role : CachedObject<long> | |||
public sealed class Role : CachedObject<ulong> | |||
{ | |||
/// <summary> Returns the name of this role. </summary> | |||
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> _server; | |||
/// <summary> Returns true if this is the role representing all users in a server. </summary> | |||
@@ -36,13 +36,13 @@ namespace Discord | |||
[JsonIgnore] | |||
public IEnumerable<User> Members => _server.Id != null ? (IsEveryone ? Server.Members : Server.Members.Where(x => x.HasRole(this))) : new User[0]; | |||
[JsonProperty] | |||
private IEnumerable<long> MemberIds => Members.Select(x => x.Id); | |||
private IEnumerable<ulong> MemberIds => Members.Select(x => x.Id); | |||
//TODO: Add local members cache | |||
/// <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"); } } | |||
internal Role(DiscordClient client, long id, long serverId) | |||
internal Role(DiscordClient client, ulong id, ulong serverId) | |||
: base(client, id) | |||
{ | |||
_server = new Reference<Server>(serverId, x => _client.Servers[x], x => x.AddRole(this), x => x.RemoveRole(this)); | |||
@@ -7,7 +7,7 @@ using System.Linq; | |||
namespace Discord | |||
{ | |||
public sealed class Server : CachedObject<long> | |||
public sealed class Server : CachedObject<ulong> | |||
{ | |||
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<User> _owner; | |||
/// <summary> Returns the AFK voice channel for this server (see AFKTimeout). </summary> | |||
[JsonIgnore] | |||
public Channel AFKChannel => _afkChannel.Value; | |||
[JsonProperty] | |||
private long? AFKChannelId => _afkChannel.Id; | |||
private ulong? AFKChannelId => _afkChannel.Id; | |||
private Reference<Channel> _afkChannel; | |||
/// <summary> Returns the default channel for this server. </summary> | |||
@@ -57,8 +57,8 @@ namespace Discord | |||
public Channel DefaultChannel { get; private set; } | |||
/// <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> | |||
[JsonIgnore] | |||
@@ -70,15 +70,15 @@ namespace Discord | |||
[JsonIgnore] | |||
public IEnumerable<Channel> VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice); | |||
[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> | |||
[JsonIgnore] | |||
public IEnumerable<User> Members => _members.Select(x => x.Value.User); | |||
[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> | |||
[JsonIgnore] | |||
@@ -87,22 +87,22 @@ namespace Discord | |||
[JsonIgnore] | |||
public IEnumerable<Role> Roles => _roles.Select(x => x.Value); | |||
[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) | |||
{ | |||
_owner = new Reference<User>(x => _client.Users[x, Id]); | |||
_afkChannel = new Reference<Channel>(x => _client.Channels[x]); | |||
//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 | |||
_bans = new ConcurrentDictionary<long, bool>(); | |||
_bans = new ConcurrentDictionary<ulong, bool>(); | |||
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); | |||
@@ -6,12 +6,12 @@ using System.Linq; | |||
namespace Discord | |||
{ | |||
public class User : CachedObject<long> | |||
public class User : CachedObject<ulong> | |||
{ | |||
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; | |||
UserId = userId; | |||
@@ -28,7 +28,7 @@ namespace Discord | |||
/// <summary> Returns the name of this user on this server. </summary> | |||
public string Name { get; private set; } | |||
/// <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> | |||
public string AvatarId { get; private set; } | |||
/// <summary> Returns the URL to this user's current avatar. </summary> | |||
@@ -66,20 +66,20 @@ namespace Discord | |||
public Server Server => _server.Value; | |||
private readonly Reference<Server> _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<Channel> _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<Role> Roles => _roles.Select(x => x.Value); | |||
private Dictionary<long, Role> _roles; | |||
private Dictionary<ulong, Role> _roles; | |||
[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> | |||
[JsonIgnore] | |||
@@ -134,7 +134,7 @@ namespace Discord | |||
/// <summary> Returns the string used to mention this user. </summary> | |||
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<GlobalUser>(id, | |||
@@ -156,7 +156,7 @@ namespace Discord | |||
x.CurrentUser = null; | |||
}); | |||
_voiceChannel = new Reference<Channel>(x => _client.Channels[x]); | |||
_roles = new Dictionary<long, Role>(); | |||
_roles = new Dictionary<ulong, Role>(); | |||
Status = UserStatus.Offline; | |||
@@ -240,7 +240,7 @@ namespace Discord | |||
} | |||
private void UpdateRoles(IEnumerable<Role> roles) | |||
{ | |||
Dictionary<long, Role> newRoles = new Dictionary<long, Role>(); | |||
var newRoles = new Dictionary<ulong, Role>(); | |||
if (roles != null) | |||
{ | |||
foreach (var r in roles) | |||
@@ -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; | |||