From c0cf4c6bb3219ffb409ad958b567439ada9e5a86 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 19 Sep 2024 19:36:11 +1000 Subject: [PATCH] Discord: Allow messages to adjust http web request state, e.g. for setting custom headers --- MCGalaxy/Modules/Relay/Discord/DiscordApiClient.cs | 1 + MCGalaxy/Modules/Relay/Discord/DiscordMessages.cs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/MCGalaxy/Modules/Relay/Discord/DiscordApiClient.cs b/MCGalaxy/Modules/Relay/Discord/DiscordApiClient.cs index 9c777ca54..5eb98e9c2 100644 --- a/MCGalaxy/Modules/Relay/Discord/DiscordApiClient.cs +++ b/MCGalaxy/Modules/Relay/Discord/DiscordApiClient.cs @@ -64,6 +64,7 @@ protected override void HandleNext() { string data = Json.SerialiseObject(msg.ToJson()); HttpUtil.SetRequestData(req, Encoding.UTF8.GetBytes(data)); + msg.OnRequest(req); res = req.GetResponse(); string resp = HttpUtil.GetResponseText(res); diff --git a/MCGalaxy/Modules/Relay/Discord/DiscordMessages.cs b/MCGalaxy/Modules/Relay/Discord/DiscordMessages.cs index ba689fb32..8ebb03408 100644 --- a/MCGalaxy/Modules/Relay/Discord/DiscordMessages.cs +++ b/MCGalaxy/Modules/Relay/Discord/DiscordMessages.cs @@ -18,6 +18,7 @@ permissions and limitations under the Licenses. using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.Text; using MCGalaxy.Config; @@ -40,6 +41,9 @@ public abstract class DiscordApiMessage /// Attempts to combine this message with a prior message to reduce API calls public virtual bool CombineWith(DiscordApiMessage prior) { return false; } + + /// Optionally adjusts the request to send to Discord + public virtual void OnRequest(HttpWebRequest req) { } /// Processes the response received from Discord public virtual void ProcessResponse(string response) { }