snowtransfer
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -682,2 +682,4 @@ /// <reference types="node" /> | ||
components?: Array<import("discord-typings").MessageComponentData>; | ||
sticker_ids?: Array<string>; | ||
attachments?: Array<Exclude<import("discord-typings").AttachmentData, "ephemeral" | "proxy_url" | "url" | "size">>; | ||
} | ||
@@ -720,5 +722,5 @@ interface EditMessageData { | ||
/** | ||
* [Attached files](https://discord.com/developers/docs/resources/channel#attachment-object) to keep | ||
* [Attached files](https://discord.com/developers/docs/resources/channel#attachment-object) to remove or edit descriptions for | ||
*/ | ||
attachments?: Array<import("discord-typings").AttachmentData>; | ||
attachments?: Array<Exclude<import("discord-typings").AttachmentData, "ephemeral" | "proxy_url" | "url" | "size">>; | ||
/** | ||
@@ -725,0 +727,0 @@ * [Buttons](https://discord.com/developers/docs/interactions/message-components#component-object) to add to the message |
@@ -191,8 +191,6 @@ "use strict"; | ||
} | ||
if (data.files) { | ||
if (data.files) | ||
return this.requestHandler.request(Endpoints_1.default.CHANNEL_MESSAGES(channelId), "post", "multipart", data); | ||
} | ||
else { | ||
else | ||
return this.requestHandler.request(Endpoints_1.default.CHANNEL_MESSAGES(channelId), "post", "json", data); | ||
} | ||
} | ||
@@ -245,8 +243,6 @@ /** | ||
} | ||
if (data.files) { | ||
if (data.files) | ||
return this.requestHandler.request(Endpoints_1.default.CHANNEL_MESSAGE(channelId, messageId), "patch", "multipart", data); | ||
} | ||
else { | ||
else | ||
return this.requestHandler.request(Endpoints_1.default.CHANNEL_MESSAGE(channelId, messageId), "patch", "json", data); | ||
} | ||
} | ||
@@ -253,0 +249,0 @@ /** |
@@ -183,3 +183,3 @@ "use strict"; | ||
createFollowupMessage(appId, token, data) { | ||
// @ts-ignore | ||
// wait is always true for interactions | ||
return this.webhooks.executeWebhook(appId, token, data); | ||
@@ -186,0 +186,0 @@ } |
@@ -134,4 +134,5 @@ /// <reference types="node" /> | ||
executeWebhook(webhookId: string, token: string, data: WebhookCreateMessageData, options?: { | ||
wait?: boolean; | ||
wait?: false; | ||
disableEveryone?: boolean; | ||
thread_id?: string; | ||
}): Promise<void>; | ||
@@ -141,2 +142,3 @@ executeWebhook(webhookId: string, token: string, data: WebhookCreateMessageData, options: { | ||
disableEveryone?: boolean; | ||
thread_id?: string; | ||
}): Promise<import("discord-typings").MessageData>; | ||
@@ -154,2 +156,3 @@ /** | ||
disableEveryone?: boolean; | ||
thread_id?: string; | ||
}): Promise<void>; | ||
@@ -166,2 +169,3 @@ /** | ||
wait?: boolean; | ||
thread_id?: string; | ||
}): Promise<void>; | ||
@@ -286,3 +290,3 @@ /** | ||
allowed_mentions?: import("discord-typings").AllowedMentionsData | null; | ||
attachments?: Array<import("discord-typings").AttachmentData> | null; | ||
attachments?: Array<Exclude<import("discord-typings").AttachmentData, "ephemeral" | "proxy_url" | "url" | "size">>; | ||
/** | ||
@@ -292,3 +296,4 @@ * [Buttons](https://discord.com/developers/docs/interactions/message-components#component-object) to add to the message | ||
components?: Array<import("discord-typings").MessageComponentData>; | ||
thread_id?: string; | ||
} | ||
export = WebhookMethods; |
@@ -149,5 +149,5 @@ "use strict"; | ||
if (data.files) | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN(webhookId, token) + (options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "", "post", "multipart", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN(webhookId, token) + ((options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "") + ((options === null || options === void 0 ? void 0 : options.thread_id) ? `${(options === null || options === void 0 ? void 0 : options.wait) ? "&" : "?"}thread_id=${options.thread_id}` : ""), "post", "multipart", data); | ||
else | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN(webhookId, token) + (options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "", "post", "json", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN(webhookId, token) + ((options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "") + ((options === null || options === void 0 ? void 0 : options.thread_id) ? `${(options === null || options === void 0 ? void 0 : options.wait) ? "&" : "?"}thread_id=${options.thread_id}` : ""), "post", "json", data); | ||
} | ||
@@ -167,3 +167,3 @@ /** | ||
} | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_SLACK(webhookId, token) + (options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "", "post", "json", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_SLACK(webhookId, token) + ((options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "") + ((options === null || options === void 0 ? void 0 : options.thread_id) ? `${(options === null || options === void 0 ? void 0 : options.wait) ? "&" : "?"}thread_id=${options.thread_id}` : ""), "post", "json", data); | ||
} | ||
@@ -179,3 +179,3 @@ /** | ||
async executeWebhookGitHub(webhookId, token, data, options = { wait: false }) { | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_GITHUB(webhookId, token) + (options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "", "post", "json", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_GITHUB(webhookId, token) + ((options === null || options === void 0 ? void 0 : options.wait) ? "?wait=true" : "") + ((options === null || options === void 0 ? void 0 : options.thread_id) ? `${(options === null || options === void 0 ? void 0 : options.wait) ? "&" : "?"}thread_id=${options.thread_id}` : ""), "post", "json", data); | ||
} | ||
@@ -201,6 +201,10 @@ /** | ||
async editWebhookMessage(webhookId, token, messageId, data) { | ||
let threadID = undefined; | ||
if (data.thread_id) | ||
threadID = data.thread_id; | ||
delete data.thread_id; | ||
if (data.files) | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), "patch", "multipart", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId) + threadID ? `?thread_id=${threadID}` : "", "patch", "multipart", data); | ||
else | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), "patch", "json", data); | ||
return this.requestHandler.request(Endpoints_1.default.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId) + threadID ? `?thread_id=${threadID}` : "", "patch", "json", data); | ||
} | ||
@@ -207,0 +211,0 @@ /** |
@@ -86,2 +86,3 @@ "use strict"; | ||
this.ratelimiter.queue(async (bkt) => { | ||
var _a; | ||
const reqID = crypto_1.default.randomBytes(20).toString("hex"); | ||
@@ -104,3 +105,3 @@ try { | ||
if (request.statusCode && !Constants_1.default.OK_STATUS_CODES.includes(request.statusCode) && ![429, 502].includes(request.statusCode)) { | ||
const e = new DiscordAPIError(endpoint, request.headers["content-type"] === "application/json" ? await request.json() : request.body, method, request.statusCode); | ||
const e = new DiscordAPIError(endpoint, ((_a = request.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.startsWith("application/json")) ? await request.json() : request.body.toString(), method, request.statusCode); | ||
e.stack = stack; | ||
@@ -205,5 +206,7 @@ throw e; | ||
if (data.files && Array.isArray(data.files) && data.files.every(f => !!f.name && !!f.file)) { | ||
let index = 0; | ||
for (const file of data.files) { | ||
form.append(file.name, file.file, file.name); | ||
form.append(`files[${index}]`, file.file, { filename: file.name }); | ||
delete file.file; | ||
index++; | ||
} | ||
@@ -210,0 +213,0 @@ } |
{ | ||
"name": "snowtransfer", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Minimalistic Rest client for the Discord Api", | ||
@@ -39,11 +39,11 @@ "main": "./dist/index.js", | ||
"@types/node": "^16.0.1", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"eslint": "^7.32.0", | ||
"typedoc": "^0.22.5", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"eslint": "^8.2.0", | ||
"typedoc": "^0.22.7", | ||
"typedoc-plugin-mdn-links": "^1.0.4", | ||
"typedoc-plugin-missing-exports": "^0.22.3", | ||
"typescript": "^4.4.3" | ||
"typedoc-plugin-missing-exports": "^0.22.4", | ||
"typescript": "^4.4.4" | ||
}, | ||
"files": ["dist", "README.md", "LICENSE.md"] | ||
} |
Sorry, the diff of this file is not supported yet
5754
282393