From 2c20a85871b3dd19ceb1416d5a199c42bcbafc97 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:51:24 -0400 Subject: [PATCH] Webhook info works, deleting also works, sending is still a WIP. --- src/userplugins/WebhookManager.tsx | 100 +++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 11 deletions(-) diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx index cc7f21d1c..8f5c3a5a2 100644 --- a/src/userplugins/WebhookManager.tsx +++ b/src/userplugins/WebhookManager.tsx @@ -1,6 +1,12 @@ +/* + Vencord is very swag +*/ + import definePlugin from "@utils/types"; -import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage } from "@api/Commands"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage, findOption } from "@api/Commands"; import { Devs } from "@utils/constants"; +import { RestAPI } from "@webpack/common"; + export default definePlugin({ name: "WebhookManager", @@ -17,14 +23,25 @@ export default definePlugin({ { name: "url", description: "The URL of the webhook.", - type: ApplicationCommandOptionType.STRING + type: ApplicationCommandOptionType.STRING, + required: true } ], - execute: async (_, ctx) => { - sendBotMessage(ctx.channel.id, { - content: "Hello world! \n " + - "This is a string addition and \n, testing." - }); + execute: async (option, ctx) => { + try { + await RestAPI.delete({ + url: "" + findOption(option, "url") + }); + sendBotMessage(ctx.channel.id, { + content: "Webhook deleted successfully." + }); + } + catch + { + sendBotMessage(ctx.channel.id, { + content: "Webhook NOT deleted successfully." + }); + } } }, { @@ -35,13 +52,74 @@ export default definePlugin({ { name: "url", description: "The URL of the webhook.", - type: ApplicationCommandOptionType.STRING + type: ApplicationCommandOptionType.STRING, + required: true } ], - execute: async (_, ctx) => { + execute: async (option, ctx) => { + var webhookthing = findOption(option, "url"); + await fetch("" + webhookthing).then(response => response.json()) + .then(response => { + sendBotMessage(ctx.channel.id, { + content: "# Webhook Information: \n" + + "Webhook Username: " + response.name + "\n " + + "Webhook ID: " + response.id + "\n " + + "Webhook Token: " + response.token + "\n " + + "Channel ID: " + response.channel_id + "\n " + + "Server ID: " + response.guild_id + "\n " + + "Webhook Profile Picture: " + "[Click Me](https://cdn.discordapp.com/avatars/" + response.id + "/" + response.avatar + ".png)" + "\n " + + "Webhook Type: " + response.type + "\n \n" + + + "# Webhook Creator Information: \n " + + "Creator UserID: " + response.user.id + "\n" + + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" + + }); + }); + } + }, + { + name: "sendwebhookmessage", + description: "Send a message through a webhook.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "url", + description: "The URL of the webhook.", + type: ApplicationCommandOptionType.STRING, + required: true + }, + { + name: "message", + 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) => { + const request = new XMLHttpRequest(); + request.open("POST", "" + findOption(option, "url")); + request.setRequestHeader('Content-type', 'application/json'); + + const headers: Record = { + "Accept": "application/json", + "Accept-Language": "en", + }; + + const params = { + content: "" + findOption(option, "message"), + }; + + request.send(JSON.stringify(params)); + sendBotMessage(ctx.channel.id, { - content: "Hello world! \n " + - "This is a string addition and \n, testing." + content: "Message sent successfully!" }); } }