diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 19e9434e2..c3e0d151a 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -1,10 +1,12 @@ /* - Vencord is very swag -*/ + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ -import definePlugin, { PluginNative } from "@utils/types"; -import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage, findOption } from "@api/Commands"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; +import definePlugin, { PluginNative } from "@utils/types"; import { RestAPI } from "@webpack/common"; export let webhookDefaultName; @@ -34,7 +36,7 @@ export default definePlugin({ execute: async (option, ctx) => { const res = await RestAPI.delete({ url: "" + findOption(option, "url") }); try { - if (res.ok == true) { + if (res.ok === true) { sendBotMessage(ctx.channel.id, { content: "Webhook deleted successfully." }); @@ -105,11 +107,21 @@ export default definePlugin({ type: ApplicationCommandOptionType.STRING, required: true } + /* + { + name: "username", + description: "Give the webhook a custom name (Leave blank for default).", + type: ApplicationCommandOptionType.STRING, + required: true + } + */ + ], execute: async (option, ctx) => { var webhookUrl = findOption(option, "url"); var webhookMessage = findOption(option, "message"); + // var webhookUsername = findOption(option, "username"); webhookUrlGLOBAL = webhookUrl; webhookMessageGLOBAL = webhookMessage; await fetch("" + webhookUrl).then(response => response.json()) @@ -117,13 +129,14 @@ export default definePlugin({ webhookDefaultName = response.name; }); - Native.doSomething(); - - - + Native.executeWebhook("" + webhookUrl, { + content: webhookMessage, + username: webhookDefaultName, + avatar_url: "" + }); sendBotMessage(ctx.channel.id, { - content: "Message sent.?" + content: "Message sent successfully." }); } diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index 7c3ab4dd4..a6155e8f4 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -1,17 +1,30 @@ -import { webhookDefaultName, webhookMessageGLOBAL, webhookUrlGLOBAL } from "."; -const https = require('https'); +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ -export function doSomething() { - const request = new XMLHttpRequest(); - request.open("POST", "" + webhookUrlGLOBAL); - request.setRequestHeader('Content-type', 'application/json'); +/* +todo: also add web support (should be as easy as if navigator is on web or smthn like that, might even have a variable for that somewhere) +(thank you official vendicated vending machine 2024 real) +const iframe = document.createElement("iframe") +iframe.sandbox = "allow-scripts" +iframe.srcdoc = `` +document.body.append(iframe); +setTimeout(() => iframe.remove(), 1000); +*/ +import https from "https"; - const params = { - content: webhookMessageGLOBAL, - username: webhookDefaultName ?? "User", - avatar_url: "" - }; - request.send(JSON.stringify(params)); + +export function executeWebhook(_, url: string, body: object) { + const req = https.request(url, + { + method: "POST", + headers: { + 'Content-Type': 'application/json', + } + }); + req.write(JSON.stringify(body)); + req.end(); } -