From 278c4f0d6022a31a0b1dadf4a0acdd7ecd5b0293 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:38:34 -0400 Subject: [PATCH] Plugin now crashes, but im pushing to see if i accidnetally messed with another file --- src/plugins/WebhookManager/index.tsx | 42 ++++++++++++++-------------- src/plugins/WebhookManager/native.ts | 17 +++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 src/plugins/WebhookManager/native.ts diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 307b2287c..19e9434e2 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -2,11 +2,16 @@ Vencord is very swag */ -import definePlugin from "@utils/types"; +import definePlugin, { PluginNative } from "@utils/types"; import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage, findOption } from "@api/Commands"; import { Devs } from "@utils/constants"; import { RestAPI } from "@webpack/common"; +export let webhookDefaultName; +export let webhookUrlGLOBAL; +export let webhookMessageGLOBAL; +const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; + export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -99,33 +104,28 @@ export default definePlugin({ description: "The message you want to send.", type: ApplicationCommandOptionType.STRING, required: true - }, - { - name: "tts", - description: "Send message with TTS?", - type: ApplicationCommandOptionType.BOOLEAN, - required: false } ], execute: async (option, ctx) => { - // discord seems to have updated their webhook api, sending messages has changed - const request = new XMLHttpRequest(); - request.open("POST", "" + findOption(option, "url")); - request.setRequestHeader('Content-type', 'application/json'); - request.setRequestHeader('Accept', 'application/json'); - request.setRequestHeader('Accept-Language', 'en'); - const params = { - content: "" + findOption(option, "message"), - tts: "" + findOption(option, "tts") ?? false - }; + var webhookUrl = findOption(option, "url"); + var webhookMessage = findOption(option, "message"); + webhookUrlGLOBAL = webhookUrl; + webhookMessageGLOBAL = webhookMessage; + await fetch("" + webhookUrl).then(response => response.json()) + .then(response => { + webhookDefaultName = response.name; + }); + + Native.doSomething(); + + + - request.send(JSON.stringify(params)); sendBotMessage(ctx.channel.id, { - content: "Message sent. Check console for an advanced output." + content: "Message sent.?" }); - console.log(params); - console.log(JSON.stringify(request)); + } } ] diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts new file mode 100644 index 000000000..7c3ab4dd4 --- /dev/null +++ b/src/plugins/WebhookManager/native.ts @@ -0,0 +1,17 @@ +import { webhookDefaultName, webhookMessageGLOBAL, webhookUrlGLOBAL } from "."; +const https = require('https'); + + +export function doSomething() { + const request = new XMLHttpRequest(); + request.open("POST", "" + webhookUrlGLOBAL); + request.setRequestHeader('Content-type', 'application/json'); + + const params = { + content: webhookMessageGLOBAL, + username: webhookDefaultName ?? "User", + avatar_url: "" + }; + request.send(JSON.stringify(params)); +} +