diff --git a/src/Discord.Net/API/Common/Channel.cs b/src/Discord.Net/API/Common/Channel.cs index b0789b111..19cd79cc7 100644 --- a/src/Discord.Net/API/Common/Channel.cs +++ b/src/Discord.Net/API/Common/Channel.cs @@ -11,14 +11,14 @@ namespace Discord.API public bool IsPrivate { get; set; } [JsonProperty("last_message_id")] public ulong? LastMessageId { get; set; } + [JsonProperty("type")] + public ChannelType Type { get; set; } //GuildChannel [JsonProperty("guild_id")] public Optional GuildId { get; set; } [JsonProperty("name")] public Optional Name { get; set; } - [JsonProperty("type")] - public Optional Type { get; set; } [JsonProperty("position")] public Optional Position { get; set; } [JsonProperty("permission_overwrites")] @@ -34,8 +34,9 @@ namespace Discord.API [JsonProperty("user_limit")] public Optional UserLimit { get; set; } - //DMChannel - [JsonProperty("recipient")] - public Optional Recipient { get; set; } + //DMChannel or GroupChannel + [JsonProperty("recipients")] + public Optional Recipients { get; set; } + } } diff --git a/src/Discord.Net/API/Common/Message.cs b/src/Discord.Net/API/Common/Message.cs index be5305114..7deacf792 100644 --- a/src/Discord.Net/API/Common/Message.cs +++ b/src/Discord.Net/API/Common/Message.cs @@ -9,6 +9,8 @@ namespace Discord.API public ulong Id { get; set; } [JsonProperty("channel_id")] public ulong ChannelId { get; set; } + [JsonProperty("type")] + public MessageType Type { get; set; } [JsonProperty("author")] public Optional Author { get; set; } [JsonProperty("content")] diff --git a/src/Discord.Net/API/Common/RelationshipType.cs b/src/Discord.Net/API/Common/RelationshipType.cs index 53be3a98f..8ed431d09 100644 --- a/src/Discord.Net/API/Common/RelationshipType.cs +++ b/src/Discord.Net/API/Common/RelationshipType.cs @@ -4,6 +4,7 @@ { Friend = 1, Blocked = 2, - Pending = 4 + Incoming = 3, + Outgoing = 3 } } diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index d80b374f4..b83d624fe 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -166,7 +166,11 @@ namespace Discord } } else - return new DMChannel(this, new User(model.Recipient.Value), model); + { + if (model.Type == ChannelType.DM) + return new DMChannel(this, new User(model.Recipients.Value[0]), model); + throw new NotImplementedException("Groups are not implemented."); + } } return null; } @@ -174,7 +178,7 @@ namespace Discord public virtual async Task> GetDMChannelsAsync() { var models = await ApiClient.GetMyDMsAsync().ConfigureAwait(false); - return models.Select(x => new DMChannel(this, new User(x.Recipient.Value), x)).ToImmutableArray(); + return models.Where(m => m.Type == ChannelType.DM).Select(x => new DMChannel(this, new User(x.Recipients.Value[0]), x)).ToImmutableArray(); } /// diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs index 75d5b7a21..b25d2f75c 100644 --- a/src/Discord.Net/DiscordConfig.cs +++ b/src/Discord.Net/DiscordConfig.cs @@ -8,10 +8,10 @@ namespace Discord public static string Version { get; } = typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown"; public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; - public const int GatewayAPIVersion = 5; + public const int GatewayAPIVersion = 6; public const string GatewayEncoding = "json"; - public const string ClientAPIUrl = "https://discordapp.com/api/"; + public const string ClientAPIUrl = "https://discordapp.com/api/v6/"; public const string CDNUrl = "https://cdn.discordapp.com/"; public const string InviteUrl = "https://discord.gg/"; diff --git a/src/Discord.Net/DiscordSocketClient.cs b/src/Discord.Net/DiscordSocketClient.cs index f3948a1eb..da0c9580b 100644 --- a/src/Discord.Net/DiscordSocketClient.cs +++ b/src/Discord.Net/DiscordSocketClient.cs @@ -335,7 +335,7 @@ namespace Discord } internal CachedDMChannel AddDMChannel(API.Channel model, DataStore dataStore) { - var recipient = GetOrAddUser(model.Recipient.Value, dataStore); + var recipient = GetOrAddUser(model.Recipients.Value[0], dataStore); var channel = new CachedDMChannel(this, new CachedDMUser(recipient), model); recipient.AddRef(); dataStore.AddDMChannel(channel); @@ -505,7 +505,8 @@ namespace Discord await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); - var dataStore = new DataStore( data.Guilds.Length, data.PrivateChannels.Length); + var privateChannels = data.PrivateChannels.Where(c => c.Type == ChannelType.DM).ToArray(); + var dataStore = new DataStore( data.Guilds.Length, privateChannels.Length); var currentUser = new CachedSelfUser(this, data.User); int unavailableGuilds = 0; @@ -517,8 +518,8 @@ namespace Discord if (model.Unavailable == true) unavailableGuilds++; } - for (int i = 0; i < data.PrivateChannels.Length; i++) - AddDMChannel(data.PrivateChannels[i], dataStore); + for (int i = 0; i < privateChannels.Length; i++) + AddDMChannel(privateChannels[i], dataStore); _sessionId = data.SessionId; _currentUser = currentUser; @@ -740,7 +741,7 @@ namespace Discord } } else - channel = RemoveDMChannel(data.Recipient.Value.Id); + channel = RemoveDMChannel(data.Id); if (channel != null) await _channelDestroyedEvent.InvokeAsync(channel).ConfigureAwait(false); else diff --git a/src/Discord.Net/Entities/Channels/ChannelType.cs b/src/Discord.Net/Entities/Channels/ChannelType.cs index e6a3a1e00..ccffa1297 100644 --- a/src/Discord.Net/Entities/Channels/ChannelType.cs +++ b/src/Discord.Net/Entities/Channels/ChannelType.cs @@ -2,8 +2,9 @@ { public enum ChannelType : byte { - DM, - Text, - Voice + DM = 1, + Text = 0, + Voice = 2, + Group = 3 } } diff --git a/src/Discord.Net/Entities/Channels/DMChannel.cs b/src/Discord.Net/Entities/Channels/DMChannel.cs index a5adc4284..f1635ad8f 100644 --- a/src/Discord.Net/Entities/Channels/DMChannel.cs +++ b/src/Discord.Net/Entities/Channels/DMChannel.cs @@ -30,7 +30,7 @@ namespace Discord { if (/*source == UpdateSource.Rest && */IsAttached) return; - (Recipient as User).Update(model.Recipient.Value, source); + (Recipient as User).Update(model.Recipients.Value[0], source); } public async Task UpdateAsync() diff --git a/src/Discord.Net/Entities/Guilds/Guild.cs b/src/Discord.Net/Entities/Guilds/Guild.cs index 1e400cce0..9589420a3 100644 --- a/src/Discord.Net/Entities/Guilds/Guild.cs +++ b/src/Discord.Net/Entities/Guilds/Guild.cs @@ -296,14 +296,14 @@ namespace Discord internal GuildChannel ToChannel(API.Channel model) { - switch (model.Type.Value) + switch (model.Type) { case ChannelType.Text: return new TextChannel(this, model); case ChannelType.Voice: return new VoiceChannel(this, model); default: - throw new InvalidOperationException($"Unknown channel type: {model.Type.Value}"); + throw new InvalidOperationException($"Unknown channel type: {model.Type}"); } } diff --git a/src/Discord.Net/Entities/Messages/IMessage.cs b/src/Discord.Net/Entities/Messages/IMessage.cs index df620a516..8d34cddde 100644 --- a/src/Discord.Net/Entities/Messages/IMessage.cs +++ b/src/Discord.Net/Entities/Messages/IMessage.cs @@ -17,6 +17,8 @@ namespace Discord string Text { get; } /// Gets the time this message was sent. DateTimeOffset Timestamp { get; } + /// Gets the type of message this is. Value will always be default, unless the message was sent in a group. + MessageType Type { get; } /// Gets the channel this message was sent to. IMessageChannel Channel { get; } diff --git a/src/Discord.Net/Entities/Messages/Message.cs b/src/Discord.Net/Entities/Messages/Message.cs index db3929af3..ee261a16e 100644 --- a/src/Discord.Net/Entities/Messages/Message.cs +++ b/src/Discord.Net/Entities/Messages/Message.cs @@ -18,6 +18,7 @@ namespace Discord public bool IsTTS { get; private set; } public string Text { get; private set; } public bool IsPinned { get; private set; } + public MessageType Type { get; private set; } public IMessageChannel Channel { get; } public IUser Author { get; } diff --git a/src/Discord.Net/Entities/Messages/MessageType.cs b/src/Discord.Net/Entities/Messages/MessageType.cs new file mode 100644 index 000000000..8e62afe4f --- /dev/null +++ b/src/Discord.Net/Entities/Messages/MessageType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord +{ + public enum MessageType + { + Default = 0, + RecipientAdd = 1, + RecipientRemove = 2, + Call = 3, + NameChange = 4, + IconChange = 5 + } +} diff --git a/src/Discord.Net/Entities/WebSocket/CachedGuild.cs b/src/Discord.Net/Entities/WebSocket/CachedGuild.cs index 569347d73..55b7b6e6b 100644 --- a/src/Discord.Net/Entities/WebSocket/CachedGuild.cs +++ b/src/Discord.Net/Entities/WebSocket/CachedGuild.cs @@ -311,14 +311,14 @@ namespace Discord new internal ICachedGuildChannel ToChannel(ChannelModel model) { - switch (model.Type.Value) + switch (model.Type) { case ChannelType.Text: return new CachedTextChannel(this, model); case ChannelType.Voice: return new CachedVoiceChannel(this, model); default: - throw new InvalidOperationException($"Unknown channel type: {model.Type.Value}"); + throw new InvalidOperationException($"Unknown channel type: {model.Type}"); } } diff --git a/src/Discord.Net/Net/Converters/ChannelTypeConverter.cs b/src/Discord.Net/Net/Converters/ChannelTypeConverter.cs index 48bcbd755..f23910368 100644 --- a/src/Discord.Net/Net/Converters/ChannelTypeConverter.cs +++ b/src/Discord.Net/Net/Converters/ChannelTypeConverter.cs @@ -13,30 +13,12 @@ namespace Discord.Net.Converters public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - switch ((string)reader.Value) - { - case "text": - return ChannelType.Text; - case "voice": - return ChannelType.Voice; - default: - throw new JsonSerializationException("Unknown channel type"); - } + return (ChannelType)((long)reader.Value); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - switch ((ChannelType)value) - { - case ChannelType.Text: - writer.WriteValue("text"); - break; - case ChannelType.Voice: - writer.WriteValue("voice"); - break; - default: - throw new JsonSerializationException("Invalid channel type"); - } + writer.WriteValue((int)value); } } }