diff --git a/Maki/Discord.cs b/Maki/Discord.cs index c0d896e..45818c4 100644 --- a/Maki/Discord.cs +++ b/Maki/Discord.cs @@ -295,13 +295,7 @@ namespace Maki if (gi.Shards.HasValue) shards = gi.Shards.Value; } - - if (Gateway.Contains("?")) - Gateway = Gateway.Substring(0, Gateway.IndexOf('?')); - - if (!Gateway.EndsWith("/")) - Gateway += "/"; - + for (int i = 0; i < shards; i++) ShardClient.Create(i); } diff --git a/Maki/Gateway/GatewayShard.cs b/Maki/Gateway/GatewayShard.cs index 868d224..3a602d7 100644 --- a/Maki/Gateway/GatewayShard.cs +++ b/Maki/Gateway/GatewayShard.cs @@ -10,6 +10,10 @@ namespace Maki.Gateway /// class GatewayShard : IDisposable { + private const string GATEWAY_URL = "{0}?v={1}&encoding=json"; + + private readonly string GatewayUrl; + /// /// Session key for continuing a resuming after disconnecting /// @@ -54,13 +58,18 @@ namespace Maki.Gateway /// Constructor /// /// Shard Id - /// Parent DiscordClient instance - public GatewayShard(int id, Discord c) + /// Parent DiscordClient instance + /// Whether to immediately call Connect() + public GatewayShard(int id, Discord client, bool connect = true) { Id = id; - Client = c; + Client = client; + HeartbeatHandler = new GatewayHeartbeatManager(this); - Connect(); + GatewayUrl = string.Format(GATEWAY_URL, Client.Gateway, Discord.GATEWAY_VERSION); + + if (connect) + Connect(); } /// @@ -165,7 +174,7 @@ namespace Maki.Gateway /// public void Connect() { - WebSocket = new WebSocket($"{Client.Gateway}?v={Discord.GATEWAY_VERSION}&encoding=json"); + WebSocket = new WebSocket(GatewayUrl); // make wss not log anything on its own WebSocket.Log.Output = (LogData logData, string path) => { };