diff --git a/lib/gateway/WSManager.ts b/lib/gateway/WSManager.ts index aa810f5..65a0fa9 100644 --- a/lib/gateway/WSManager.ts +++ b/lib/gateway/WSManager.ts @@ -65,6 +65,7 @@ export class WSManager extends TypedEmitter { #connectTimeout: NodeJS.Timeout | null; compression: boolean; #sharedZLib!: Pako.Inflate | Inflate; + isOfficialMarkdownEnabled: boolean; constructor(client: Client, params: WSManagerParams) { super(); Object.defineProperties(this, { @@ -108,6 +109,7 @@ export class WSManager extends TypedEmitter { this.#connectTimeout = null; this.compression = params.compression ?? false; // not enabled, guilded doesn't support compression for now. + this.isOfficialMarkdownEnabled = client.params.isOfficialMarkdownEnabled ?? params.isOfficialMarkdownEnabled ?? true; } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @@ -146,6 +148,7 @@ export class WSManager extends TypedEmitter { } const wsoptions = { headers: { Authorization: `Bearer ${this.params.token}` }, protocol: "HTTPS" }; + Object.assign(wsoptions.headers, { "x-guilded-bot-api-use-official-markdown": this.isOfficialMarkdownEnabled }); // temporary header if (this.replayEventsCondition) Object.assign(wsoptions.headers, { "guilded-last-message-id": this.lastMessageID }); this.ws = new WebSocket(this.proxyURL, wsoptions); @@ -431,4 +434,6 @@ export interface WSManagerParams { client: Client; /** Compression */ compression?: boolean; + /** Enable official Guilded markdown header to opt-in. */ + isOfficialMarkdownEnabled?: boolean; } diff --git a/lib/rest/RequestHandler.ts b/lib/rest/RequestHandler.ts index 5dc7e70..624e6c2 100644 --- a/lib/rest/RequestHandler.ts +++ b/lib/rest/RequestHandler.ts @@ -74,6 +74,7 @@ export class RequestHandler { const controller = new AbortController(); headers["User-Agent"] = `TouchGuild ${pkgconfig.branch} (${pkgconfig.version}) Node.JS ${pkgconfig.NodeJSVersion}`; + headers["x-guilded-bot-api-use-official-markdown"] = String(this.#manager.client.params.isOfficialMarkdownEnabled ?? true); // temporary header if (typeof options.auth === "string"){ const tokenArgs = options.auth.split(" "); diff --git a/lib/types/client.d.ts b/lib/types/client.d.ts index 1e4d64d..d3d86cf 100644 --- a/lib/types/client.d.ts +++ b/lib/types/client.d.ts @@ -38,6 +38,14 @@ export interface ClientOptions { */ waitForCaching?: boolean; + /** + * Fixes & improves Guilded API markdown and makes it Commonmark compliant. + * + * Enabled by default, can be disabled to use old version of the Guilded markdown. (if facing issues for example) + */ + isOfficialMarkdownEnabled?: boolean; + + /** Set your own limit to how much messages, threads, comments, events.. will be stored in cache before deletion. */ collectionLimits?: { messages?: number; threads?: number;