Browse Source

Clean up support for Gateway V6

pull/124/head
Christopher F 9 years ago
parent
commit
6ea3ce3807
4 changed files with 6 additions and 33 deletions
  1. +2
    -2
      src/Discord.Net/DiscordClient.cs
  2. +1
    -1
      src/Discord.Net/DiscordConfig.cs
  3. +2
    -5
      src/Discord.Net/DiscordSocketClient.cs
  4. +1
    -25
      src/Discord.Net/Net/Converters/ChannelTypeConverter.cs

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

@@ -167,7 +167,7 @@ namespace Discord
}
else
{
if (model.Recipients.Value.Count() == 1)
if (model.Type == ChannelType.DM)
return new DMChannel(this, new User(model.Recipients.Value[0]), model);
throw new NotImplementedException("Groups are not implemented.");
}
@@ -178,7 +178,7 @@ namespace Discord
public virtual async Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync()
{
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 />


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

@@ -11,7 +11,7 @@ namespace Discord
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/";



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

@@ -442,9 +442,6 @@ namespace Discord
_lastSeq = seq.Value;
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)
{
case GatewayOpCode.Hello:
@@ -508,7 +505,7 @@ namespace Discord
await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false);
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 currentUser = new CachedSelfUser(this, data.User);
@@ -1264,7 +1261,7 @@ namespace Discord
catch (Exception ex)
{
await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false);
throw;
return;
}
#if BENCHMARK
}


+ 1
- 25
src/Discord.Net/Net/Converters/ChannelTypeConverter.cs View File

@@ -13,35 +13,11 @@ namespace Discord.Net.Converters

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)
{
/*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