@@ -167,7 +167,7 @@ namespace Discord | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (model.Recipients.Value.Count() == 1) | |||||
if (model.Type == ChannelType.DM) | |||||
return new DMChannel(this, new User(model.Recipients.Value[0]), model); | return new DMChannel(this, new User(model.Recipients.Value[0]), model); | ||||
throw new NotImplementedException("Groups are not implemented."); | throw new NotImplementedException("Groups are not implemented."); | ||||
} | } | ||||
@@ -178,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.Where(m => m.Recipients.Value.Count() == 1).Select(x => new DMChannel(this, new User(x.Recipients.Value[0]), 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 /> | ||||
@@ -11,7 +11,7 @@ namespace Discord | |||||
public const int GatewayAPIVersion = 6; | 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/"; | ||||
@@ -442,9 +442,6 @@ namespace Discord | |||||
_lastSeq = seq.Value; | _lastSeq = seq.Value; | ||||
try | try | ||||
{ | { | ||||
string writeOutput = $"PACKET ---\n OPCODE: {opCode}\nSEQ: {(seq.HasValue ? seq.Value : -1)}\nTYPE: {type}\n========== BEGIN PAYLOAD ==========\n\n{payload}\n========================="; | |||||
System.IO.File.WriteAllText($"./discord-debug/{opCode}-{DateTime.Now.ToFileTime()}", writeOutput); | |||||
switch (opCode) | switch (opCode) | ||||
{ | { | ||||
case GatewayOpCode.Hello: | case GatewayOpCode.Hello: | ||||
@@ -508,7 +505,7 @@ 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 privateChannels = data.PrivateChannels.Where(c => c.Recipients.IsSpecified && c.Recipients.Value.Count() == 1).ToArray(); | |||||
var privateChannels = data.PrivateChannels.Where(c => c.Type == ChannelType.DM).ToArray(); | |||||
var dataStore = new DataStore( data.Guilds.Length, privateChannels.Length); | var dataStore = new DataStore( data.Guilds.Length, privateChannels.Length); | ||||
var currentUser = new CachedSelfUser(this, data.User); | var currentUser = new CachedSelfUser(this, data.User); | ||||
@@ -1264,7 +1261,7 @@ namespace Discord | |||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); | await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); | ||||
throw; | |||||
return; | |||||
} | } | ||||
#if BENCHMARK | #if BENCHMARK | ||||
} | } | ||||
@@ -13,35 +13,11 @@ 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) | ||||
{ | { | ||||
// TODO: This should probably just be a cast to an enum | |||||
switch ((long)reader.Value) | |||||
{ | |||||
case 0: | |||||
return ChannelType.Text; | |||||
case 1: | |||||
return ChannelType.DM; | |||||
case 2: | |||||
return ChannelType.Voice; | |||||
case 3: | |||||
return ChannelType.Group; | |||||
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); | writer.WriteValue((int)value); | ||||
} | } | ||||
} | } | ||||