Browse Source

Merge 6ea3ce3807 into edb4941e04

pull/124/merge
Christopher F GitHub 9 years ago
parent
commit
083db0707e
14 changed files with 55 additions and 43 deletions
  1. +6
    -5
      src/Discord.Net/API/Common/Channel.cs
  2. +2
    -0
      src/Discord.Net/API/Common/Message.cs
  3. +2
    -1
      src/Discord.Net/API/Common/RelationshipType.cs
  4. +6
    -2
      src/Discord.Net/DiscordClient.cs
  5. +2
    -2
      src/Discord.Net/DiscordConfig.cs
  6. +6
    -5
      src/Discord.Net/DiscordSocketClient.cs
  7. +4
    -3
      src/Discord.Net/Entities/Channels/ChannelType.cs
  8. +1
    -1
      src/Discord.Net/Entities/Channels/DMChannel.cs
  9. +2
    -2
      src/Discord.Net/Entities/Guilds/Guild.cs
  10. +2
    -0
      src/Discord.Net/Entities/Messages/IMessage.cs
  11. +1
    -0
      src/Discord.Net/Entities/Messages/Message.cs
  12. +17
    -0
      src/Discord.Net/Entities/Messages/MessageType.cs
  13. +2
    -2
      src/Discord.Net/Entities/WebSocket/CachedGuild.cs
  14. +2
    -20
      src/Discord.Net/Net/Converters/ChannelTypeConverter.cs

+ 6
- 5
src/Discord.Net/API/Common/Channel.cs View File

@@ -11,14 +11,14 @@ namespace Discord.API
public bool IsPrivate { get; set; } public bool IsPrivate { get; set; }
[JsonProperty("last_message_id")] [JsonProperty("last_message_id")]
public ulong? LastMessageId { get; set; } public ulong? LastMessageId { get; set; }
[JsonProperty("type")]
public ChannelType Type { get; set; }


//GuildChannel //GuildChannel
[JsonProperty("guild_id")] [JsonProperty("guild_id")]
public Optional<ulong> GuildId { get; set; } public Optional<ulong> GuildId { get; set; }
[JsonProperty("name")] [JsonProperty("name")]
public Optional<string> Name { get; set; } public Optional<string> Name { get; set; }
[JsonProperty("type")]
public Optional<ChannelType> Type { get; set; }
[JsonProperty("position")] [JsonProperty("position")]
public Optional<int> Position { get; set; } public Optional<int> Position { get; set; }
[JsonProperty("permission_overwrites")] [JsonProperty("permission_overwrites")]
@@ -34,8 +34,9 @@ namespace Discord.API
[JsonProperty("user_limit")] [JsonProperty("user_limit")]
public Optional<int> UserLimit { get; set; } public Optional<int> UserLimit { get; set; }


//DMChannel
[JsonProperty("recipient")]
public Optional<User> Recipient { get; set; }
//DMChannel or GroupChannel
[JsonProperty("recipients")]
public Optional<User[]> Recipients { get; set; }

} }
} }

+ 2
- 0
src/Discord.Net/API/Common/Message.cs View File

@@ -9,6 +9,8 @@ namespace Discord.API
public ulong Id { get; set; } public ulong Id { get; set; }
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
[JsonProperty("type")]
public MessageType Type { get; set; }
[JsonProperty("author")] [JsonProperty("author")]
public Optional<User> Author { get; set; } public Optional<User> Author { get; set; }
[JsonProperty("content")] [JsonProperty("content")]


+ 2
- 1
src/Discord.Net/API/Common/RelationshipType.cs View File

@@ -4,6 +4,7 @@
{ {
Friend = 1, Friend = 1,
Blocked = 2, Blocked = 2,
Pending = 4
Incoming = 3,
Outgoing = 3
} }
} }

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

@@ -166,7 +166,11 @@ namespace Discord
} }
} }
else 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; return null;
} }
@@ -174,7 +178,7 @@ namespace Discord
public virtual async Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync() public virtual async Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync()
{ {
var models = await ApiClient.GetMyDMsAsync().ConfigureAwait(false); 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();
} }


/// <inheritdoc /> /// <inheritdoc />


+ 2
- 2
src/Discord.Net/DiscordConfig.cs View File

@@ -8,10 +8,10 @@ namespace Discord
public static string Version { get; } = typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown"; 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 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 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 CDNUrl = "https://cdn.discordapp.com/";
public const string InviteUrl = "https://discord.gg/"; public const string InviteUrl = "https://discord.gg/";




+ 6
- 5
src/Discord.Net/DiscordSocketClient.cs View File

