Browse Source

READY won't fire until all GUILD_CREATES are received

really ugly fix for a few of the major discord.net bots that were crashing during startup and/or had 0 servers in their READY event.
pull/45/head
Christopher F 9 years ago
parent
commit
4f16f12efc
1 changed files with 8 additions and 1 deletions
  1. +8
    -1
      src/Discord.Net/DiscordClient.cs

+ 8
- 1
src/Discord.Net/DiscordClient.cs View File

@@ -34,6 +34,8 @@ namespace Discord
private Dictionary<string, Region> _regions; private Dictionary<string, Region> _regions;
private Stopwatch _connectionStopwatch; private Stopwatch _connectionStopwatch;


private int _readyServerCount;

internal Logger Logger { get; } internal Logger Logger { get; }


/// <summary> Gets the configuration object used to make this client. </summary> /// <summary> Gets the configuration object used to make this client. </summary>
@@ -493,6 +495,8 @@ namespace Discord
_channels = new ConcurrentDictionary<ulong, Channel>(2, (int)(data.Guilds.Length * 2 * 1.05)); _channels = new ConcurrentDictionary<ulong, Channel>(2, (int)(data.Guilds.Length * 2 * 1.05));
_privateChannels = new ConcurrentDictionary<ulong, Channel>(2, (int)(data.PrivateChannels.Length * 1.05)); _privateChannels = new ConcurrentDictionary<ulong, Channel>(2, (int)(data.PrivateChannels.Length * 1.05));


_readyServerCount = data.Guilds.Length;

SessionId = data.SessionId; SessionId = data.SessionId;
PrivateUser = new User(this, data.User.Id, null); PrivateUser = new User(this, data.User.Id, null);
PrivateUser.Update(data.User); PrivateUser.Update(data.User);
@@ -514,7 +518,8 @@ namespace Discord
var channel = AddPrivateChannel(model.Id, model.Recipient.Id); var channel = AddPrivateChannel(model.Id, model.Recipient.Id);
channel.Update(model); channel.Update(model);
} }
EndConnect();
Log.Info("Discord", "READY was processed, holding off to raise event until servers are filled.");
//EndConnect();
} }
break; break;


@@ -540,6 +545,8 @@ namespace Discord
OnServerAvailable(server); OnServerAvailable(server);
} }
} }
if (State == ConnectionState.Connecting && Servers.Count() >= _readyServerCount)
EndConnect();
} }
break; break;
case "GUILD_UPDATE": case "GUILD_UPDATE":


Loading…
Cancel
Save