Skip to content

Commit

Permalink
fix!: gateway compression, encoding and version was never applied
Browse files Browse the repository at this point in the history
thanks dzi, honestly

Co-Authored-By: Dziurwa <[email protected]>
  • Loading branch information
Lulalaby and Dziurwa14 committed Dec 30, 2023
1 parent 50a14a4 commit e717107
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions DisCatSharp/Clients/DiscordClient.WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ internal async Task InternalConnectAsync()
this.WebSocketClient.MessageReceived += SocketOnMessage;
this.WebSocketClient.ExceptionThrown += SocketOnException;

var gwuri = new QueryUriBuilder(this.GatewayUri)
.AddParameter("v", this.Configuration.ApiVersion)
.AddParameter("encoding", "json");
var gwuri = this.GatewayUri.AddParameter("v", this.Configuration.ApiVersion).AddParameter("encoding", "json");

if (this.Configuration.GatewayCompressionLevel == GatewayCompressionLevel.Stream)
gwuri.AddParameter("compress", "zlib-stream");
gwuri = gwuri.AddParameter("compress", "zlib-stream");

this.GatewayUri = gwuri;

this.Logger.LogDebug(LoggerEvents.Startup, "Connecting to {gw}", this.GatewayUri.AbsoluteUri);

await this.WebSocketClient.ConnectAsync(gwuri.Build()).ConfigureAwait(false);
await this.WebSocketClient.ConnectAsync(this.GatewayUri).ConfigureAwait(false);
return;

Task SocketOnConnect(IWebSocketClient sender, SocketEventArgs e)
Expand Down
18 changes: 18 additions & 0 deletions DisCatSharp/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;

using DisCatSharp.Common;
using DisCatSharp.Common.RegularExpressions;
Expand Down Expand Up @@ -89,6 +90,23 @@ static Utilities()
VersionHeader = $"DiscordBot (https://github.com/Aiko-IT-Systems/DisCatSharp, v{vs})";
}

/// <summary>
/// Adds the specified parameter to the Query String.
/// </summary>
/// <param name="url"></param>
/// <param name="paramName">Name of the parameter to add.</param>
/// <param name="paramValue">Value for the parameter to add.</param>
/// <returns>Url with added parameter.</returns>
public static Uri AddParameter(this Uri url, string paramName, string paramValue)
{
var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query[paramName] = paramValue;
uriBuilder.Query = query.ToString();

return uriBuilder.Uri;
}

/// <summary>
/// Gets the api base uri.
/// </summary>
Expand Down

0 comments on commit e717107

Please sign in to comment.