@@ -335,7 +335,7 @@ namespace Discord
} }
internal CachedDMChannel AddDMChannel(API.Channel model, DataStore dataStore) 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); var channel = new CachedDMChannel(this, new CachedDMUser(recipient), model);
recipient.AddRef(); recipient.AddRef();
dataStore.AddDMChannel(channel); dataStore.AddDMChannel(channel);
@@ -505,7 +505,8 @@ namespace Discord
await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false); await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false);
var data = (payload as JToken).ToObject<ReadyEvent>(_serializer); var data = (payload as JToken).ToObject<ReadyEvent>(_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); var currentUser = new CachedSelfUser(this, data.User);
int unavailableGuilds = 0; int unavailableGuilds = 0;
@@ -517,8 +518,8 @@ namespace Discord
if (model.Unavailable == true) if (model.Unavailable == true)
unavailableGuilds++; 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; _sessionId = data.SessionId;
_currentUser = currentUser; _currentUser = currentUser;
@@ -740,7 +741,7 @@ namespace Discord
} }
} }
else else
channel = RemoveDMChannel(data.Recipient.Value.Id);
channel = RemoveDMChannel(data.Id);
if (channel != null) if (channel != null)
await _channelDestroyedEvent.InvokeAsync(channel).ConfigureAwait(false); await _channelDestroyedEvent.InvokeAsync(channel).ConfigureAwait(false);
else else


+ 4
- 3
src/Discord.Net/Entities/Channels/ChannelType.cs View File

@@ -2,8 +2,9 @@
{ {
public enum ChannelType : byte public enum ChannelType : byte
{ {
DM,
Text,
Voice
DM = 1,
Text = 0,
Voice = 2,
Group = 3
} }
} }

+ 1
- 1
src/Discord.Net/Entities/Channels/DMChannel.cs View File

@@ -30,7 +30,7 @@ namespace Discord
{ {
if (/*source == UpdateSource.Rest && */IsAttached) return; 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() public async Task UpdateAsync()


+ 2
- 2
src/Discord.Net/Entities/Guilds/Guild.cs View File

@@ -296,14 +296,14 @@ namespace Discord


internal GuildChannel ToChannel(API.Channel model) internal GuildChannel ToChannel(API.Channel model)
{ {
switch (model.Type.Value)
switch (model.Type)
{ {
case ChannelType.Text: case ChannelType.Text:
return new TextChannel(this, model); return new TextChannel(this, model);
case ChannelType.Voice: case ChannelType.Voice:
return new VoiceChannel(this, model); return new VoiceChannel(this, model);
default: default:
throw new InvalidOperationException($"Unknown channel type: {model.Type.Value}");
throw new InvalidOperationException($"Unknown channel type: {model.Type}");
} }
} }




+ 2
- 0
src/Discord.Net/Entities/Messages/IMessage.cs View File

@@ -17,6 +17,8 @@ namespace Discord
string Text { get; } string Text { get; }
/// <summary> Gets the time this message was sent. </summary> /// <summary> Gets the time this message was sent. </summary>
DateTimeOffset Timestamp { get; } DateTimeOffset Timestamp { get; }
/// <summary> Gets the type of message this is. Value will always be default, unless the message was sent in a group. </summary>
MessageType Type { get; }


/// <summary> Gets the channel this message was sent to. </summary> /// <summary> Gets the channel this message was sent to. </summary>
IMessageChannel Channel { get; } IMessageChannel Channel { get; }


+ 1
- 0
src/Discord.Net/Entities/Messages/Message.cs View File

@@ -18,6 +18,7 @@ namespace Discord
public bool IsTTS { get; private set; } public bool IsTTS { get; private set; }
public string Text { get; private set; } public string Text { get; private set; }
public bool IsPinned { get; private set; } public bool IsPinned { get; private set; }
public MessageType Type { get; private set; }
public IMessageChannel Channel { get; } public IMessageChannel Channel { get; }
public IUser Author { get; } public IUser Author { get; }


+ 17
- 0
src/Discord.Net/Entities/Messages/MessageType.cs View File

@@ -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
}
}

+ 2
- 2
src/Discord.Net/Entities/WebSocket/CachedGuild.cs View File

@@ -311,14 +311,14 @@ namespace Discord


new internal ICachedGuildChannel ToChannel(ChannelModel model) new internal ICachedGuildChannel ToChannel(ChannelModel model)
{ {
switch (model.Type.Value)
switch (model.Type)
{ {
case ChannelType.Text: case ChannelType.Text:
return new CachedTextChannel(this, model); return new CachedTextChannel(this, model);
case ChannelType.Voice: case ChannelType.Voice:
return new CachedVoiceChannel(this, model); return new CachedVoiceChannel(this, model);
default: default:
throw new InvalidOperationException($"Unknown channel type: {model.Type.Value}");
throw new InvalidOperationException($"Unknown channel type: {model.Type}");
} }
} }




+ 2
- 20
src/Discord.Net/Net/Converters/ChannelTypeConverter.cs View File

@@ -13,30 +13,12 @@ namespace Discord.Net.Converters


public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 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) 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);
} }
} }
} }

Loading…
Cancel
Save