-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly encode audit log/ban reasons
- Loading branch information
1 parent
692febf
commit 6771b3f
Showing
2 changed files
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ class RequestHandler { | |
this.options = options = Object.assign({ | ||
agent: client.options.agent || null, | ||
baseURL: Endpoints.BASE_URL, | ||
decodeReasons: true, | ||
disableLatencyCompensation: false, | ||
domain: "discord.com", | ||
latencyThreshold: client.options.latencyThreshold || 30000, | ||
|
@@ -92,9 +93,21 @@ class RequestHandler { | |
headers.Authorization = this._client._token; | ||
} | ||
if(body && body.reason) { // Audit log reason sniping | ||
headers["X-Audit-Log-Reason"] = body.reason; | ||
let unencodedReason = body.reason; | ||
if(this.options.decodeReasons) { | ||
try { | ||
if(unencodedReason.includes("%") && !unencodedReason.includes(" ")) { | ||
unencodedReason = decodeURIComponent(unencodedReason); | ||
} | ||
} catch(err) { | ||
this._client.emit("error", err); | ||
} | ||
} | ||
headers["X-Audit-Log-Reason"] = encodeURIComponent(unencodedReason); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bsian03
Collaborator
|
||
if((method !== "PUT" || !url.includes("/bans")) && (method !== "POST" || !url.includes("/prune"))) { | ||
delete body.reason; | ||
} else { | ||
body.reason = unencodedReason; | ||
} | ||
} | ||
if(file) { | ||
|
i have been using
encodeURI
without any issue and it accept the percentage and i never found any issue with it in production, What do you think about this?