From ccce4952cceffcc2577c018ffb0aff1b566ea745 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:43:10 -0400 Subject: [PATCH 001/100] create plugin, haven't tested yet but will soon --- src/userplugins/WebhookManager/index.ts | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/userplugins/WebhookManager/index.ts diff --git a/src/userplugins/WebhookManager/index.ts b/src/userplugins/WebhookManager/index.ts new file mode 100644 index 000000000..893b33109 --- /dev/null +++ b/src/userplugins/WebhookManager/index.ts @@ -0,0 +1,39 @@ +/* + + vencord is cool + +*/ + +import definePlugin from "@utils/types"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage, RequiredMessageOption } from "@api/Commands"; + +export default definePlugin({ + name: "WebhookManager", + description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", + authors: [{ id: 1, name: "byron", },], // will change ID soon, not home + dependencies: ["CommandsAPI"], + commands: [ + { + name: "deletewebhook", + description: "Delete a webhook.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + RequiredMessageOption, // will this work? will debug when home. + name: "url", + description: "The URL of the webhook.", + + + type: ApplicationCommandOptionType.STRING, + execute: (opts, ctx) => { + + sendBotMessage(ctx.channel.id, { + content: "Hello world! \n " + + "This is a string addition and \n, testing." + }); + } + } + ], + }, + ] +}); \ No newline at end of file From bde85e073abff34683eaa60a687dbd1bc5c011d9 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:55:39 -0400 Subject: [PATCH 002/100] added second command, also added to devs for simplicity not sure if i should YET tho --- src/userplugins/WebhookManager/index.ts | 29 +++++++++++++++++++++---- src/utils/constants.ts | 4 ++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/userplugins/WebhookManager/index.ts b/src/userplugins/WebhookManager/index.ts index 893b33109..0b9e611c5 100644 --- a/src/userplugins/WebhookManager/index.ts +++ b/src/userplugins/WebhookManager/index.ts @@ -6,11 +6,12 @@ import definePlugin from "@utils/types"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage, RequiredMessageOption } from "@api/Commands"; +import Devs from "utils/constants"; export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", - authors: [{ id: 1, name: "byron", },], // will change ID soon, not home + authors: [Devs.byron], dependencies: ["CommandsAPI"], commands: [ { @@ -19,12 +20,11 @@ export default definePlugin({ inputType: ApplicationCommandInputType.BUILT_IN, options: [ { - RequiredMessageOption, // will this work? will debug when home. + RequiredMessageOption, // will debug when home. name: "url", description: "The URL of the webhook.", - - type: ApplicationCommandOptionType.STRING, + execute: (opts, ctx) => { sendBotMessage(ctx.channel.id, { @@ -35,5 +35,26 @@ export default definePlugin({ } ], }, + { + name: "webhookinfo", + description: "Retrieve information about a webhook.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + RequiredMessageOption, + name: "url", + description: "The URL of the webhook.", + type: ApplicationCommandOptionType.STRING, + + execute: (opts, ctx) => { + + sendBotMessage(ctx.channel.id, { + content: "Hello world! \n " + + "This is a string addition and \n, testing." + }); + } + } + ], + } ] }); \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 081eed34f..9d5e9b0b9 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -426,6 +426,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ Elvyra: { name: "Elvyra", id: 708275751816003615n, + }, + Byron: { + name: "byron", // am i even allowed to add this right now? + id: 639577344276692992n, } } satisfies Record); From ff6f24b8c9450522d33e3d397b01b94bbe5a5642 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:15:58 -0400 Subject: [PATCH 003/100] Fixed bugs with plugin, on pc now & i use other plugins so i put it in gitignore --- .gitignore | 2 +- src/userplugins/WebhookManager.tsx | 49 ++++++++++++++++++++ src/userplugins/WebhookManager/index.ts | 60 ------------------------- 3 files changed, 50 insertions(+), 61 deletions(-) create mode 100644 src/userplugins/WebhookManager.tsx delete mode 100644 src/userplugins/WebhookManager/index.ts diff --git a/.gitignore b/.gitignore index 135673a6d..9eacd797b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ lerna-debug.log* .pnpm-debug.log* *.tsbuildinfo -src/userplugins +src/userplugins/globalBadges.tsx ExtensionCache/ settings/ diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx new file mode 100644 index 000000000..cc7f21d1c --- /dev/null +++ b/src/userplugins/WebhookManager.tsx @@ -0,0 +1,49 @@ +import definePlugin from "@utils/types"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage } from "@api/Commands"; +import { Devs } from "@utils/constants"; + +export default definePlugin({ + name: "WebhookManager", + description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", + authors: [Devs.Byron], + dependencies: ["CommandsAPI"], + + commands: [ + { + name: "deletewebhook", + description: "Delete a webhook.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "url", + description: "The URL of the webhook.", + type: ApplicationCommandOptionType.STRING + } + ], + execute: async (_, ctx) => { + sendBotMessage(ctx.channel.id, { + content: "Hello world! \n " + + "This is a string addition and \n, testing." + }); + } + }, + { + name: "webhookinfo", + description: "Retrieve information about a webhook.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "url", + description: "The URL of the webhook.", + type: ApplicationCommandOptionType.STRING + } + ], + execute: async (_, ctx) => { + sendBotMessage(ctx.channel.id, { + content: "Hello world! \n " + + "This is a string addition and \n, testing." + }); + } + } + ] +}); \ No newline at end of file diff --git a/src/userplugins/WebhookManager/index.ts b/src/userplugins/WebhookManager/index.ts deleted file mode 100644 index 0b9e611c5..000000000 --- a/src/userplugins/WebhookManager/index.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - - vencord is cool - -*/ - -import definePlugin from "@utils/types"; -import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage, RequiredMessageOption } from "@api/Commands"; -import Devs from "utils/constants"; - -export default definePlugin({ - name: "WebhookManager", - description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", - authors: [Devs.byron], - dependencies: ["CommandsAPI"], - commands: [ - { - name: "deletewebhook", - description: "Delete a webhook.", - inputType: ApplicationCommandInputType.BUILT_IN, - options: [ - { - RequiredMessageOption, // will debug when home. - name: "url", - description: "The URL of the webhook.", - type: ApplicationCommandOptionType.STRING, - - execute: (opts, ctx) => { - - sendBotMessage(ctx.channel.id, { - content: "Hello world! \n " + - "This is a string addition and \n, testing." - }); - } - } - ], - }, - { - name: "webhookinfo", - description: "Retrieve information about a webhook.", - inputType: ApplicationCommandInputType.BUILT_IN, - options: [ - { - RequiredMessageOption, - name: "url", - description: "The URL of the webhook.", - type: ApplicationCommandOptionType.STRING, - - execute: (opts, ctx) => { - - sendBotMessage(ctx.channel.id, { - content: "Hello world! \n " + - "This is a string addition and \n, testing." - }); - } - } - ], - } - ] -}); \ No newline at end of file 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 004/100] 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!" }); } } From 0207b9fa121422d561cdce69a04d424c7e2d24ef Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 08:55:10 -0400 Subject: [PATCH 005/100] [style]fix missing line --- src/userplugins/WebhookManager.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx index 8f5c3a5a2..e554d0ae4 100644 --- a/src/userplugins/WebhookManager.tsx +++ b/src/userplugins/WebhookManager.tsx @@ -73,7 +73,6 @@ export default definePlugin({ "# Webhook Creator Information: \n " + "Creator UserID: " + response.user.id + "\n" + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" - }); }); } @@ -103,6 +102,7 @@ export default definePlugin({ } ], execute: async (option, ctx) => { + // discord seems to have updated their webhook api, sending messages has changed, will work on soon const request = new XMLHttpRequest(); request.open("POST", "" + findOption(option, "url")); request.setRequestHeader('Content-type', 'application/json'); @@ -114,6 +114,7 @@ export default definePlugin({ const params = { content: "" + findOption(option, "message"), + tts: "" + findOption(option, "tts") }; request.send(JSON.stringify(params)); @@ -124,4 +125,4 @@ export default definePlugin({ } } ] -}); \ No newline at end of file +}); From 369f66e810c33d7cebf12c8790ca799f867a8c60 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:24:23 -0400 Subject: [PATCH 006/100] Added 'Creator Username' section for webhookinfo and adding text to speech on sending webhook message --- src/userplugins/WebhookManager.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx index e554d0ae4..6d1a8594e 100644 --- a/src/userplugins/WebhookManager.tsx +++ b/src/userplugins/WebhookManager.tsx @@ -7,7 +7,6 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessa import { Devs } from "@utils/constants"; import { RestAPI } from "@webpack/common"; - export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -28,6 +27,8 @@ export default definePlugin({ } ], execute: async (option, ctx) => { + + // const res = await REST.delete(findOption(option, "url")); try { await RestAPI.delete({ url: "" + findOption(option, "url") @@ -71,7 +72,8 @@ export default definePlugin({ "Webhook Type: " + response.type + "\n \n" + "# Webhook Creator Information: \n " + - "Creator UserID: " + response.user.id + "\n" + + "Creator UserID: " + response.user.id + "\n " + + "Creator Username: " + response.user.name + "\n " + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" }); }); @@ -102,26 +104,24 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - // discord seems to have updated their webhook api, sending messages has changed, will work on soon + // 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'); - - const headers: Record = { - "Accept": "application/json", - "Accept-Language": "en", - }; + request.setRequestHeader('Accept', 'application/json'); + request.setRequestHeader('Accept-Language', 'en'); const params = { content: "" + findOption(option, "message"), - tts: "" + findOption(option, "tts") + tts: "" + findOption(option, "tts") ?? false }; request.send(JSON.stringify(params)); - sendBotMessage(ctx.channel.id, { - content: "Message sent successfully!" + content: "Message sent. Check console for an advanced output." }); + console.log(params); + console.log(JSON.stringify(request)); } } ] From 3dd65d520e44c6eba80e5104470397002790eb91 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:52:55 -0400 Subject: [PATCH 007/100] /webhookinfo has the ability to get a pingable version of the creator, webhook deletion now can determine if the URL is valid --- src/userplugins/WebhookManager.tsx | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx index 6d1a8594e..b7aa0b64a 100644 --- a/src/userplugins/WebhookManager.tsx +++ b/src/userplugins/WebhookManager.tsx @@ -27,20 +27,23 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - - // const res = await REST.delete(findOption(option, "url")); + const res = await RestAPI.delete(findOption(option, "url")); try { - await RestAPI.delete({ - url: "" + findOption(option, "url") - }); - sendBotMessage(ctx.channel.id, { - content: "Webhook deleted successfully." - }); + if (res.ok == true) { + sendBotMessage(ctx.channel.id, { + content: "Webhook deleted successfully." + }); + } + else { + console.log("WebhookManager encountered an error deleting a webhook. " + res.status); + sendBotMessage(ctx.channel.id, { + content: "There was an error deleting the webhook. Check the console for more info." + }); + } } - catch - { + catch (error) { sendBotMessage(ctx.channel.id, { - content: "Webhook NOT deleted successfully." + content: "There was an error deleting the webhook. Did you input a valid webhook URL?" }); } } @@ -58,8 +61,8 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - var webhookthing = findOption(option, "url"); - await fetch("" + webhookthing).then(response => response.json()) + var webhookUrl = findOption(option, "url"); + await fetch("" + webhookUrl).then(response => response.json()) .then(response => { sendBotMessage(ctx.channel.id, { content: "# Webhook Information: \n" + @@ -73,7 +76,7 @@ export default definePlugin({ "# Webhook Creator Information: \n " + "Creator UserID: " + response.user.id + "\n " + - "Creator Username: " + response.user.name + "\n " + + "Creator Username: " + response.username + " | ( <@" + res.user.id + "> )" + "\n " + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" }); }); From 87e86271fe0ed1e0d355caa5ef12d30f74191629 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:29:41 -0400 Subject: [PATCH 008/100] Forgot to add error to console, removed dumb note I added in badge thing --- src/userplugins/WebhookManager.tsx | 3 ++- src/utils/constants.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/userplugins/WebhookManager.tsx b/src/userplugins/WebhookManager.tsx index b7aa0b64a..d8b414879 100644 --- a/src/userplugins/WebhookManager.tsx +++ b/src/userplugins/WebhookManager.tsx @@ -42,8 +42,9 @@ export default definePlugin({ } } catch (error) { + console.log("WebhookManager encountered an error deleting a webhook. " + error); sendBotMessage(ctx.channel.id, { - content: "There was an error deleting the webhook. Did you input a valid webhook URL?" + content: "There was an error deleting the webhook. Check the console for more info. Did you input a valid webhook URL?" }); } } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 9d5e9b0b9..5a51a0c45 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -428,8 +428,8 @@ export const Devs = /* #__PURE__*/ Object.freeze({ id: 708275751816003615n, }, Byron: { - name: "byron", // am i even allowed to add this right now? - id: 639577344276692992n, + name: "byron", + id: 639577344276692992n } } satisfies Record); From f41c6f4762444c40a24bd7595bc06d2163237b29 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:53:41 -0400 Subject: [PATCH 009/100] Learned that I'm supposed to actually put the plugins in /plugins and not /userplugins, moved plugin into correct directory and fixed the .gitignore --- .gitignore | 2 +- src/plugins/WebhookManager/README.MD | 25 +++++++++++++++++++ .../WebhookManager}/WebhookManager.tsx | 0 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/plugins/WebhookManager/README.MD rename src/{userplugins => plugins/WebhookManager}/WebhookManager.tsx (100%) diff --git a/.gitignore b/.gitignore index 9eacd797b..32e6f9531 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ lerna-debug.log* .pnpm-debug.log* *.tsbuildinfo -src/userplugins/globalBadges.tsx +src/userplugins/ ExtensionCache/ settings/ diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD new file mode 100644 index 000000000..8089eabfc --- /dev/null +++ b/src/plugins/WebhookManager/README.MD @@ -0,0 +1,25 @@ +
+

WebhookManager

+ Manage your webhooks easily; delete, send messages, get detailed info and more. +
+ + ## Commands + - /sendwebhookmessage - *Sends a message through a webhook.* + + + - /deletewebhook - *Deletes a webhook.* + + + - /webhookinfo - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it* +
Full /webhookinfo Output + - Webhook Username
+ - Webhook ID
+ - Webhook Token
+ - Channel ID
+ - Server ID
+ - Webhook Profile Picture
+ - Webhook Type
+ - Creator UserID
+ - Creator Username
+ - Creator Profile
+
\ No newline at end of file diff --git a/src/userplugins/WebhookManager.tsx b/src/plugins/WebhookManager/WebhookManager.tsx similarity index 100% rename from src/userplugins/WebhookManager.tsx rename to src/plugins/WebhookManager/WebhookManager.tsx From ba0a9d06968c260c8b938a783c9f3ecf0346517c Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:56:40 -0400 Subject: [PATCH 010/100] Fixed issues with plugin not loading, and fixed bugs --- src/plugins/WebhookManager/{WebhookManager.tsx => index.tsx} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/plugins/WebhookManager/{WebhookManager.tsx => index.tsx} (97%) diff --git a/src/plugins/WebhookManager/WebhookManager.tsx b/src/plugins/WebhookManager/index.tsx similarity index 97% rename from src/plugins/WebhookManager/WebhookManager.tsx rename to src/plugins/WebhookManager/index.tsx index d8b414879..307b2287c 100644 --- a/src/plugins/WebhookManager/WebhookManager.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -27,7 +27,7 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - const res = await RestAPI.delete(findOption(option, "url")); + const res = await RestAPI.delete({ url: "" + findOption(option, "url") }); try { if (res.ok == true) { sendBotMessage(ctx.channel.id, { @@ -77,7 +77,7 @@ export default definePlugin({ "# Webhook Creator Information: \n " + "Creator UserID: " + response.user.id + "\n " + - "Creator Username: " + response.username + " | ( <@" + res.user.id + "> )" + "\n " + + "Creator Username: " + response.username + " | ( <@" + response.user.id + "> )" + "\n " + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" }); }); 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 011/100] 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)); +} + From 4f6863108081b5f94d3236b654a29d1ad3e2d635 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:45:52 -0400 Subject: [PATCH 012/100] Finally did it, fixed the sending bug --- src/plugins/WebhookManager/index.tsx | 33 ++++++++++++++++------- src/plugins/WebhookManager/native.ts | 39 ++++++++++++++++++---------- 2 files changed, 49 insertions(+), 23 deletions(-) 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(); } - From cedf10bdd250f4336b39fbc66b153b8bfdcd2fb6 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:47:15 -0400 Subject: [PATCH 013/100] removed personal plugin i use before pull request (its in .gitignore i think) also added logging to console on getinfo --- src/plugins/WebhookManager/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index c3e0d151a..b46ab3c15 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -72,6 +72,7 @@ export default definePlugin({ var webhookUrl = findOption(option, "url"); await fetch("" + webhookUrl).then(response => response.json()) .then(response => { + console.log(JSON.stringify(response)); sendBotMessage(ctx.channel.id, { content: "# Webhook Information: \n" + "Webhook Username: " + response.name + "\n " + From d02a241ff94a6fa23b56fdaf66970a32c545cdff Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:49:36 -0400 Subject: [PATCH 014/100] (also fixed small bug where creator username would be undefined) --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index b46ab3c15..bf44c66e8 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -85,7 +85,7 @@ export default definePlugin({ "# Webhook Creator Information: \n " + "Creator UserID: " + response.user.id + "\n " + - "Creator Username: " + response.username + " | ( <@" + response.user.id + "> )" + "\n " + + "Creator Username: " + response.user.username + " | ( <@" + response.user.id + "> )" + "\n " + "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" }); }); From 284a951353500ebe03048f6f04a5da60e2103010 Mon Sep 17 00:00:00 2001 From: V Date: Wed, 13 Mar 2024 03:23:51 +0100 Subject: [PATCH 015/100] Discard changes to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 32e6f9531..135673a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ lerna-debug.log* .pnpm-debug.log* *.tsbuildinfo -src/userplugins/ +src/userplugins ExtensionCache/ settings/ From 4ea2d1ca5c267790503180dc4a4d6dcf5badb329 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:34:10 -0400 Subject: [PATCH 016/100] Fixed a ton of things, thank you suggestions and code reviews --- .gitignore | 2 -- src/plugins/WebhookManager/index.tsx | 16 +++------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 135673a6d..343842de8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,5 @@ lerna-debug.log* .pnpm-debug.log* *.tsbuildinfo -src/userplugins - ExtensionCache/ settings/ diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index bf44c66e8..33e3f65a3 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -9,9 +9,6 @@ import { Devs } from "@utils/constants"; import definePlugin, { PluginNative } from "@utils/types"; import { RestAPI } from "@webpack/common"; -export let webhookDefaultName; -export let webhookUrlGLOBAL; -export let webhookMessageGLOBAL; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; export default definePlugin({ @@ -36,7 +33,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) { sendBotMessage(ctx.channel.id, { content: "Webhook deleted successfully." }); @@ -85,8 +82,7 @@ export default definePlugin({ "# Webhook Creator Information: \n " + "Creator UserID: " + response.user.id + "\n " + - "Creator Username: " + response.user.username + " | ( <@" + response.user.id + "> )" + "\n " + - "Creator Profile: [Click Me](https://img.discord.dog/" + response.user.id + ") \n" + "Creator Username: " + "<@" + response.user.id + ">" + "\n " }); }); } @@ -123,16 +119,10 @@ export default definePlugin({ 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()) - .then(response => { - webhookDefaultName = response.name; - }); Native.executeWebhook("" + webhookUrl, { content: webhookMessage, - username: webhookDefaultName, + username: fetch("" + webhookUrl).then(response => response.json()), // yea might have issues, sleepy brain as well, will fix tmr avatar_url: "" }); From 9060352977c99306fd7ce6777a9b17c4ab3907cb Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:36:55 -0400 Subject: [PATCH 017/100] re-discarded changes to .gitignore (sorry) --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 343842de8..135673a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,7 @@ lerna-debug.log* .pnpm-debug.log* *.tsbuildinfo +src/userplugins + ExtensionCache/ settings/ From 1c3e33dbbda4a41a865d56cb299be159ad21c205 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:18:16 -0400 Subject: [PATCH 018/100] Logger for error handling instead of console.log --- src/plugins/WebhookManager/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 33e3f65a3..014375b52 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -8,8 +8,10 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import definePlugin, { PluginNative } from "@utils/types"; import { RestAPI } from "@webpack/common"; +import { Logger } from "@utils/Logger"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; +const WMLogger = new Logger("WebhookManager"); export default definePlugin({ name: "WebhookManager", @@ -39,14 +41,14 @@ export default definePlugin({ }); } else { - console.log("WebhookManager encountered an error deleting a webhook. " + res.status); + WMLogger.error("WebhookManager encountered an error deleting a webhook. " + res.status); sendBotMessage(ctx.channel.id, { content: "There was an error deleting the webhook. Check the console for more info." }); } } catch (error) { - console.log("WebhookManager encountered an error deleting a webhook. " + error); + WMLogger.error("WebhookManager encountered an error deleting a webhook. " + error); sendBotMessage(ctx.channel.id, { content: "There was an error deleting the webhook. Check the console for more info. Did you input a valid webhook URL?" }); From 2f1c10de3e15f949579409326ddfa9bff25ff40f Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:03:52 -0400 Subject: [PATCH 019/100] me when im at school and bored and decide to keep on making improvements :trolley: --- src/plugins/WebhookManager/index.tsx | 38 ++++++++++++++++++---------- src/plugins/WebhookManager/native.ts | 2 +- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 014375b52..4ff94af2d 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -68,7 +68,7 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - var webhookUrl = findOption(option, "url"); + let webhookUrl = findOption(option, "url"); await fetch("" + webhookUrl).then(response => response.json()) .then(response => { console.log(JSON.stringify(response)); @@ -105,28 +105,40 @@ export default definePlugin({ description: "The message you want to send.", type: ApplicationCommandOptionType.STRING, required: true - } - /* + }, { name: "username", description: "Give the webhook a custom name (Leave blank for default).", type: ApplicationCommandOptionType.STRING, - required: true + required: false + }, + { + name: "rawjson", + description: "Send as a raw JSON", + type: ApplicationCommandOptionType.BOOLEAN, + required: false } - */ ], execute: async (option, ctx) => { - var webhookUrl = findOption(option, "url"); - var webhookMessage = findOption(option, "message"); - // var webhookUsername = findOption(option, "username"); + let webhookUrl = findOption(option, "url"); + let webhookMessage = findOption(option, "message"); + let webhookUsername = findOption(option, "username"); + if (findOption(option, "rawjson")) { + Native.executeWebhook("" + webhookUrl, { + webhookMessage // doubt it will work but it might, might clash with other options such as the username, but once i'm home i'll continue testing. + }); + + } + else { + Native.executeWebhook("" + webhookUrl, { + content: webhookMessage, + username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json()), // still may have issues, supposed to go to webhook name if a custom name is not set, ?? should be the right operator + avatar_url: "" + }); + } - Native.executeWebhook("" + webhookUrl, { - content: webhookMessage, - username: fetch("" + webhookUrl).then(response => response.json()), // yea might have issues, sleepy brain as well, will fix tmr - avatar_url: "" - }); sendBotMessage(ctx.channel.id, { content: "Message sent successfully." diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index a6155e8f4..0df881f71 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -27,4 +27,4 @@ export function executeWebhook(_, url: string, body: object) { }); req.write(JSON.stringify(body)); req.end(); -} +} \ No newline at end of file From f2b22bc349154fe5c97285b09404b95943503bc2 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 12:15:39 -0400 Subject: [PATCH 020/100] Removed notes, fully moved logging to Logger, fixed everything back to const (thank you) --- src/plugins/WebhookManager/README.MD | 1 - src/plugins/WebhookManager/index.tsx | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index 8089eabfc..5963c1893 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -21,5 +21,4 @@ - Webhook Type
- Creator UserID
- Creator Username
- - Creator Profile
\ No newline at end of file diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 4ff94af2d..58790c21f 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -68,10 +68,10 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - let webhookUrl = findOption(option, "url"); + const webhookUrl = findOption(option, "url"); await fetch("" + webhookUrl).then(response => response.json()) .then(response => { - console.log(JSON.stringify(response)); + WMLogger.info(JSON.stringify(response)); sendBotMessage(ctx.channel.id, { content: "# Webhook Information: \n" + "Webhook Username: " + response.name + "\n " + @@ -122,19 +122,19 @@ export default definePlugin({ ], execute: async (option, ctx) => { - let webhookUrl = findOption(option, "url"); - let webhookMessage = findOption(option, "message"); - let webhookUsername = findOption(option, "username"); + const webhookUrl = findOption(option, "url"); + const webhookMessage = findOption(option, "message"); + const webhookUsername = findOption(option, "username"); if (findOption(option, "rawjson")) { Native.executeWebhook("" + webhookUrl, { - webhookMessage // doubt it will work but it might, might clash with other options such as the username, but once i'm home i'll continue testing. + webhookMessage }); } else { Native.executeWebhook("" + webhookUrl, { content: webhookMessage, - username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json()), // still may have issues, supposed to go to webhook name if a custom name is not set, ?? should be the right operator + username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json()), avatar_url: "" }); } From 0fd7a59d8aa63c388fd5b5f9080242fcf5f942cc Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 12:47:22 -0400 Subject: [PATCH 021/100] literal string for webhookinfo, also inside of an embed, better way to format the icon instead of clicking now. --- src/plugins/WebhookManager/index.tsx | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 58790c21f..d4bf4753c 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -73,18 +73,22 @@ export default definePlugin({ .then(response => { WMLogger.info(JSON.stringify(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" + + embeds: [ + { + author: { + icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + }, - "# Webhook Creator Information: \n " + - "Creator UserID: " + response.user.id + "\n " + - "Creator Username: " + "<@" + response.user.id + ">" + "\n " + content: `# Webhook Information: \n + Webhook Username: ${response.name} + Webhook ID: ${response.id} + Webhook Token: ${response.token} + Webhook Type: ${response.type} + Channel ID: ${response.channel_id} + Server ID: ${response.guild_id} + + "Creator Profile: <@${response.user.id}>` + }] }); }); } @@ -114,7 +118,7 @@ export default definePlugin({ }, { name: "rawjson", - description: "Send as a raw JSON", + description: "Send message as raw JSON", type: ApplicationCommandOptionType.BOOLEAN, required: false } @@ -147,4 +151,4 @@ export default definePlugin({ } } ] -}); +});;;;; From 4cb2661ae9c915918108298c2d5652a022154e52 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 12:52:25 -0400 Subject: [PATCH 022/100] Also fixed the commands to be better --- src/plugins/WebhookManager/README.MD | 11 ++++++----- src/plugins/WebhookManager/index.tsx | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index 5963c1893..9931556a4 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -4,13 +4,13 @@ ## Commands - - /sendwebhookmessage - *Sends a message through a webhook.* + - /webhook send - *Sends a message through a webhook.* - - /deletewebhook - *Deletes a webhook.* + - /webhook delete - *Deletes a webhook.* - - /webhookinfo - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it* + - /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it*
Full /webhookinfo Output - Webhook Username
- Webhook ID
@@ -19,6 +19,7 @@ - Server ID
- Webhook Profile Picture
- Webhook Type
- - Creator UserID
- - Creator Username
+ + + - Creator Profile
\ No newline at end of file diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index d4bf4753c..0d90e92f1 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -21,7 +21,7 @@ export default definePlugin({ commands: [ { - name: "deletewebhook", + name: "webhook delete", description: "Delete a webhook.", inputType: ApplicationCommandInputType.BUILT_IN, options: [ @@ -56,7 +56,7 @@ export default definePlugin({ } }, { - name: "webhookinfo", + name: "webhook info", description: "Retrieve information about a webhook.", inputType: ApplicationCommandInputType.BUILT_IN, options: [ @@ -94,7 +94,7 @@ export default definePlugin({ } }, { - name: "sendwebhookmessage", + name: "webhook send", description: "Send a message through a webhook.", inputType: ApplicationCommandInputType.BUILT_IN, options: [ From a6c7cb95170a237343e6092a60206eb7380547cc Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:07:51 -0400 Subject: [PATCH 023/100] Also added the ability to send webhooks with TTS (For the sillies and goofs) --- src/plugins/WebhookManager/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 0d90e92f1..41efe8dc1 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -121,6 +121,12 @@ export default definePlugin({ description: "Send message as raw JSON", type: ApplicationCommandOptionType.BOOLEAN, required: false + }, + { + name: "tts", + description: "Send with TTS?", + type: ApplicationCommandOptionType.BOOLEAN, + required: false } ], @@ -133,17 +139,16 @@ export default definePlugin({ Native.executeWebhook("" + webhookUrl, { webhookMessage }); - } else { Native.executeWebhook("" + webhookUrl, { content: webhookMessage, username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json()), - avatar_url: "" + avatar_url: "", + tts: findOption(option, "tts") }); } - sendBotMessage(ctx.channel.id, { content: "Message sent successfully." }); From 6df510d9f535438f918b84029a01a757d67ccecb Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:20:48 -0400 Subject: [PATCH 024/100] Added title to embed, fixed accidental leftover symbols --- src/plugins/WebhookManager/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 41efe8dc1..f05135bd5 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -75,11 +75,11 @@ export default definePlugin({ sendBotMessage(ctx.channel.id, { embeds: [ { + title: "Webhook Information", author: { - icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png` }, - - content: `# Webhook Information: \n + content: ` Webhook Username: ${response.name} Webhook ID: ${response.id} Webhook Token: ${response.token} @@ -87,7 +87,7 @@ export default definePlugin({ Channel ID: ${response.channel_id} Server ID: ${response.guild_id} - "Creator Profile: <@${response.user.id}>` + Creator Profile: <@${response.user.id}>` }] }); }); From 9b600b9dad92d604482c16d4ef64ae4f39b62f8f Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:57:14 -0400 Subject: [PATCH 025/100] *quickly changed some grammar* --- src/plugins/WebhookManager/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index f05135bd5..d44541a50 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -27,7 +27,7 @@ export default definePlugin({ options: [ { name: "url", - description: "The URL of the webhook.", + description: "The URL of the webhook", type: ApplicationCommandOptionType.STRING, required: true } @@ -62,7 +62,7 @@ export default definePlugin({ options: [ { name: "url", - description: "The URL of the webhook.", + description: "The URL of the webhook", type: ApplicationCommandOptionType.STRING, required: true } @@ -100,19 +100,19 @@ export default definePlugin({ options: [ { name: "url", - description: "The URL of the webhook.", + description: "The URL of the webhook", type: ApplicationCommandOptionType.STRING, required: true }, { name: "message", - description: "The message you want to send.", + description: "The message you want to send", type: ApplicationCommandOptionType.STRING, required: true }, { name: "username", - description: "Give the webhook a custom name (Leave blank for default).", + description: "Send with a custom webhook username", type: ApplicationCommandOptionType.STRING, required: false }, @@ -124,7 +124,7 @@ export default definePlugin({ }, { name: "tts", - description: "Send with TTS?", + description: "Send with TTS", type: ApplicationCommandOptionType.BOOLEAN, required: false } From 1225861843798276aa6fc23479a9ecf472a74e46 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:28:58 -0400 Subject: [PATCH 026/100] Fixed bug that was caused when doing /webhook info, also updated the embed style and looks better --- src/plugins/WebhookManager/index.tsx | 21 +++++++++++++++------ src/plugins/WebhookManager/native.ts | 5 ++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index d44541a50..8548785f6 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -6,9 +6,9 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; +import { Logger } from "@utils/Logger"; import definePlugin, { PluginNative } from "@utils/types"; import { RestAPI } from "@webpack/common"; -import { Logger } from "@utils/Logger"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); @@ -72,15 +72,24 @@ export default definePlugin({ await fetch("" + webhookUrl).then(response => response.json()) .then(response => { WMLogger.info(JSON.stringify(response)); + if (response.type === 2) { + const sourceGuild = response.source_guild; + const sourceChannel = response.source_channel; + } sendBotMessage(ctx.channel.id, { embeds: [ { - title: "Webhook Information", + // @ts-ignore + title: ` ${response.name}'s Webhook Information`, + color: '#00007d', author: { - icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png` + // @ts-ignore + icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + proxy_icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + name: response.name, + url: "" }, - content: ` - Webhook Username: ${response.name} + description: ` Webhook ID: ${response.id} Webhook Token: ${response.token} Webhook Type: ${response.type} @@ -156,4 +165,4 @@ export default definePlugin({ } } ] -});;;;; +}); diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index 0df881f71..ae2f108dd 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -4,7 +4,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ - /* 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) @@ -22,9 +21,9 @@ export function executeWebhook(_, url: string, body: object) { { method: "POST", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", } }); req.write(JSON.stringify(body)); req.end(); -} \ No newline at end of file +} From 9fab41449a85514b962db1cae569f31018a4b274 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:46:28 -0400 Subject: [PATCH 027/100] Added extra information for 'Type 2' Webhooks (Server Following / Announcements), more small tweaks to the embed --- src/plugins/WebhookManager/index.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 8548785f6..178a6c049 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -12,7 +12,8 @@ import { RestAPI } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); - +let sourceGuildGet; +let sourceChannelGet; export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -73,14 +74,27 @@ export default definePlugin({ .then(response => { WMLogger.info(JSON.stringify(response)); if (response.type === 2) { - const sourceGuild = response.source_guild; - const sourceChannel = response.source_channel; + const sourceGuild = ` + Source Server ID: ${response.source_guild.id} + Source Server Name: ${response.source_guild.name} + `; + sourceGuildGet = sourceGuild; + const sourceChannel = ` + Source Channel ID: ${response.source_channel.id} + Source Channel Name: ${response.source_channel.name} + `; + sourceChannelGet = sourceChannel; + } + else { + sourceGuildGet = ""; + sourceChannelGet = ""; } sendBotMessage(ctx.channel.id, { + embeds: [ { // @ts-ignore - title: ` ${response.name}'s Webhook Information`, + title: `Webhook Information`, color: '#00007d', author: { // @ts-ignore @@ -95,6 +109,8 @@ export default definePlugin({ Webhook Type: ${response.type} Channel ID: ${response.channel_id} Server ID: ${response.guild_id} + ${sourceGuildGet} + ${sourceChannelGet} Creator Profile: <@${response.user.id}>` }] @@ -123,7 +139,7 @@ export default definePlugin({ name: "username", description: "Send with a custom webhook username", type: ApplicationCommandOptionType.STRING, - required: false + required: true }, { name: "rawjson", From 2da6a647488b3602fd57bea641e79a0000b54b9c Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:02:42 -0400 Subject: [PATCH 028/100] Ready for reviews / feedback --- src/plugins/WebhookManager/index.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 178a6c049..bf6860f0f 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -90,7 +90,6 @@ export default definePlugin({ sourceChannelGet = ""; } sendBotMessage(ctx.channel.id, { - embeds: [ { // @ts-ignore @@ -141,25 +140,24 @@ export default definePlugin({ type: ApplicationCommandOptionType.STRING, required: true }, - { - name: "rawjson", - description: "Send message as raw JSON", - type: ApplicationCommandOptionType.BOOLEAN, - required: false - }, { name: "tts", description: "Send with TTS", type: ApplicationCommandOptionType.BOOLEAN, required: false + }, + { + name: "rawjson", + description: "Send message as raw JSON", + type: ApplicationCommandOptionType.BOOLEAN, + required: false } - ], execute: async (option, ctx) => { const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); - const webhookUsername = findOption(option, "username"); + let webhookUsername = findOption(option, "username"); if (findOption(option, "rawjson")) { Native.executeWebhook("" + webhookUrl, { webhookMessage @@ -168,12 +166,11 @@ export default definePlugin({ else { Native.executeWebhook("" + webhookUrl, { content: webhookMessage, - username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json()), + username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json().then(response => { response.name; })), avatar_url: "", tts: findOption(option, "tts") }); } - sendBotMessage(ctx.channel.id, { content: "Message sent successfully." }); From 73a2f5548a57f5531531e7c2bca19f4849dfbcc4 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:03:31 -0400 Subject: [PATCH 029/100] now* it's ready --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index bf6860f0f..30d8bd9ce 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -166,7 +166,7 @@ export default definePlugin({ else { Native.executeWebhook("" + webhookUrl, { content: webhookMessage, - username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json().then(response => { response.name; })), + username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json().then(response => { webhookUsername = response.name; })), avatar_url: "", tts: findOption(option, "tts") }); From f43f4041233fd89fecd91376528e5bf44a7e0958 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:03:54 -0400 Subject: [PATCH 030/100] put the pingable text into 'content' and not the embed, also added the ability to get the userID for simplicity --- src/plugins/WebhookManager/README.MD | 3 +-- src/plugins/WebhookManager/index.tsx | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index 9931556a4..245c51875 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -19,7 +19,6 @@ - Server ID
- Webhook Profile Picture
- Webhook Type
- - - Creator Profile
+ - Creator UserID
\ No newline at end of file diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 30d8bd9ce..c10278ff8 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -90,6 +90,7 @@ export default definePlugin({ sourceChannelGet = ""; } sendBotMessage(ctx.channel.id, { + content: `This webhook was created by <@${response.user.id}>.`, embeds: [ { // @ts-ignore @@ -111,7 +112,7 @@ export default definePlugin({ ${sourceGuildGet} ${sourceChannelGet} - Creator Profile: <@${response.user.id}>` + Creator UserID: ${response.user.id}` }] }); }); From 9c7c3d0c5da22f623510f66d4af89192e4502843 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:44:30 -0400 Subject: [PATCH 031/100] fixed that god-awful annoying bug where you couldnt use the default webhook name --- src/plugins/WebhookManager/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index c10278ff8..a24574022 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -139,7 +139,7 @@ export default definePlugin({ name: "username", description: "Send with a custom webhook username", type: ApplicationCommandOptionType.STRING, - required: true + required: false }, { name: "tts", @@ -165,9 +165,11 @@ export default definePlugin({ }); } else { + fetch("" + webhookUrl).then(response => response.json().then(response => { if (webhookUsername === "") { webhookUsername = response.name; } })); + Native.executeWebhook("" + webhookUrl, { content: webhookMessage, - username: webhookUsername ?? fetch("" + webhookUrl).then(response => response.json().then(response => { webhookUsername = response.name; })), + username: webhookUsername, avatar_url: "", tts: findOption(option, "tts") }); From 8a09cb533b2f10f6dbd9fce95f72b4fef3d0fb1c Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:00:40 -0400 Subject: [PATCH 032/100] Could simplify this to one variable instead --- src/plugins/WebhookManager/index.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index a24574022..a510fc942 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -13,7 +13,6 @@ import { RestAPI } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); let sourceGuildGet; -let sourceChannelGet; export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -74,20 +73,16 @@ export default definePlugin({ .then(response => { WMLogger.info(JSON.stringify(response)); if (response.type === 2) { - const sourceGuild = ` + const sourceWebhook = ` Source Server ID: ${response.source_guild.id} Source Server Name: ${response.source_guild.name} - `; - sourceGuildGet = sourceGuild; - const sourceChannel = ` Source Channel ID: ${response.source_channel.id} Source Channel Name: ${response.source_channel.name} `; - sourceChannelGet = sourceChannel; + sourceGuildGet = sourceWebhook; } else { sourceGuildGet = ""; - sourceChannelGet = ""; } sendBotMessage(ctx.channel.id, { content: `This webhook was created by <@${response.user.id}>.`, @@ -110,7 +105,6 @@ export default definePlugin({ Channel ID: ${response.channel_id} Server ID: ${response.guild_id} ${sourceGuildGet} - ${sourceChannelGet} Creator UserID: ${response.user.id}` }] @@ -173,6 +167,7 @@ export default definePlugin({ avatar_url: "", tts: findOption(option, "tts") }); + } sendBotMessage(ctx.channel.id, { content: "Message sent successfully." From 736fef879e123c1f6487f6d2fec752de6a03911a Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:18:53 -0400 Subject: [PATCH 033/100] removed unneeded / unreachable code, changed 'rawjson' to just 'raw', working on attachment sending as well --- src/plugins/WebhookManager/index.tsx | 31 +++++++++------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index a510fc942..5359bd9fa 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -12,7 +12,6 @@ import { RestAPI } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); -let sourceGuildGet; export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -72,18 +71,6 @@ export default definePlugin({ await fetch("" + webhookUrl).then(response => response.json()) .then(response => { WMLogger.info(JSON.stringify(response)); - if (response.type === 2) { - const sourceWebhook = ` - Source Server ID: ${response.source_guild.id} - Source Server Name: ${response.source_guild.name} - Source Channel ID: ${response.source_channel.id} - Source Channel Name: ${response.source_channel.name} - `; - sourceGuildGet = sourceWebhook; - } - else { - sourceGuildGet = ""; - } sendBotMessage(ctx.channel.id, { content: `This webhook was created by <@${response.user.id}>.`, embeds: [ @@ -94,7 +81,6 @@ export default definePlugin({ author: { // @ts-ignore icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, - proxy_icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, name: response.name, url: "" }, @@ -103,10 +89,7 @@ export default definePlugin({ Webhook Token: ${response.token} Webhook Type: ${response.type} Channel ID: ${response.channel_id} - Server ID: ${response.guild_id} - ${sourceGuildGet} - - Creator UserID: ${response.user.id}` + Server ID: ${response.guild_id}` }] }); }); @@ -142,7 +125,13 @@ export default definePlugin({ required: false }, { - name: "rawjson", + name: "attachment", + description: "Send with a custom attachment.", + type: ApplicationCommandOptionType.ATTACHMENT, + required: false + }, + { + name: "raw", description: "Send message as raw JSON", type: ApplicationCommandOptionType.BOOLEAN, required: false @@ -153,13 +142,13 @@ export default definePlugin({ const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); let webhookUsername = findOption(option, "username"); - if (findOption(option, "rawjson")) { + if (findOption(option, "raw")) { Native.executeWebhook("" + webhookUrl, { webhookMessage }); } else { - fetch("" + webhookUrl).then(response => response.json().then(response => { if (webhookUsername === "") { webhookUsername = response.name; } })); + webhookUsername = undefined; Native.executeWebhook("" + webhookUrl, { content: webhookMessage, From 610c48fe924e1582e2dd5f0506960b2f98d8c005 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:25:15 -0400 Subject: [PATCH 034/100] hope this adds attachment support, if not i may need help --- src/plugins/WebhookManager/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 5359bd9fa..cf3c98479 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -141,6 +141,7 @@ export default definePlugin({ const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); + const webhookAttachment = findOption(option, "attachment"); let webhookUsername = findOption(option, "username"); if (findOption(option, "raw")) { Native.executeWebhook("" + webhookUrl, { @@ -154,7 +155,8 @@ export default definePlugin({ content: webhookMessage, username: webhookUsername, avatar_url: "", - tts: findOption(option, "tts") + tts: findOption(option, "tts"), + attachments: webhookAttachment }); } From 1947cedd559ced60e9db6d5b1e4bb3e9f21cf54e Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:31:05 -0400 Subject: [PATCH 035/100] oops forgot to add back the if statement --- src/plugins/WebhookManager/index.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index cf3c98479..588139807 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -125,8 +125,8 @@ export default definePlugin({ required: false }, { - name: "attachment", - description: "Send with a custom attachment.", + name: "pfp", + description: "Send with a custom profile picture.", type: ApplicationCommandOptionType.ATTACHMENT, required: false }, @@ -141,7 +141,7 @@ export default definePlugin({ const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); - const webhookAttachment = findOption(option, "attachment"); + const webhookProfilePic = findOption(option, "pfp"); let webhookUsername = findOption(option, "username"); if (findOption(option, "raw")) { Native.executeWebhook("" + webhookUrl, { @@ -149,14 +149,15 @@ export default definePlugin({ }); } else { - webhookUsername = undefined; + if (webhookUsername === "") { + webhookUsername = undefined; + } Native.executeWebhook("" + webhookUrl, { content: webhookMessage, username: webhookUsername, - avatar_url: "", + avatar_url: webhookProfilePic, tts: findOption(option, "tts"), - attachments: webhookAttachment }); } From 2ac335c3f4544f326796b66c55489fe57c55eb86 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:28:08 -0400 Subject: [PATCH 036/100] handle if there is no profile pic option, also making it string only because compatibility issues --- src/plugins/WebhookManager/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 588139807..341eeddc5 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -126,8 +126,8 @@ export default definePlugin({ }, { name: "pfp", - description: "Send with a custom profile picture.", - type: ApplicationCommandOptionType.ATTACHMENT, + description: "Send with a custom profile picture. You must input a valid image URL.", + type: ApplicationCommandOptionType.STRING, required: false }, { @@ -141,7 +141,7 @@ export default definePlugin({ const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); - const webhookProfilePic = findOption(option, "pfp"); + let webhookProfilePic = findOption(option, "pfp"); let webhookUsername = findOption(option, "username"); if (findOption(option, "raw")) { Native.executeWebhook("" + webhookUrl, { @@ -153,6 +153,10 @@ export default definePlugin({ webhookUsername = undefined; } + if (webhookProfilePic === "") { + webhookProfilePic = undefined; + } + Native.executeWebhook("" + webhookUrl, { content: webhookMessage, username: webhookUsername, From 7c71d9f52d05cf0bf24a574c2a23a63365f377c2 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:27:57 -0400 Subject: [PATCH 037/100] added url validation --- src/plugins/WebhookManager/index.tsx | 5 ++--- src/plugins/WebhookManager/native.ts | 17 +++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 341eeddc5..23e678594 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -12,6 +12,7 @@ import { RestAPI } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); + export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", @@ -163,12 +164,10 @@ export default definePlugin({ avatar_url: webhookProfilePic, tts: findOption(option, "tts"), }); - } sendBotMessage(ctx.channel.id, { - content: "Message sent successfully." + content: "Your message to the webhook has been executed." }); - } } ] diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index ae2f108dd..12dcdc890 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -4,19 +4,16 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -/* -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"; - export function executeWebhook(_, url: string, body: object) { + const { hostname, pathname } = new URL(url); + + if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(hostname) || !pathname.startsWith("/api/webhooks/")) { + + throw new Error("This URL is not a valid webhook."); + } + const req = https.request(url, { method: "POST", From 3ec9f7cf897a2368a89b1c9b42f67d24dd933a34 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:32:35 -0400 Subject: [PATCH 038/100] test push that hopefully fixes something --- src/plugins/WebhookManager/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 23e678594..aa8f0db30 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -18,7 +18,6 @@ export default definePlugin({ description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", authors: [Devs.Byron], dependencies: ["CommandsAPI"], - commands: [ { name: "webhook delete", From c2a8671f31c44fbb4e1ed321aa7da4b5b864eef4 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:35:04 -0400 Subject: [PATCH 039/100] linting and testing all over the place --- src/plugins/WebhookManager/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index aa8f0db30..a4d2a0bf8 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -76,8 +76,8 @@ export default definePlugin({ embeds: [ { // @ts-ignore - title: `Webhook Information`, - color: '#00007d', + title: "Webhook Information", + color: "#00007d", author: { // @ts-ignore icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, From 1a106e755b2ab19e0c8e618a5e10c46284d1b499 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:39:01 -0400 Subject: [PATCH 040/100] TEMP DOING THIS JUST TO FIX BRANCH ISSUE --- src/utils/constants.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 5a51a0c45..848feab18 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -427,10 +427,6 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Elvyra", id: 708275751816003615n, }, - Byron: { - name: "byron", - id: 639577344276692992n - } } satisfies Record); // iife so #__PURE__ works correctly From 1d93a03654d7869abdd14996f3980085e9d07fd5 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:40:42 -0400 Subject: [PATCH 041/100] revert --- src/utils/constants.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 848feab18..5a51a0c45 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -427,6 +427,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Elvyra", id: 708275751816003615n, }, + Byron: { + name: "byron", + id: 639577344276692992n + } } satisfies Record); // iife so #__PURE__ works correctly From 9edb4c01f2d9e3a42d3d5efd91a75f9165a0199c Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:06:57 -0400 Subject: [PATCH 042/100] test --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index a4d2a0bf8..f8e114e12 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -165,7 +165,7 @@ export default definePlugin({ }); } sendBotMessage(ctx.channel.id, { - content: "Your message to the webhook has been executed." + content: "Your webhook message has been executed." }); } } From 83fedd4df19ced463c09f24f433a8b29093ca9a6 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:16:41 -0400 Subject: [PATCH 043/100] remove empty lines --- src/plugins/WebhookManager/native.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index 12dcdc890..321739e12 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -10,7 +10,6 @@ export function executeWebhook(_, url: string, body: object) { const { hostname, pathname } = new URL(url); if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(hostname) || !pathname.startsWith("/api/webhooks/")) { - throw new Error("This URL is not a valid webhook."); } From 39b3e747f99cd5a3e6bf594fca650aa1a1152a65 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:17:31 -0400 Subject: [PATCH 044/100] also updating dev label to be on proper account --- src/utils/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 515715a54..dc89e9a40 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -427,8 +427,8 @@ export const Devs = /* #__PURE__*/ Object.freeze({ id: 421405303951851520n }, Byron: { - name: "byron", - id: 639577344276692992n + name: "byeoon", + id: 1167275288036655133n } } satisfies Record); From b7225136623a8a94d74e754a99aa73ae83718f52 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:40:16 -0400 Subject: [PATCH 045/100] add debug to check sticker output --- src/plugins/emoteCloner/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 4c0fe94ad..cf252edf8 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -145,8 +145,10 @@ async function fetchBlob(url: string) { async function doClone(guildId: string, data: Sticker | Emoji) { try { - if (data.t === "Sticker") + if (data.t === "Sticker") { + new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + data); await cloneSticker(guildId, data); + } else await cloneEmoji(guildId, data); From 570e41b95ced20515e24ad528ae1929d3e66c939 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:43:46 -0400 Subject: [PATCH 046/100] bruh moment i should probably change forks --- src/plugins/emoteCloner/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index cf252edf8..6db07cbfc 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -87,6 +87,9 @@ async function cloneSticker(guildId: string, sticker: Sticker) { body: data, }); + new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + data); + new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + sticker.name); + FluxDispatcher.dispatch({ type: "GUILD_STICKERS_CREATE_SUCCESS", guildId, @@ -146,7 +149,6 @@ async function fetchBlob(url: string) { async function doClone(guildId: string, data: Sticker | Emoji) { try { if (data.t === "Sticker") { - new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + data); await cloneSticker(guildId, data); } else From 2c11a7ad84ab4d7e7d60cd3e7fad7743cce4f431 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:04:32 -0400 Subject: [PATCH 047/100] Set the default sticker size to 2048 to prevent downscaling, also, time to put this into a second branch --- src/plugins/emoteCloner/index.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 6db07cbfc..5bc086ce5 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -56,7 +56,7 @@ function getUrl(data: Data) { if (data.t === "Emoji") return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}`; - return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}`; + return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=2048`; } async function fetchSticker(id: string) { @@ -87,9 +87,6 @@ async function cloneSticker(guildId: string, sticker: Sticker) { body: data, }); - new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + data); - new Logger("EmoteCloner").info("hiiii hi hi hi :3 " + sticker.name); - FluxDispatcher.dispatch({ type: "GUILD_STICKERS_CREATE_SUCCESS", guildId, @@ -165,7 +162,7 @@ async function doClone(guildId: string, data: Sticker | Emoji) { message = JSON.parse(e.text).message; } catch { } - new Logger("EmoteCloner").error("Failed to clone", data.name, "to", guildId, e); + new Logger("EmoteCloner").error("Failed to clone", data.name, "to server ", guildId, e); Toasts.show({ message: "Failed to clone: " + message, type: Toasts.Type.FAILURE, From abf48db04d402e9daff7814b46a80abfa73d2167 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:15:28 -0400 Subject: [PATCH 048/100] (fix)Fixed a bug where EmoteCloner would clone stickers at the lowest resolution (now defaults to 2048) --- src/plugins/emoteCloner/index.tsx | 4 ++-- src/utils/constants.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 4c0fe94ad..ea5b33dbe 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -56,7 +56,7 @@ function getUrl(data: Data) { if (data.t === "Emoji") return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}`; - return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}`; + return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=2048`; } async function fetchSticker(id: string) { @@ -362,7 +362,7 @@ export default definePlugin({ name: "EmoteCloner", description: "Allows you to clone Emotes & Stickers to your own server (right click them)", tags: ["StickerCloner"], - authors: [Devs.Ven, Devs.Nuckyz], + authors: [Devs.Ven, Devs.Nuckyz, Devs.Byron], contextMenus: { "message": messageContextMenuPatch, "expression-picker": expressionPickerPatch diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f3626aaa0..dc89e9a40 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -425,6 +425,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ newwares: { name: "newwares", id: 421405303951851520n + }, + Byron: { + name: "byeoon", + id: 1167275288036655133n } } satisfies Record); From c5d03bab3b8b4508cf43722fe100e33415da72af Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:20:51 -0400 Subject: [PATCH 049/100] oopsie idk why i added words there --- src/plugins/emoteCloner/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 5bc086ce5..f380d0990 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -162,7 +162,7 @@ async function doClone(guildId: string, data: Sticker | Emoji) { message = JSON.parse(e.text).message; } catch { } - new Logger("EmoteCloner").error("Failed to clone", data.name, "to server ", guildId, e); + new Logger("EmoteCloner").error("Failed to clone", data.name, "to", guildId, e); Toasts.show({ message: "Failed to clone: " + message, type: Toasts.Type.FAILURE, From 38647087e00e85fa68db38308392f30abc3da513 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 2 Apr 2024 07:28:15 -0400 Subject: [PATCH 050/100] update to actual highest quality Co-authored-by: Nam Anh --- src/plugins/emoteCloner/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index ea5b33dbe..c2c975b70 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -56,7 +56,7 @@ function getUrl(data: Data) { if (data.t === "Emoji") return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}`; - return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=2048`; + return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096`; } async function fetchSticker(id: string) { From bc64dd400a38271d06bd426ed0fd8fd7cac0bb08 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:19:00 -0400 Subject: [PATCH 051/100] fixed a bug where external emotes counted towards the limit (twitch) --- src/plugins/emoteCloner/index.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index f380d0990..27bb1eca2 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -129,9 +129,15 @@ function getGuildCandidates(data: Data) { const { emojis } = EmojiStore.getGuilds()[g.id]; let count = 0; - for (const emoji of emojis) - if (emoji.animated === isAnimated) count++; - return count < emojiSlots; + for (const emoji of emojis) { + if (emoji.animated === isAnimated) { + count++; + } + if (emoji.managed === true) { + count--; // twitch emojis do not count towards the limit + } + } + return count = emojiSlots; }).sort((a, b) => a.name.localeCompare(b.name)); } From 23992bd213ad5de630b36aee30aea67841a1c9c9 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:20:37 -0400 Subject: [PATCH 052/100] fixed an issue where external emotes would count towards the max emote limit --- src/plugins/emoteCloner/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index c2c975b70..ea040965c 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -129,8 +129,14 @@ function getGuildCandidates(data: Data) { const { emojis } = EmojiStore.getGuilds()[g.id]; let count = 0; - for (const emoji of emojis) - if (emoji.animated === isAnimated) count++; + for (const emoji of emojis) { + if (emoji.animated === isAnimated) { + count++; + } + if (emoji.managed === true) { + count--; // twitch emojis do not count towards the limit + } + } return count < emojiSlots; }).sort((a, b) => a.name.localeCompare(b.name)); } From 521647b4e1e7e8b7eb03014c4a951d2aa62e0b36 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:32:17 -0400 Subject: [PATCH 053/100] merged into above statement --- src/plugins/emoteCloner/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index ea040965c..3976b3991 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -132,10 +132,11 @@ function getGuildCandidates(data: Data) { for (const emoji of emojis) { if (emoji.animated === isAnimated) { count++; + if (emoji.managed === true) { + count--; + } } - if (emoji.managed === true) { - count--; // twitch emojis do not count towards the limit - } + } return count < emojiSlots; }).sort((a, b) => a.name.localeCompare(b.name)); From e24d5d3f9361dc4bdf2035dc038fd5521503b826 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:39:46 -0400 Subject: [PATCH 054/100] Update src/plugins/emoteCloner/index.tsx Co-authored-by: ryan-0324 <77452312+ryan-0324@users.noreply.github.com> --- src/plugins/emoteCloner/index.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 3976b3991..ecdd62b42 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -129,15 +129,9 @@ function getGuildCandidates(data: Data) { const { emojis } = EmojiStore.getGuilds()[g.id]; let count = 0; - for (const emoji of emojis) { - if (emoji.animated === isAnimated) { + for (const emoji of emojis) + if (emoji.animated === isAnimated && !emoji.managed) count++; - if (emoji.managed === true) { - count--; - } - } - - } return count < emojiSlots; }).sort((a, b) => a.name.localeCompare(b.name)); } From 522d2fd35c6e4ef498fbd8ac2b31b623b5e2040d Mon Sep 17 00:00:00 2001 From: V Date: Tue, 9 Apr 2024 02:29:20 +0200 Subject: [PATCH 055/100] lossless --- src/plugins/emoteCloner/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index ecdd62b42..08389a756 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -54,9 +54,9 @@ const StickerExt = [, "png", "png", "json", "gif"] as const; function getUrl(data: Data) { if (data.t === "Emoji") - return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}`; + return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}?size=4096&lossless=true`; - return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096`; + return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096&lossless=true`; } async function fetchSticker(id: string) { From 4c466e9c04570bc498fa10358554cf2dd810d976 Mon Sep 17 00:00:00 2001 From: V Date: Tue, 9 Apr 2024 02:29:58 +0200 Subject: [PATCH 056/100] Update index.tsx --- src/plugins/emoteCloner/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 08389a756..cd9890a80 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -363,7 +363,7 @@ export default definePlugin({ name: "EmoteCloner", description: "Allows you to clone Emotes & Stickers to your own server (right click them)", tags: ["StickerCloner"], - authors: [Devs.Ven, Devs.Nuckyz, Devs.Byron], + authors: [Devs.Ven, Devs.Nuckyz], contextMenus: { "message": messageContextMenuPatch, "expression-picker": expressionPickerPatch From 1dc98721ee622d3b955fce8923e8035eda3badbd Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:52:50 -0400 Subject: [PATCH 057/100] Instead of logging to console when there's an error, log it to the webhook message, also fixes to the README --- src/plugins/WebhookManager/README.MD | 26 ++++++++++++-------------- src/plugins/WebhookManager/index.tsx | 6 ++---- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index 245c51875..c50fd759b 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -1,7 +1,6 @@ -
-

WebhookManager

+# WebhookManager Manage your webhooks easily; delete, send messages, get detailed info and more. -
+ ## Commands - /webhook send - *Sends a message through a webhook.* @@ -9,16 +8,15 @@ - /webhook delete - *Deletes a webhook.* - + - /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it*
Full /webhookinfo Output - - Webhook Username
- - Webhook ID
- - Webhook Token
- - Channel ID
- - Server ID
- - Webhook Profile Picture
- - Webhook Type
- - Creator Profile
- - Creator UserID
-
\ No newline at end of file + - Webhook Username + - Webhook ID + - Webhook Token + - Channel ID + - Server ID + - Webhook Profile Picture + - Webhook Type + - Creator Profile + diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index f8e114e12..fccef8dbf 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -40,16 +40,14 @@ export default definePlugin({ }); } else { - WMLogger.error("WebhookManager encountered an error deleting a webhook. " + res.status); sendBotMessage(ctx.channel.id, { - content: "There was an error deleting the webhook. Check the console for more info." + content: "There was an error with deleting the webhook, error code: " + res.status }); } } catch (error) { - WMLogger.error("WebhookManager encountered an error deleting a webhook. " + error); sendBotMessage(ctx.channel.id, { - content: "There was an error deleting the webhook. Check the console for more info. Did you input a valid webhook URL?" + content: "There was an error deleting the webhook. Did you input a valid webhook URL? Error: " + error }); } } From 31993c00539c671a49c6a2c886fc87d585aacc1a Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:05:26 -0400 Subject: [PATCH 058/100] oops readme was broken fixed it again --- src/plugins/WebhookManager/README.MD | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index c50fd759b..fa62b36b5 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -6,17 +6,25 @@ - /webhook send - *Sends a message through a webhook.* - - /webhook delete - *Deletes a webhook.* + - /webhook delete - *Deletes any webhook that is specified.* - /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it*
Full /webhookinfo Output - Webhook Username + - Webhook ID + - Webhook Token + - Channel ID + - Server ID + - Webhook Profile Picture + - Webhook Type + - Creator Profile +
From 8c48731026363b7e3792564d2884af734573b781 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:06:20 -0400 Subject: [PATCH 059/100] this shit is confusing me --- src/plugins/WebhookManager/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index fa62b36b5..b334f7ec9 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -11,6 +11,7 @@ - /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it*
Full /webhookinfo Output + - Webhook Username - Webhook ID From f801ab3cb920130594c3cde7eee43debe1633d3d Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:13:50 -0400 Subject: [PATCH 060/100] Discard changes to src/plugins/emoteCloner/index.tsx --- src/plugins/emoteCloner/index.tsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 27bb1eca2..4c0fe94ad 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -56,7 +56,7 @@ function getUrl(data: Data) { if (data.t === "Emoji") return `${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/emojis/${data.id}.${data.isAnimated ? "gif" : "png"}`; - return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=2048`; + return `${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}`; } async function fetchSticker(id: string) { @@ -129,15 +129,9 @@ function getGuildCandidates(data: Data) { const { emojis } = EmojiStore.getGuilds()[g.id]; let count = 0; - for (const emoji of emojis) { - if (emoji.animated === isAnimated) { - count++; - } - if (emoji.managed === true) { - count--; // twitch emojis do not count towards the limit - } - } - return count = emojiSlots; + for (const emoji of emojis) + if (emoji.animated === isAnimated) count++; + return count < emojiSlots; }).sort((a, b) => a.name.localeCompare(b.name)); } @@ -151,9 +145,8 @@ async function fetchBlob(url: string) { async function doClone(guildId: string, data: Sticker | Emoji) { try { - if (data.t === "Sticker") { + if (data.t === "Sticker") await cloneSticker(guildId, data); - } else await cloneEmoji(guildId, data); From 8f0204b4cae3e4add2d78ed59ab7eb6c8dcfb7fb Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:13:57 -0400 Subject: [PATCH 061/100] Discard changes to src/utils/constants.ts --- src/utils/constants.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index dc89e9a40..f3626aaa0 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -425,10 +425,6 @@ export const Devs = /* #__PURE__*/ Object.freeze({ newwares: { name: "newwares", id: 421405303951851520n - }, - Byron: { - name: "byeoon", - id: 1167275288036655133n } } satisfies Record); From b4366bdab6cf945edb2db6b0f0b623f99b118607 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:32:53 -0400 Subject: [PATCH 062/100] small code refactors and changes to text --- src/plugins/WebhookManager/index.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index fccef8dbf..9c9a827b1 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -41,7 +41,7 @@ export default definePlugin({ } else { sendBotMessage(ctx.channel.id, { - content: "There was an error with deleting the webhook, error code: " + res.status + content: "There was an error with deleting the webhook, Error: " + res.status }); } } @@ -112,7 +112,7 @@ export default definePlugin({ }, { name: "username", - description: "Send with a custom webhook username", + description: "Send with a custom username", type: ApplicationCommandOptionType.STRING, required: false }, @@ -147,13 +147,11 @@ export default definePlugin({ }); } else { - if (webhookUsername === "") { + if (webhookUsername === "") webhookUsername = undefined; - } - if (webhookProfilePic === "") { + if (webhookProfilePic === "") webhookProfilePic = undefined; - } Native.executeWebhook("" + webhookUrl, { content: webhookMessage, From 28f70e29422ab756b7e99b79a38bd0b3bca2f774 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 1 May 2024 18:02:14 -0400 Subject: [PATCH 063/100] fix embed color not being blue, fix webhook profile picture not appearing, fix deleting webhooks not working, general code and QoL improvements --- src/plugins/WebhookManager/index.tsx | 27 ++++++++++----------------- src/plugins/WebhookManager/native.ts | 8 +------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 9c9a827b1..732fb8281 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -8,7 +8,6 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { PluginNative } from "@utils/types"; -import { RestAPI } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; const WMLogger = new Logger("WebhookManager"); @@ -32,18 +31,8 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - const res = await RestAPI.delete({ url: "" + findOption(option, "url") }); try { - if (res.ok) { - sendBotMessage(ctx.channel.id, { - content: "Webhook deleted successfully." - }); - } - else { - sendBotMessage(ctx.channel.id, { - content: "There was an error with deleting the webhook, Error: " + res.status - }); - } + await fetch("" + findOption(option, "url"), { method: 'DELETE' }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); } catch (error) { sendBotMessage(ctx.channel.id, { @@ -70,18 +59,22 @@ export default definePlugin({ .then(response => { WMLogger.info(JSON.stringify(response)); sendBotMessage(ctx.channel.id, { - content: `This webhook was created by <@${response.user.id}>.`, + content: `This webhook was created by ${response.user?.name}.`, embeds: [ { - // @ts-ignore title: "Webhook Information", - color: "#00007d", + color: "1323", + //@ts-ignore author: { - // @ts-ignore - icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, name: response.name, url: "" }, + thumbnail: { + url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + proxyURL: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, + height: 128, + width: 128 + }, description: ` Webhook ID: ${response.id} Webhook Token: ${response.token} diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/WebhookManager/native.ts index 321739e12..05b5beab8 100644 --- a/src/plugins/WebhookManager/native.ts +++ b/src/plugins/WebhookManager/native.ts @@ -13,13 +13,7 @@ export function executeWebhook(_, url: string, body: object) { throw new Error("This URL is not a valid webhook."); } - const req = https.request(url, - { - method: "POST", - headers: { - "Content-Type": "application/json", - } - }); + const req = https.request(url, { method: "POST", headers: { "Content-Type": "application/json", } }); req.write(JSON.stringify(body)); req.end(); } From 7f36d8569f45fdad0be7aebcd17d4ae417ef6c12 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Wed, 1 May 2024 18:07:11 -0400 Subject: [PATCH 064/100] fixed lint --- src/plugins/WebhookManager/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 732fb8281..86e603297 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -32,7 +32,7 @@ export default definePlugin({ ], execute: async (option, ctx) => { try { - await fetch("" + findOption(option, "url"), { method: 'DELETE' }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); + await fetch("" + findOption(option, "url"), { method: "DELETE" }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); } catch (error) { sendBotMessage(ctx.channel.id, { @@ -64,7 +64,7 @@ export default definePlugin({ { title: "Webhook Information", color: "1323", - //@ts-ignore + // @ts-ignore author: { name: response.name, url: "" From f04bd8a7adb819baf9454dcd1f12d4a0e38832db Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 7 May 2024 06:13:38 -0300 Subject: [PATCH 065/100] useStateFromStores: Document 3rd param and fix JSDoc --- src/webpack/common/stores.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index 2f9786bc5..b5b3a0e73 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -16,10 +16,11 @@ * along with this program. If not, see . */ +import { proxyLazy } from "@utils/lazy"; import type * as Stores from "discord-types/stores"; // eslint-disable-next-line path-alias/no-relative -import { findByPropsLazy } from "../webpack"; +import { findByProps, findByPropsLazy } from "../webpack"; import { waitForStore } from "./internal"; import * as t from "./types/stores"; @@ -67,20 +68,17 @@ export let DraftStore: t.DraftStore; * * @param stores The stores to listen to * @param mapper A function that returns the data you need - * @param idk some thing, idk just pass null + * @param dependencies An array of reactive values which the hook depends on. Use this if your mapper or equality function depends on the value of another hook * @param isEqual A custom comparator for the data returned by mapper * * @example const user = useStateFromStores([UserStore], () => UserStore.getCurrentUser(), null, (old, current) => old.id === current.id); */ -export const { useStateFromStores }: { - useStateFromStores: ( - stores: t.FluxStore[], - mapper: () => T, - idk?: any, - isEqual?: (old: T, newer: T) => boolean - ) => T; -} - = findByPropsLazy("useStateFromStores"); +export const useStateFromStores = proxyLazy(() => findByProps("useStateFromStores").useStateFromStores) as ( + stores: t.FluxStore[], + mapper: () => T, + dependencies?: any, + isEqual?: (old: T, newer: T) => boolean +) => T; waitForStore("DraftStore", s => DraftStore = s); waitForStore("UserStore", s => UserStore = s); From 13119c0b29e4577c992d82276e76168421876add Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Wed, 15 May 2024 09:43:30 -0400 Subject: [PATCH 066/100] extra error handling - will add more later --- src/plugins/WebhookManager/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 86e603297..2e206a132 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -35,6 +35,12 @@ export default definePlugin({ await fetch("" + findOption(option, "url"), { method: "DELETE" }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); } catch (error) { + if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(findOption(option, "url")) || !pathname.startsWith("/api/webhooks/")) { + sendBotMessage(ctx.channel.id, { + content: "Please input a valid webhook URL to delete." + }); + } + sendBotMessage(ctx.channel.id, { content: "There was an error deleting the webhook. Did you input a valid webhook URL? Error: " + error }); From f0483f9c24f67e2c8db53a90398d5f2184ee0f47 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Wed, 15 May 2024 09:46:10 -0400 Subject: [PATCH 067/100] why cant i remove the stores.ts conflict --- src/webpack/common/stores.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index b5b3a0e73..c03b60507 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -79,6 +79,7 @@ export const useStateFromStores = proxyLazy(() => findByProps("useStateFromStore dependencies?: any, isEqual?: (old: T, newer: T) => boolean ) => T; +// why the fuck cant i get rid of this stupid fucking conflict waitForStore("DraftStore", s => DraftStore = s); waitForStore("UserStore", s => UserStore = s); From 46e4fc664a047d205c0eb7db07a2630e12b9571e Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Wed, 15 May 2024 09:49:32 -0400 Subject: [PATCH 068/100] oopsie --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 2e206a132..9fcff3be8 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -35,7 +35,7 @@ export default definePlugin({ await fetch("" + findOption(option, "url"), { method: "DELETE" }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); } catch (error) { - if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(findOption(option, "url")) || !pathname.startsWith("/api/webhooks/")) { + if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(findOption(option, "url")) || !findOption(option, "url").startsWith("/api/webhooks/")) { sendBotMessage(ctx.channel.id, { content: "Please input a valid webhook URL to delete." }); From d29d5e9476d9744b247bce86e73068a6c01640fe Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 20 May 2024 15:53:56 -0400 Subject: [PATCH 069/100] revert error change --- src/plugins/WebhookManager/index.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 9fcff3be8..86e603297 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -35,12 +35,6 @@ export default definePlugin({ await fetch("" + findOption(option, "url"), { method: "DELETE" }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); } catch (error) { - if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(findOption(option, "url")) || !findOption(option, "url").startsWith("/api/webhooks/")) { - sendBotMessage(ctx.channel.id, { - content: "Please input a valid webhook URL to delete." - }); - } - sendBotMessage(ctx.channel.id, { content: "There was an error deleting the webhook. Did you input a valid webhook URL? Error: " + error }); From c8602ef52be0a1171be9506f23ba6208f0be4436 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 29 May 2024 06:45:44 -0300 Subject: [PATCH 070/100] Fix reporter breaking because of ConsoleShortcuts --- scripts/generateReport.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 8bb87d812..200aa3f83 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -205,7 +205,12 @@ page.on("console", async e => { } if (isVencord) { - const args = await Promise.all(e.args().map(a => a.jsonValue())); + let args: unknown[] = []; + try { + args = await Promise.all(e.args().map(a => a.jsonValue())); + } catch { + return; + } const [, tag, message] = args as Array; const cause = await maybeGetError(e.args()[3]); From 892de53603a1af1bf9f4dbd331868f12fec2edc0 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 30 May 2024 00:51:23 -0300 Subject: [PATCH 071/100] Fix extractAndLoadChunks issue with 2 match groups; Improve testing of lazy extractAndLoadChunks --- scripts/generateReport.ts | 11 +++++------ src/webpack/webpack.ts | 37 ++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 200aa3f83..d3068492f 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -343,7 +343,7 @@ async function runtime(token: string) { // True if resolved, false otherwise const chunksSearchPromises = [] as Array<() => boolean>; - const LazyChunkRegex = canonicalizeMatch(/(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\)))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); + const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); async function searchAndLoadLazyChunks(factoryCode: string) { const lazyChunks = factoryCode.matchAll(LazyChunkRegex); @@ -353,8 +353,7 @@ async function runtime(token: string) { // the chunk containing the component const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT"); - await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIdsArray, rawChunkIdsSingle, entryPoint]) => { - const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle; + await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Vencord.Webpack.ChunkIdsRegex)).map(m => m[1]) : []; if (chunkIds.length === 0) { @@ -525,14 +524,14 @@ async function runtime(token: string) { } else if (method === "extractAndLoadChunks") { const [code, matcher] = args; - const module = Vencord.Webpack.findModuleFactory(...code); - if (module) result = module.toString().match(canonicalizeMatch(matcher)); + result = await Vencord.Webpack.extractAndLoadChunks(code, matcher); + if (result === false) result = null; } else { // @ts-ignore result = Vencord.Webpack[method](...args); } - if (result == null || ("$$vencordInternal" in result && result.$$vencordInternal() == null)) throw "a rock at ben shapiro"; + if (result == null || (result.$$vencordInternal != null && result.$$vencordInternal() == null)) throw "a rock at ben shapiro"; } catch (e) { let logMessage = searchType; if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${args[0].toString().slice(0, 147)}...)`; diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index f2e6e58a8..9e0c0d000 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -402,14 +402,14 @@ export function findExportedComponentLazy(...props: stri }); } -export const DefaultExtractAndLoadChunksRegex = /(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\))|Promise\.resolve\(\))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/; -export const ChunkIdsRegex = /\("(.+?)"\)/g; +export const DefaultExtractAndLoadChunksRegex = /(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?|Promise\.resolve\(\))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/; +export const ChunkIdsRegex = /\("([^"]+?)"\)/g; /** * Extract and load chunks using their entry point * @param code An array of all the code the module factory containing the lazy chunk loading must include - * @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory - * @returns A promise that resolves when the chunks were loaded + * @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory + * @returns A promise that resolves with a boolean whether the chunks were loaded */ export async function extractAndLoadChunks(code: string[], matcher: RegExp = DefaultExtractAndLoadChunksRegex) { const module = findModuleFactory(...code); @@ -417,7 +417,11 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def const err = new Error("extractAndLoadChunks: Couldn't find module factory"); logger.warn(err, "Code:", code, "Matcher:", matcher); - return; + // Strict behaviour in DevBuilds to fail early and make sure the issue is found + if (IS_DEV && !devToolsOpen) + throw err; + + return false; } const match = module.toString().match(canonicalizeMatch(matcher)); @@ -429,10 +433,10 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def if (IS_DEV && !devToolsOpen) throw err; - return; + return false; } - const [, rawChunkIdsArray, rawChunkIdsSingle, entryPointId] = match; + const [, rawChunkIds, entryPointId] = match; if (Number.isNaN(Number(entryPointId))) { const err = new Error("extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number"); logger.warn(err, "Code:", code, "Matcher:", matcher); @@ -441,16 +445,27 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def if (IS_DEV && !devToolsOpen) throw err; - return; + return false; } - const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle; if (rawChunkIds) { const chunkIds = Array.from(rawChunkIds.matchAll(ChunkIdsRegex)).map((m: any) => m[1]); await Promise.all(chunkIds.map(id => wreq.e(id))); } + if (wreq.m[entryPointId] == null) { + const err = new Error("extractAndLoadChunks: Entry point is not loaded in the module factories, perhaps one of the chunks failed to load"); + logger.warn(err, "Code:", code, "Matcher:", matcher); + + // Strict behaviour in DevBuilds to fail early and make sure the issue is found + if (IS_DEV && !devToolsOpen) + throw err; + + return false; + } + wreq(entryPointId); + return true; } /** @@ -458,8 +473,8 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def * * Extract and load chunks using their entry point * @param code An array of all the code the module factory containing the lazy chunk loading must include - * @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory - * @returns A function that returns a promise that resolves when the chunks were loaded, on first call + * @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory + * @returns A function that returns a promise that resolves with a boolean whether the chunks were loaded, on first call */ export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtractAndLoadChunksRegex) { if (IS_DEV) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]); From 9a9c1b04871599000557d068ab7d00c5b495bfa5 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 30 May 2024 04:44:13 -0300 Subject: [PATCH 072/100] Reporter: Properly implement reporter build of Vencord; Test more plugins; Fix running in wrong pages --- .github/workflows/reportBrokenPlugins.yml | 4 +- package.json | 2 + scripts/build/build.mjs | 22 ++--- scripts/build/buildWeb.mjs | 52 ++++++----- scripts/build/common.mjs | 30 ++++--- scripts/generateReport.ts | 47 ++-------- src/debug/Tracer.ts | 8 +- src/globals.d.ts | 3 +- src/plugins/arRPC.web/index.tsx | 3 +- src/plugins/devCompanion.dev/index.tsx | 3 +- src/plugins/index.ts | 94 ++++++++++++++------ src/plugins/invisibleChat.desktop/index.tsx | 6 +- src/plugins/shikiCodeblocks.desktop/index.ts | 6 +- src/plugins/vcNarrator/index.tsx | 3 +- src/plugins/xsOverlay.desktop/index.ts | 4 +- src/utils/Logger.ts | 5 ++ src/utils/types.ts | 11 +++ src/webpack/common/internal.tsx | 4 +- src/webpack/webpack.ts | 22 ++--- 19 files changed, 184 insertions(+), 145 deletions(-) diff --git a/.github/workflows/reportBrokenPlugins.yml b/.github/workflows/reportBrokenPlugins.yml index d3a882fa3..a669c1a27 100644 --- a/.github/workflows/reportBrokenPlugins.yml +++ b/.github/workflows/reportBrokenPlugins.yml @@ -37,8 +37,8 @@ jobs: with: chrome-version: stable - - name: Build web - run: pnpm buildWeb --standalone --dev + - name: Build Vencord Reporter Version + run: pnpm buildReporter - name: Create Report timeout-minutes: 10 diff --git a/package.json b/package.json index 29b1506e2..881e42a28 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "build": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/build.mjs", "buildStandalone": "pnpm build --standalone", "buildWeb": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/buildWeb.mjs", + "buildReporter": "pnpm buildWeb --standalone --reporter --skip-extension", "watch": "pnpm build --watch", + "watchWeb": "pnpm buildWeb --watch", "generatePluginJson": "tsx scripts/generatePluginList.ts", "generateTypes": "tspc --emitDeclarationOnly --declaration --outDir packages/vencord-types", "inject": "node scripts/runInstaller.mjs", diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index 0c2a930a0..fcf56f66c 100755 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -21,19 +21,21 @@ import esbuild from "esbuild"; import { readdir } from "fs/promises"; import { join } from "path"; -import { BUILD_TIMESTAMP, commonOpts, existsAsync, globPlugins, isDev, isStandalone, updaterDisabled, VERSION, watch } from "./common.mjs"; +import { BUILD_TIMESTAMP, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_STANDALONE, IS_UPDATER_DISABLED, VERSION, watch } from "./common.mjs"; const defines = { - IS_STANDALONE: isStandalone, - IS_DEV: JSON.stringify(isDev), - IS_UPDATER_DISABLED: updaterDisabled, + IS_STANDALONE, + IS_DEV, + IS_REPORTER, + IS_UPDATER_DISABLED, IS_WEB: false, IS_EXTENSION: false, VERSION: JSON.stringify(VERSION), - BUILD_TIMESTAMP, + BUILD_TIMESTAMP }; -if (defines.IS_STANDALONE === "false") - // If this is a local build (not standalone), optimise + +if (defines.IS_STANDALONE === false) + // If this is a local build (not standalone), optimize // for the specific platform we're on defines["process.platform"] = JSON.stringify(process.platform); @@ -46,7 +48,7 @@ const nodeCommonOpts = { platform: "node", target: ["esnext"], external: ["electron", "original-fs", "~pluginNatives", ...commonOpts.external], - define: defines, + define: defines }; const sourceMapFooter = s => watch ? "" : `//# sourceMappingURL=vencord://${s}.js.map`; @@ -73,13 +75,13 @@ const globNativesPlugin = { let i = 0; for (const dir of pluginDirs) { const dirPath = join("src", dir); - if (!await existsAsync(dirPath)) continue; + if (!await exists(dirPath)) continue; const plugins = await readdir(dirPath); for (const p of plugins) { const nativePath = join(dirPath, p, "native.ts"); const indexNativePath = join(dirPath, p, "native/index.ts"); - if (!(await existsAsync(nativePath)) && !(await existsAsync(indexNativePath))) + if (!(await exists(nativePath)) && !(await exists(indexNativePath))) continue; const nameParts = p.split("."); diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index b4c726064..04ff674fc 100644 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -23,7 +23,7 @@ import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises import { join } from "path"; import Zip from "zip-local"; -import { BUILD_TIMESTAMP, commonOpts, globPlugins, isDev, VERSION } from "./common.mjs"; +import { BUILD_TIMESTAMP, commonOpts, globPlugins, IS_DEV, IS_REPORTER, VERSION } from "./common.mjs"; /** * @type {esbuild.BuildOptions} @@ -40,15 +40,16 @@ const commonOptions = { ], target: ["esnext"], define: { - IS_WEB: "true", - IS_EXTENSION: "false", - IS_STANDALONE: "true", - IS_DEV: JSON.stringify(isDev), - IS_DISCORD_DESKTOP: "false", - IS_VESKTOP: "false", - IS_UPDATER_DISABLED: "true", + IS_WEB: true, + IS_EXTENSION: false, + IS_STANDALONE: true, + IS_DEV, + IS_REPORTER, + IS_DISCORD_DESKTOP: false, + IS_VESKTOP: false, + IS_UPDATER_DISABLED: true, VERSION: JSON.stringify(VERSION), - BUILD_TIMESTAMP, + BUILD_TIMESTAMP } }; @@ -87,16 +88,16 @@ await Promise.all( esbuild.build({ ...commonOptions, outfile: "dist/browser.js", - footer: { js: "//# sourceURL=VencordWeb" }, + footer: { js: "//# sourceURL=VencordWeb" } }), esbuild.build({ ...commonOptions, outfile: "dist/extension.js", define: { ...commonOptions?.define, - IS_EXTENSION: "true", + IS_EXTENSION: true, }, - footer: { js: "//# sourceURL=VencordWeb" }, + footer: { js: "//# sourceURL=VencordWeb" } }), esbuild.build({ ...commonOptions, @@ -112,7 +113,7 @@ await Promise.all( footer: { // UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local js: "Object.defineProperty(unsafeWindow,'Vencord',{get:()=>Vencord});" - }, + } }) ] ); @@ -165,7 +166,7 @@ async function buildExtension(target, files) { f.startsWith("manifest") ? "manifest.json" : f, content ]; - }))), + }))) }; await rm(target, { recursive: true, force: true }); @@ -192,14 +193,19 @@ const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content return appendFile("dist/Vencord.user.js", cssRuntime); }); -await Promise.all([ - appendCssRuntime, - buildExtension("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"]), - buildExtension("firefox-unpacked", ["background.js", "content.js", "manifestv2.json", "icon.png"]), -]); +if (!process.argv.includes("--skip-extension")) { + await Promise.all([ + appendCssRuntime, + buildExtension("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"]), + buildExtension("firefox-unpacked", ["background.js", "content.js", "manifestv2.json", "icon.png"]), + ]); -Zip.sync.zip("dist/chromium-unpacked").compress().save("dist/extension-chrome.zip"); -console.info("Packed Chromium Extension written to dist/extension-chrome.zip"); + Zip.sync.zip("dist/chromium-unpacked").compress().save("dist/extension-chrome.zip"); + console.info("Packed Chromium Extension written to dist/extension-chrome.zip"); -Zip.sync.zip("dist/firefox-unpacked").compress().save("dist/extension-firefox.zip"); -console.info("Packed Firefox Extension written to dist/extension-firefox.zip"); + Zip.sync.zip("dist/firefox-unpacked").compress().save("dist/extension-firefox.zip"); + console.info("Packed Firefox Extension written to dist/extension-firefox.zip"); + +} else { + await appendCssRuntime; +} diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 3b1473e1c..cdbb26eec 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -35,24 +35,26 @@ const PackageJSON = JSON.parse(readFileSync("package.json")); export const VERSION = PackageJSON.version; // https://reproducible-builds.org/docs/source-date-epoch/ export const BUILD_TIMESTAMP = Number(process.env.SOURCE_DATE_EPOCH) || Date.now(); + export const watch = process.argv.includes("--watch"); -export const isDev = watch || process.argv.includes("--dev"); -export const isStandalone = JSON.stringify(process.argv.includes("--standalone")); -export const updaterDisabled = JSON.stringify(process.argv.includes("--disable-updater")); +export const IS_DEV = watch || process.argv.includes("--dev"); +export const IS_REPORTER = process.argv.includes("--reporter"); +export const IS_STANDALONE = process.argv.includes("--standalone"); + +export const IS_UPDATER_DISABLED = process.argv.includes("--disable-updater"); export const gitHash = process.env.VENCORD_HASH || execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim(); + export const banner = { js: ` // Vencord ${gitHash} -// Standalone: ${isStandalone} -// Platform: ${isStandalone === "false" ? process.platform : "Universal"} -// Updater disabled: ${updaterDisabled} +// Standalone: ${IS_STANDALONE} +// Platform: ${IS_STANDALONE === false ? process.platform : "Universal"} +// Updater Disabled: ${IS_UPDATER_DISABLED} `.trim() }; -const isWeb = process.argv.slice(0, 2).some(f => f.endsWith("buildWeb.mjs")); - -export function existsAsync(path) { - return access(path, FsConstants.F_OK) +export async function exists(path) { + return await access(path, FsConstants.F_OK) .then(() => true) .catch(() => false); } @@ -66,7 +68,7 @@ export const makeAllPackagesExternalPlugin = { setup(build) { const filter = /^[^./]|^\.[^./]|^\.\.[^/]/; // Must not start with "/" or "./" or "../" build.onResolve({ filter }, args => ({ path: args.path, external: true })); - }, + } }; /** @@ -89,14 +91,14 @@ export const globPlugins = kind => ({ let plugins = "\n"; let i = 0; for (const dir of pluginDirs) { - if (!await existsAsync(`./src/${dir}`)) continue; + if (!await exists(`./src/${dir}`)) continue; const files = await readdir(`./src/${dir}`); for (const file of files) { if (file.startsWith("_") || file.startsWith(".")) continue; if (file === "index.ts") continue; const target = getPluginTarget(file); - if (target) { + if (target && !IS_REPORTER) { if (target === "dev" && !watch) continue; if (target === "web" && kind === "discordDesktop") continue; if (target === "desktop" && kind === "web") continue; @@ -178,7 +180,7 @@ export const fileUrlPlugin = { build.onLoad({ filter, namespace: "file-uri" }, async ({ pluginData: { path, uri } }) => { const { searchParams } = new URL(uri); const base64 = searchParams.has("base64"); - const minify = isStandalone === "true" && searchParams.has("minify"); + const minify = IS_STANDALONE === true && searchParams.has("minify"); const noTrim = searchParams.get("trim") === "false"; const encoding = base64 ? "base64" : "utf-8"; diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index d3068492f..8233f3e5d 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -282,7 +282,7 @@ page.on("pageerror", e => console.error("[Page Error]", e)); await page.setBypassCSP(true); -async function runtime(token: string) { +async function reporterRuntime(token: string) { console.log("[PUP_DEBUG]", "Starting test..."); try { @@ -290,43 +290,7 @@ async function runtime(token: string) { Object.defineProperty(navigator, "languages", { get: function () { return ["en-US", "en"]; - }, - }); - - // Monkey patch Logger to not log with custom css - // @ts-ignore - const originalLog = Vencord.Util.Logger.prototype._log; - // @ts-ignore - Vencord.Util.Logger.prototype._log = function (level, levelColor, args) { - if (level === "warn" || level === "error") - return console[level]("[Vencord]", this.name + ":", ...args); - - return originalLog.call(this, level, levelColor, args); - }; - - // Force enable all plugins and patches - Vencord.Plugins.patches.length = 0; - Object.values(Vencord.Plugins.plugins).forEach(p => { - // Needs native server to run - if (p.name === "WebRichPresence (arRPC)") return; - - Vencord.Settings.plugins[p.name].enabled = true; - p.patches?.forEach(patch => { - patch.plugin = p.name; - delete patch.predicate; - delete patch.group; - - Vencord.Util.canonicalizeFind(patch); - if (!Array.isArray(patch.replacement)) { - patch.replacement = [patch.replacement]; - } - - patch.replacement.forEach(r => { - delete r.predicate; - }); - - Vencord.Plugins.patches.push(patch); - }); + } }); let wreq: typeof Vencord.Webpack.wreq; @@ -549,9 +513,10 @@ async function runtime(token: string) { } await page.evaluateOnNewDocument(` - ${readFileSync("./dist/browser.js", "utf-8")} - - ;(${runtime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)}); + if (location.host.endsWith("discord.com")) { + ${readFileSync("./dist/browser.js", "utf-8")}; + (${reporterRuntime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)}); + } `); await page.goto(CANARY ? "https://canary.discord.com/login" : "https://discord.com/login"); diff --git a/src/debug/Tracer.ts b/src/debug/Tracer.ts index 4337e0019..7d80f425c 100644 --- a/src/debug/Tracer.ts +++ b/src/debug/Tracer.ts @@ -18,14 +18,14 @@ import { Logger } from "@utils/Logger"; -if (IS_DEV) { +if (IS_DEV || IS_REPORTER) { var traces = {} as Record; var logger = new Logger("Tracer", "#FFD166"); } const noop = function () { }; -export const beginTrace = !IS_DEV ? noop : +export const beginTrace = !(IS_DEV || IS_REPORTER) ? noop : function beginTrace(name: string, ...args: any[]) { if (name in traces) throw new Error(`Trace ${name} already exists!`); @@ -33,7 +33,7 @@ export const beginTrace = !IS_DEV ? noop : traces[name] = [performance.now(), args]; }; -export const finishTrace = !IS_DEV ? noop : function finishTrace(name: string) { +export const finishTrace = !(IS_DEV || IS_REPORTER) ? noop : function finishTrace(name: string) { const end = performance.now(); const [start, args] = traces[name]; @@ -48,7 +48,7 @@ type TraceNameMapper = (...args: Parameters) => string; const noopTracer = (name: string, f: F, mapper?: TraceNameMapper) => f; -export const traceFunction = !IS_DEV +export const traceFunction = !(IS_DEV || IS_REPORTER) ? noopTracer : function traceFunction(name: string, f: F, mapper?: TraceNameMapper): F { return function (this: any, ...args: Parameters) { diff --git a/src/globals.d.ts b/src/globals.d.ts index 94b5f15e8..e20ca4b71 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -34,9 +34,10 @@ declare global { */ export var IS_WEB: boolean; export var IS_EXTENSION: boolean; - export var IS_DEV: boolean; export var IS_STANDALONE: boolean; export var IS_UPDATER_DISABLED: boolean; + export var IS_DEV: boolean; + export var IS_REPORTER: boolean; export var IS_DISCORD_DESKTOP: boolean; export var IS_VESKTOP: boolean; export var VERSION: string; diff --git a/src/plugins/arRPC.web/index.tsx b/src/plugins/arRPC.web/index.tsx index 423dce9b5..e41e8675e 100644 --- a/src/plugins/arRPC.web/index.tsx +++ b/src/plugins/arRPC.web/index.tsx @@ -19,7 +19,7 @@ import { popNotice, showNotice } from "@api/Notices"; import { Link } from "@components/Link"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import definePlugin, { ReporterTestable } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { ApplicationAssetUtils, FluxDispatcher, Forms, Toasts } from "@webpack/common"; @@ -41,6 +41,7 @@ export default definePlugin({ name: "WebRichPresence (arRPC)", description: "Client plugin for arRPC to enable RPC on Discord Web (experimental)", authors: [Devs.Ducko], + reporterTestable: ReporterTestable.None, settingsAboutComponent: () => ( <> diff --git a/src/plugins/devCompanion.dev/index.tsx b/src/plugins/devCompanion.dev/index.tsx index 25fd563e4..a495907b2 100644 --- a/src/plugins/devCompanion.dev/index.tsx +++ b/src/plugins/devCompanion.dev/index.tsx @@ -21,7 +21,7 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { filters, findAll, search } from "@webpack"; const PORT = 8485; @@ -243,6 +243,7 @@ export default definePlugin({ name: "DevCompanion", description: "Dev Companion Plugin", authors: [Devs.Ven], + reporterTestable: ReporterTestable.None, settings, toolboxActions: { diff --git a/src/plugins/index.ts b/src/plugins/index.ts index a434b4a6f..53ab7983a 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -21,7 +21,7 @@ import { addContextMenuPatch, removeContextMenuPatch } from "@api/ContextMenu"; import { Settings } from "@api/Settings"; import { Logger } from "@utils/Logger"; import { canonicalizeFind } from "@utils/patches"; -import { Patch, Plugin, StartAt } from "@utils/types"; +import { Patch, Plugin, ReporterTestable, StartAt } from "@utils/types"; import { FluxDispatcher } from "@webpack/common"; import { FluxEvents } from "@webpack/types"; @@ -39,35 +39,68 @@ export const patches = [] as Patch[]; let enabledPluginsSubscribedFlux = false; const subscribedFluxEventsPlugins = new Set(); +const pluginsValues = Object.values(Plugins); const settings = Settings.plugins; export function isPluginEnabled(p: string) { return ( + IS_REPORTER || Plugins[p]?.required || Plugins[p]?.isDependency || settings[p]?.enabled ) ?? false; } -const pluginsValues = Object.values(Plugins); +export function addPatch(newPatch: Omit, pluginName: string) { + const patch = newPatch as Patch; + patch.plugin = pluginName; -// First roundtrip to mark and force enable dependencies (only for enabled plugins) + if (IS_REPORTER) { + delete patch.predicate; + delete patch.group; + } + + canonicalizeFind(patch); + if (!Array.isArray(patch.replacement)) { + patch.replacement = [patch.replacement]; + } + + if (IS_REPORTER) { + patch.replacement.forEach(r => { + delete r.predicate; + }); + } + + patches.push(patch); +} + +function isReporterTestable(p: Plugin, part: ReporterTestable) { + return p.reporterTestable == null + ? true + : (p.reporterTestable & part) === part; +} + +// First round-trip to mark and force enable dependencies // // FIXME: might need to revisit this if there's ever nested (dependencies of dependencies) dependencies since this only // goes for the top level and their children, but for now this works okay with the current API plugins -for (const p of pluginsValues) if (settings[p.name]?.enabled) { +for (const p of pluginsValues) if (isPluginEnabled(p.name)) { p.dependencies?.forEach(d => { const dep = Plugins[d]; - if (dep) { - settings[d].enabled = true; - dep.isDependency = true; - } - else { + + if (!dep) { const error = new Error(`Plugin ${p.name} has unresolved dependency ${d}`); - if (IS_DEV) + + if (IS_DEV) { throw error; + } + logger.warn(error); + return; } + + settings[d].enabled = true; + dep.isDependency = true; }); } @@ -82,23 +115,18 @@ for (const p of pluginsValues) { } if (p.patches && isPluginEnabled(p.name)) { - for (const patch of p.patches) { - patch.plugin = p.name; - - canonicalizeFind(patch); - if (!Array.isArray(patch.replacement)) { - patch.replacement = [patch.replacement]; + if (!IS_REPORTER || isReporterTestable(p, ReporterTestable.Patches)) { + for (const patch of p.patches) { + addPatch(patch, p.name); } - - patches.push(patch); } } } export const startAllPlugins = traceFunction("startAllPlugins", function startAllPlugins(target: StartAt) { logger.info(`Starting plugins (stage ${target})`); - for (const name in Plugins) - if (isPluginEnabled(name)) { + for (const name in Plugins) { + if (isPluginEnabled(name) && (!IS_REPORTER || isReporterTestable(Plugins[name], ReporterTestable.Start))) { const p = Plugins[name]; const startAt = p.startAt ?? StartAt.WebpackReady; @@ -106,30 +134,38 @@ export const startAllPlugins = traceFunction("startAllPlugins", function startAl startPlugin(Plugins[name]); } + } }); export function startDependenciesRecursive(p: Plugin) { let restartNeeded = false; const failures: string[] = []; - p.dependencies?.forEach(dep => { - if (!Settings.plugins[dep].enabled) { - startDependenciesRecursive(Plugins[dep]); + + p.dependencies?.forEach(d => { + if (!settings[d].enabled) { + const dep = Plugins[d]; + startDependenciesRecursive(dep); + // If the plugin has patches, don't start the plugin, just enable it. - Settings.plugins[dep].enabled = true; - if (Plugins[dep].patches) { - logger.warn(`Enabling dependency ${dep} requires restart.`); + settings[d].enabled = true; + dep.isDependency = true; + + if (dep.patches) { + logger.warn(`Enabling dependency ${d} requires restart.`); restartNeeded = true; return; } - const result = startPlugin(Plugins[dep]); - if (!result) failures.push(dep); + + const result = startPlugin(dep); + if (!result) failures.push(d); } }); + return { restartNeeded, failures }; } export function subscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof FluxDispatcher) { - if (p.flux && !subscribedFluxEventsPlugins.has(p.name)) { + if (p.flux && !subscribedFluxEventsPlugins.has(p.name) && (!IS_REPORTER || isReporterTestable(p, ReporterTestable.FluxEvents))) { subscribedFluxEventsPlugins.add(p.name); logger.debug("Subscribing to flux events of plugin", p.name); diff --git a/src/plugins/invisibleChat.desktop/index.tsx b/src/plugins/invisibleChat.desktop/index.tsx index 884ffafe3..01199d999 100644 --- a/src/plugins/invisibleChat.desktop/index.tsx +++ b/src/plugins/invisibleChat.desktop/index.tsx @@ -23,7 +23,7 @@ import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { getStegCloak } from "@utils/dependencies"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { ChannelStore, Constants, RestAPI, Tooltip } from "@webpack/common"; import { Message } from "discord-types/general"; @@ -105,6 +105,9 @@ export default definePlugin({ description: "Encrypt your Messages in a non-suspicious way!", authors: [Devs.SammCheese], dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI", "MessageUpdaterAPI"], + reporterTestable: ReporterTestable.Patches, + settings, + patches: [ { // Indicator @@ -121,7 +124,6 @@ export default definePlugin({ URL_REGEX: new RegExp( /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, ), - settings, async start() { addButton("InvisibleChat", message => { return this.INV_REGEX.test(message?.content) diff --git a/src/plugins/shikiCodeblocks.desktop/index.ts b/src/plugins/shikiCodeblocks.desktop/index.ts index 27463195d..e6676a866 100644 --- a/src/plugins/shikiCodeblocks.desktop/index.ts +++ b/src/plugins/shikiCodeblocks.desktop/index.ts @@ -20,7 +20,7 @@ import "./shiki.css"; import { enableStyle } from "@api/Styles"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import definePlugin, { ReporterTestable } from "@utils/types"; import previewExampleText from "file://previewExample.tsx"; import { shiki } from "./api/shiki"; @@ -34,6 +34,9 @@ export default definePlugin({ name: "ShikiCodeblocks", description: "Brings vscode-style codeblocks into Discord, powered by Shiki", authors: [Devs.Vap], + reporterTestable: ReporterTestable.Patches, + settings, + patches: [ { find: "codeBlock:{react(", @@ -66,7 +69,6 @@ export default definePlugin({ isPreview: true, tempSettings, }), - settings, // exports shiki, diff --git a/src/plugins/vcNarrator/index.tsx b/src/plugins/vcNarrator/index.tsx index ac629e749..6e8e4bbf5 100644 --- a/src/plugins/vcNarrator/index.tsx +++ b/src/plugins/vcNarrator/index.tsx @@ -22,7 +22,7 @@ import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; import { wordsToTitle } from "@utils/text"; -import definePlugin, { OptionType, PluginOptionsItem } from "@utils/types"; +import definePlugin, { OptionType, PluginOptionsItem, ReporterTestable } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { Button, ChannelStore, Forms, GuildMemberStore, SelectedChannelStore, SelectedGuildStore, useMemo, UserStore } from "@webpack/common"; @@ -155,6 +155,7 @@ export default definePlugin({ name: "VcNarrator", description: "Announces when users join, leave, or move voice channels via narrator", authors: [Devs.Ven], + reporterTestable: ReporterTestable.None, flux: { VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) { diff --git a/src/plugins/xsOverlay.desktop/index.ts b/src/plugins/xsOverlay.desktop/index.ts index 5251959f2..caa44a40c 100644 --- a/src/plugins/xsOverlay.desktop/index.ts +++ b/src/plugins/xsOverlay.desktop/index.ts @@ -8,7 +8,7 @@ import { definePluginSettings } from "@api/Settings"; import { makeRange } from "@components/PluginSettings/components"; import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; -import definePlugin, { OptionType, PluginNative } from "@utils/types"; +import definePlugin, { OptionType, PluginNative, ReporterTestable } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { ChannelStore, GuildStore, UserStore } from "@webpack/common"; import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general"; @@ -143,7 +143,9 @@ export default definePlugin({ description: "Forwards discord notifications to XSOverlay, for easy viewing in VR", authors: [Devs.Nyako], tags: ["vr", "notify"], + reporterTestable: ReporterTestable.None, settings, + flux: { CALL_UPDATE({ call }: { call: Call; }) { if (call?.ringing?.includes(UserStore.getCurrentUser().id) && settings.store.callNotifications) { diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 1ae4762d7..e222d71fb 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -32,6 +32,11 @@ export class Logger { constructor(public name: string, public color: string = "white") { } private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") { + if (IS_REPORTER && (level === "warn" || level === "error")) { + console[level]("[Vencord]", this.name + ":", ...args); + return; + } + console[level]( `%c Vencord %c %c ${this.name} ${customFmt}`, `background: ${levelColor}; color: black; font-weight: bold; border-radius: 5px;`, diff --git a/src/utils/types.ts b/src/utils/types.ts index 6e1524196..fe19a1093 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -94,6 +94,10 @@ export interface PluginDef { * @default StartAt.WebpackReady */ startAt?: StartAt, + /** + * Which parts of the plugin can be tested by the reporter. Defaults to all parts + */ + reporterTestable?: number; /** * Optionally provide settings that the user can configure in the Plugins tab of settings. * @deprecated Use `settings` instead @@ -144,6 +148,13 @@ export const enum StartAt { WebpackReady = "WebpackReady" } +export const enum ReporterTestable { + None = 1 << 1, + Start = 1 << 2, + Patches = 1 << 3, + FluxEvents = 1 << 4 +} + export const enum OptionType { STRING, NUMBER, diff --git a/src/webpack/common/internal.tsx b/src/webpack/common/internal.tsx index 9a89af362..8957c254b 100644 --- a/src/webpack/common/internal.tsx +++ b/src/webpack/common/internal.tsx @@ -22,7 +22,7 @@ import { LazyComponent } from "@utils/react"; import { FilterFn, filters, lazyWebpackSearchHistory, waitFor } from "../webpack"; export function waitForComponent = React.ComponentType & Record>(name: string, filter: FilterFn | string | string[]): T { - if (IS_DEV) lazyWebpackSearchHistory.push(["waitForComponent", Array.isArray(filter) ? filter : [filter]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["waitForComponent", Array.isArray(filter) ? filter : [filter]]); let myValue: T = function () { throw new Error(`Vencord could not find the ${name} Component`); @@ -38,7 +38,7 @@ export function waitForComponent = React.Comp } export function waitForStore(name: string, cb: (v: any) => void) { - if (IS_DEV) lazyWebpackSearchHistory.push(["waitForStore", [name]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["waitForStore", [name]]); waitFor(filters.byStoreName(name), cb, { isIndirect: true }); } diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 9e0c0d000..ec7218c64 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -264,7 +264,7 @@ export const lazyWebpackSearchHistory = [] as Array<["find" | "findByProps" | "f * @example const mod = proxyLazy(() => findByProps("blah")); console.log(mod.blah); */ export function proxyLazyWebpack(factory: () => any, attempts?: number) { - if (IS_DEV) lazyWebpackSearchHistory.push(["proxyLazyWebpack", [factory]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["proxyLazyWebpack", [factory]]); return proxyLazy(factory, attempts); } @@ -278,7 +278,7 @@ export function proxyLazyWebpack(factory: () => any, attempts?: number) * @returns Result of factory function */ export function LazyComponentWebpack(factory: () => any, attempts?: number) { - if (IS_DEV) lazyWebpackSearchHistory.push(["LazyComponentWebpack", [factory]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["LazyComponentWebpack", [factory]]); return LazyComponent(factory, attempts); } @@ -287,7 +287,7 @@ export function LazyComponentWebpack(factory: () => any, * Find the first module that matches the filter, lazily */ export function findLazy(filter: FilterFn) { - if (IS_DEV) lazyWebpackSearchHistory.push(["find", [filter]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["find", [filter]]); return proxyLazy(() => find(filter)); } @@ -306,7 +306,7 @@ export function findByProps(...props: string[]) { * Find the first module that has the specified properties, lazily */ export function findByPropsLazy(...props: string[]) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findByProps", props]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByProps", props]); return proxyLazy(() => findByProps(...props)); } @@ -325,7 +325,7 @@ export function findByCode(...code: string[]) { * Find the first function that includes all the given code, lazily */ export function findByCodeLazy(...code: string[]) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findByCode", code]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByCode", code]); return proxyLazy(() => findByCode(...code)); } @@ -344,7 +344,7 @@ export function findStore(name: string) { * Find a store by its displayName, lazily */ export function findStoreLazy(name: string) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findStore", [name]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findStore", [name]]); return proxyLazy(() => findStore(name)); } @@ -363,7 +363,7 @@ export function findComponentByCode(...code: string[]) { * Finds the first component that matches the filter, lazily. */ export function findComponentLazy(filter: FilterFn) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findComponent", [filter]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findComponent", [filter]]); return LazyComponent(() => { @@ -378,7 +378,7 @@ export function findComponentLazy(filter: FilterFn) { * Finds the first component that includes all the given code, lazily */ export function findComponentByCodeLazy(...code: string[]) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findComponentByCode", code]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findComponentByCode", code]); return LazyComponent(() => { const res = find(filters.componentByCode(...code), { isIndirect: true }); @@ -392,7 +392,7 @@ export function findComponentByCodeLazy(...code: string[ * Finds the first component that is exported by the first prop name, lazily */ export function findExportedComponentLazy(...props: string[]) { - if (IS_DEV) lazyWebpackSearchHistory.push(["findExportedComponent", props]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["findExportedComponent", props]); return LazyComponent(() => { const res = find(filters.byProps(...props), { isIndirect: true }); @@ -477,7 +477,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def * @returns A function that returns a promise that resolves with a boolean whether the chunks were loaded, on first call */ export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtractAndLoadChunksRegex) { - if (IS_DEV) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]); + if (IS_REPORTER) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]); return makeLazy(() => extractAndLoadChunks(code, matcher)); } @@ -487,7 +487,7 @@ export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtrac * then call the callback with the module as the first argument */ export function waitFor(filter: string | string[] | FilterFn, callback: CallbackFn, { isIndirect = false }: { isIndirect?: boolean; } = {}) { - if (IS_DEV && !isIndirect) lazyWebpackSearchHistory.push(["waitFor", Array.isArray(filter) ? filter : [filter]]); + if (IS_REPORTER && !isIndirect) lazyWebpackSearchHistory.push(["waitFor", Array.isArray(filter) ? filter : [filter]]); if (typeof filter === "string") filter = filters.byProps(filter); From 249ea309952780fa89696c9f0fe7a51780070995 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:10:29 -0400 Subject: [PATCH 073/100] holy shit since when coild READMEs look this good Co-authored-by: vee --- src/plugins/WebhookManager/README.MD | 42 +++++++++++----------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/WebhookManager/README.MD index b334f7ec9..6ca49a7f6 100644 --- a/src/plugins/WebhookManager/README.MD +++ b/src/plugins/WebhookManager/README.MD @@ -1,31 +1,21 @@ # WebhookManager - Manage your webhooks easily; delete, send messages, get detailed info and more. +Manage your webhooks easily; delete, send messages, get detailed info and more. +## Commands - ## Commands - - /webhook send - *Sends a message through a webhook.* +- /webhook send - *Sends a message through a webhook.* +- /webhook delete - *Deletes any webhook that is specified.* +- /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it* +
+ Full /webhookinfo Output - - /webhook delete - *Deletes any webhook that is specified.* - - - - /webhook info - *Gets advanced details on the webhook such as the name, profile pic, server and channel ID, and additionally, information on person who created it* -
Full /webhookinfo Output - - - Webhook Username - - - Webhook ID - - - Webhook Token - - - Channel ID - - - Server ID - - - Webhook Profile Picture - - - Webhook Type - - - Creator Profile - -
+ - Webhook Username + - Webhook ID + - Webhook Token + - Channel ID + - Server ID + - Webhook Profile Picture + - Webhook Type + - Creator Profile +
From 0df09f2aabd8263a6373d70de70e6c4d889fceaf Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Thu, 6 Jun 2024 08:33:15 -0400 Subject: [PATCH 074/100] blep small fix Co-authored-by: vee --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 86e603297..dceceb85f 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -128,7 +128,7 @@ export default definePlugin({ required: false } ], - execute: async (option, ctx) => { + async execute(option, ctx) { const webhookUrl = findOption(option, "url"); const webhookMessage = findOption(option, "message"); From 9ee1b5ba6e5353e63b3cafb3a9351794bac39ee9 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:01:46 -0400 Subject: [PATCH 075/100] Update src/plugins/WebhookManager/index.tsx Co-authored-by: vee --- src/plugins/WebhookManager/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index dceceb85f..42c94d48b 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -146,7 +146,7 @@ export default definePlugin({ if (webhookProfilePic === "") webhookProfilePic = undefined; - Native.executeWebhook("" + webhookUrl, { + Native.executeWebhook(webhookUrl, { content: webhookMessage, username: webhookUsername, avatar_url: webhookProfilePic, From d7036c5886c0459aed13f8fd2085b9170e00c180 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:02:24 -0400 Subject: [PATCH 076/100] shorter lines Co-authored-by: vee --- src/plugins/WebhookManager/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/WebhookManager/index.tsx index 42c94d48b..1c9d0e3ca 100644 --- a/src/plugins/WebhookManager/index.tsx +++ b/src/plugins/WebhookManager/index.tsx @@ -32,7 +32,12 @@ export default definePlugin({ ], execute: async (option, ctx) => { try { - await fetch("" + findOption(option, "url"), { method: "DELETE" }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." })); + await fetch(findOption(option, "url"), { + method: "DELETE" + }); + sendBotMessage(ctx.channel.id, { + content: "The webhook has deleted successfully." + }); } catch (error) { sendBotMessage(ctx.channel.id, { From cafe4b19a294e662467b52787e338a223dab078d Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 03:29:39 +0200 Subject: [PATCH 077/100] fix folder name --- src/plugins/{WebhookManager => webhookManager}/README.MD | 0 src/plugins/{WebhookManager => webhookManager}/index.tsx | 0 src/plugins/{WebhookManager => webhookManager}/native.ts | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{WebhookManager => webhookManager}/README.MD (100%) rename src/plugins/{WebhookManager => webhookManager}/index.tsx (100%) rename src/plugins/{WebhookManager => webhookManager}/native.ts (100%) diff --git a/src/plugins/WebhookManager/README.MD b/src/plugins/webhookManager/README.MD similarity index 100% rename from src/plugins/WebhookManager/README.MD rename to src/plugins/webhookManager/README.MD diff --git a/src/plugins/WebhookManager/index.tsx b/src/plugins/webhookManager/index.tsx similarity index 100% rename from src/plugins/WebhookManager/index.tsx rename to src/plugins/webhookManager/index.tsx diff --git a/src/plugins/WebhookManager/native.ts b/src/plugins/webhookManager/native.ts similarity index 100% rename from src/plugins/WebhookManager/native.ts rename to src/plugins/webhookManager/native.ts From b3a9d33411217b2bdb625c50615e63fe6d85d416 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 03:37:24 +0200 Subject: [PATCH 078/100] clean up --- src/plugins/webhookManager/index.tsx | 108 +++++++++++++-------------- src/plugins/webhookManager/native.ts | 7 +- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/plugins/webhookManager/index.tsx b/src/plugins/webhookManager/index.tsx index 1c9d0e3ca..2bc381b36 100644 --- a/src/plugins/webhookManager/index.tsx +++ b/src/plugins/webhookManager/index.tsx @@ -6,11 +6,9 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import { Logger } from "@utils/Logger"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; -const WMLogger = new Logger("WebhookManager"); export default definePlugin({ name: "WebhookManager", @@ -32,12 +30,12 @@ export default definePlugin({ ], execute: async (option, ctx) => { try { - await fetch(findOption(option, "url"), { - method: "DELETE" - }); + await fetch(findOption(option, "url", ""), { + method: "DELETE" + }); sendBotMessage(ctx.channel.id, { - content: "The webhook has deleted successfully." - }); + content: "The webhook has deleted successfully." + }); } catch (error) { sendBotMessage(ctx.channel.id, { @@ -59,36 +57,37 @@ export default definePlugin({ } ], execute: async (option, ctx) => { - const webhookUrl = findOption(option, "url"); - await fetch("" + webhookUrl).then(response => response.json()) - .then(response => { - WMLogger.info(JSON.stringify(response)); - sendBotMessage(ctx.channel.id, { - content: `This webhook was created by ${response.user?.name}.`, - embeds: [ - { - title: "Webhook Information", - color: "1323", - // @ts-ignore - author: { - name: response.name, - url: "" - }, - thumbnail: { - url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, - proxyURL: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, - height: 128, - width: 128 - }, - description: ` - Webhook ID: ${response.id} - Webhook Token: ${response.token} - Webhook Type: ${response.type} - Channel ID: ${response.channel_id} - Server ID: ${response.guild_id}` - }] - }); - }); + const webhookUrl = findOption(option, "url", ""); + const { user, avatar, name, id, token, type, channel_id, guild_id } + = await fetch(webhookUrl).then(res => res.json()); + + sendBotMessage(ctx.channel.id, { + content: `This webhook was created by ${user?.name}.`, + embeds: [ + { + title: "Webhook Information", + color: "1323", + // @ts-ignore + author: { + name, + url: "" + }, + thumbnail: { + url: `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`, + proxyURL: `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`, + height: 128, + width: 128 + }, + description: ` + Webhook ID: ${id} + Webhook Token: ${token} + Webhook Type: ${type} + Channel ID: ${channel_id} + Server ID: ${guild_id} + ` + } + ] + }); } }, { @@ -103,8 +102,8 @@ export default definePlugin({ required: true }, { - name: "message", - description: "The message you want to send", + name: "content", + description: "The message content you want to send", type: ApplicationCommandOptionType.STRING, required: true }, @@ -121,7 +120,7 @@ export default definePlugin({ required: false }, { - name: "pfp", + name: "avatar-url", description: "Send with a custom profile picture. You must input a valid image URL.", type: ApplicationCommandOptionType.STRING, required: false @@ -134,27 +133,20 @@ export default definePlugin({ } ], async execute(option, ctx) { + const webhookUrl = findOption(option, "url", ""); + const content = findOption(option, "content", ""); + const avatarUrl = findOption(option, "avatar-url"); + const username = findOption(option, "username"); - const webhookUrl = findOption(option, "url"); - const webhookMessage = findOption(option, "message"); - let webhookProfilePic = findOption(option, "pfp"); - let webhookUsername = findOption(option, "username"); if (findOption(option, "raw")) { - Native.executeWebhook("" + webhookUrl, { - webhookMessage - }); - } - else { - if (webhookUsername === "") - webhookUsername = undefined; - - if (webhookProfilePic === "") - webhookProfilePic = undefined; - Native.executeWebhook(webhookUrl, { - content: webhookMessage, - username: webhookUsername, - avatar_url: webhookProfilePic, + webhookMessage: content + }); + } else { + Native.executeWebhook(webhookUrl, { + content: content, + username: username, + avatar_url: avatarUrl, tts: findOption(option, "tts"), }); } diff --git a/src/plugins/webhookManager/native.ts b/src/plugins/webhookManager/native.ts index 05b5beab8..f400029ff 100644 --- a/src/plugins/webhookManager/native.ts +++ b/src/plugins/webhookManager/native.ts @@ -4,12 +4,15 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +import { IpcMainInvokeEvent } from "electron"; import https from "https"; -export function executeWebhook(_, url: string, body: object) { +const DiscordHosts = new Set(["discord.com", "ptb.discord.com", "canary.discord.com"]); + +export function executeWebhook(_event: IpcMainInvokeEvent, url: string, body: object) { const { hostname, pathname } = new URL(url); - if (!["discord.com", "ptb.discord.com", "canary.discord.com"].includes(hostname) || !pathname.startsWith("/api/webhooks/")) { + if (!DiscordHosts.has(hostname) || !pathname.startsWith("/api/webhooks/")) { throw new Error("This URL is not a valid webhook."); } From 61eacb2106a49e803401f895cfe6a984f4820e4e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 03:38:31 +0200 Subject: [PATCH 079/100] fix folder name part 2 --- src/plugins/{webhookManager => webhookManager.desktop}/README.MD | 0 src/plugins/{webhookManager => webhookManager.desktop}/index.tsx | 0 src/plugins/{webhookManager => webhookManager.desktop}/native.ts | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{webhookManager => webhookManager.desktop}/README.MD (100%) rename src/plugins/{webhookManager => webhookManager.desktop}/index.tsx (100%) rename src/plugins/{webhookManager => webhookManager.desktop}/native.ts (100%) diff --git a/src/plugins/webhookManager/README.MD b/src/plugins/webhookManager.desktop/README.MD similarity index 100% rename from src/plugins/webhookManager/README.MD rename to src/plugins/webhookManager.desktop/README.MD diff --git a/src/plugins/webhookManager/index.tsx b/src/plugins/webhookManager.desktop/index.tsx similarity index 100% rename from src/plugins/webhookManager/index.tsx rename to src/plugins/webhookManager.desktop/index.tsx diff --git a/src/plugins/webhookManager/native.ts b/src/plugins/webhookManager.desktop/native.ts similarity index 100% rename from src/plugins/webhookManager/native.ts rename to src/plugins/webhookManager.desktop/native.ts From ae10deaee409989caa3a3582deec3efa19fb6a7c Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 03:41:45 +0200 Subject: [PATCH 080/100] fix --- src/webpack/common/stores.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index 5273df30b..123c62b05 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -16,11 +16,10 @@ * along with this program. If not, see . */ -import { proxyLazy } from "@utils/lazy"; import type * as Stores from "discord-types/stores"; // eslint-disable-next-line path-alias/no-relative -import { findByProps, findByPropsLazy } from "../webpack"; +import { findByPropsLazy } from "../webpack"; import { waitForStore } from "./internal"; import * as t from "./types/stores"; @@ -67,13 +66,8 @@ export let DraftStore: t.DraftStore; * * @example const user = useStateFromStores([UserStore], () => UserStore.getCurrentUser(), null, (old, current) => old.id === current.id); */ - -export const useStateFromStores = proxyLazy(() => findByProps("useStateFromStores").useStateFromStores) as ( - stores: t.FluxStore[], - mapper: () => T, - dependencies?: any, - isEqual?: (old: T, newer: T) => boolean -) => T; +// eslint-disable-next-line prefer-destructuring +export const useStateFromStores: t.useStateFromStores = findByPropsLazy("useStateFromStores").useStateFromStores; waitForStore("DraftStore", s => DraftStore = s); waitForStore("UserStore", s => UserStore = s); From bc3093a41e4ed5f1ea3384a4ee1d54a70889d41c Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:25:55 -0400 Subject: [PATCH 081/100] removed tts thing because i think most people have tts muted anyways and also too much to add also small fixes --- src/plugins/webhookManager.desktop/index.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 2bc381b36..2962e7f56 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -113,12 +113,6 @@ export default definePlugin({ type: ApplicationCommandOptionType.STRING, required: false }, - { - name: "tts", - description: "Send with TTS", - type: ApplicationCommandOptionType.BOOLEAN, - required: false - }, { name: "avatar-url", description: "Send with a custom profile picture. You must input a valid image URL.", @@ -127,7 +121,7 @@ export default definePlugin({ }, { name: "raw", - description: "Send message as raw JSON", + description: "Send message as raw JSON.", type: ApplicationCommandOptionType.BOOLEAN, required: false } From 90c9dd20bbd6cc74a6f1599548114fde1d03a1d4 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:27:39 -0400 Subject: [PATCH 082/100] change name in constants --- src/plugins/webhookManager.desktop/index.tsx | 2 +- src/utils/constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 2962e7f56..68955da7b 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -13,7 +13,7 @@ const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative Date: Mon, 10 Jun 2024 09:37:37 -0400 Subject: [PATCH 083/100] fix: small bug with webhook execution & added vee to devs because they helped a lot (tysm) --- src/plugins/webhookManager.desktop/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 68955da7b..8b9b8eb3d 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -13,7 +13,7 @@ const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative Date: Mon, 10 Jun 2024 09:47:50 -0400 Subject: [PATCH 084/100] todo: add modal --- src/plugins/webhookManager.desktop/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 8b9b8eb3d..e7bfb8e3b 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -5,11 +5,23 @@ */ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; +import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import { Devs } from "@utils/constants"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; +// TODO: Create Modal +function webhookMessageModal(props: ModalProps) { + return ( + + {...props} + size={ModalSize.MEDIUM} + + ); +} + + export default definePlugin({ name: "WebhookManager", description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", From 2721cd3d4735b49034fed796b4c591efbabe703c Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:49:48 -0400 Subject: [PATCH 085/100] fix lint breaking --- src/plugins/webhookManager.desktop/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index e7bfb8e3b..558034b26 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -5,7 +5,7 @@ */ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; -import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; +import { ModalRoot, ModalSize } from "@utils/modal"; import { Devs } from "@utils/constants"; import definePlugin, { PluginNative } from "@utils/types"; From fc3618628faf81faad04848d52e45764479849ce Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:48:41 -0400 Subject: [PATCH 086/100] fix: lint and code error with modal template --- src/plugins/webhookManager.desktop/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 558034b26..7f7cb30f4 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -5,18 +5,19 @@ */ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; -import { ModalRoot, ModalSize } from "@utils/modal"; import { Devs } from "@utils/constants"; +import { ModalRoot, ModalSize } from "@utils/modal"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; -// TODO: Create Modal +// TODO: Create Modal and add stuff function webhookMessageModal(props: ModalProps) { return ( - - {...props} - size={ModalSize.MEDIUM} + + + + ); } From c0842cb84c20642361d0184dabd7e382f85983a2 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:49:57 -0400 Subject: [PATCH 087/100] forgot imports! --- src/plugins/webhookManager.desktop/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 7f7cb30f4..19e7e695e 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -6,7 +6,7 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import { ModalRoot, ModalSize } from "@utils/modal"; +import { ModalRoot, ModalSize, ModalProps, ModalContent } from "@utils/modal"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; From 9ad6e1b3a2cf15bcb80e67e542151cad62567744 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:51:19 -0400 Subject: [PATCH 088/100] ??????? --- src/plugins/webhookManager.desktop/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 19e7e695e..08fa361de 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -6,8 +6,8 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import { ModalRoot, ModalSize, ModalProps, ModalContent } from "@utils/modal"; import definePlugin, { PluginNative } from "@utils/types"; +import { ModalRoot, ModalSize, ModalProps, ModalContent } from "@utils/modal"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; From 56be5eb24770caad49b37c36262ec9db6a9cc3b4 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:53:06 -0400 Subject: [PATCH 089/100] i swear to god if this doesnt fix it --- src/plugins/webhookManager.desktop/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 08fa361de..4640a320d 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -7,7 +7,7 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; import definePlugin, { PluginNative } from "@utils/types"; -import { ModalRoot, ModalSize, ModalProps, ModalContent } from "@utils/modal"; +import { ModalContent, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; From 588a40c43f9c37e4026c658fe2aa46633d5791a4 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:53:58 -0400 Subject: [PATCH 090/100] fuck lint. --- src/plugins/webhookManager.desktop/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 4640a320d..487032f46 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -6,8 +6,8 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import definePlugin, { PluginNative } from "@utils/types"; import { ModalContent, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; +import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; From f84220eada92bfb8086f10a00ee4b077710bd038 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:35:08 -0400 Subject: [PATCH 091/100] feat: modal!! (still wip) --- src/plugins/webhookManager.desktop/index.tsx | 67 ++++++++++---------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 487032f46..976b541d1 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -6,20 +6,43 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import { ModalContent, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; +import { Margins } from "@utils/margins"; +import { ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal, openModalLazy } from "@utils/modal"; +import { Button, Forms, React, TextInput } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; // TODO: Create Modal and add stuff -function webhookMessageModal(props: ModalProps) { - return ( - - - - - - ); +function WebhookMessageModal(props: ModalProps) { + return + + Webhook Message + { + // content = value; + }} + /> + Webhook Username + { + // content = value; + }} + /> + Webhook Avatar URL + { + // content = value; + }} + /> + + + ; } @@ -113,30 +136,6 @@ export default definePlugin({ description: "The URL of the webhook", type: ApplicationCommandOptionType.STRING, required: true - }, - { - name: "content", - description: "The message content you want to send", - type: ApplicationCommandOptionType.STRING, - required: true - }, - { - name: "username", - description: "Send with a custom username", - type: ApplicationCommandOptionType.STRING, - required: false - }, - { - name: "avatar-url", - description: "Send with a custom profile picture. You must input a valid image URL.", - type: ApplicationCommandOptionType.STRING, - required: false - }, - { - name: "raw", - description: "Send message as raw JSON.", - type: ApplicationCommandOptionType.BOOLEAN, - required: false } ], async execute(option, ctx) { @@ -145,6 +144,8 @@ export default definePlugin({ const avatarUrl = findOption(option, "avatar-url"); const username = findOption(option, "username"); + openModal(props => ); + if (findOption(option, "raw")) { Native.executeWebhook(webhookUrl, { webhookMessage: content From 5180df743bb6170732d0b3d4c1e8ff412bfafbfe Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:46:10 -0400 Subject: [PATCH 092/100] todo: add finishing touches and fix bugs because webhooks arent sending rn --- src/plugins/webhookManager.desktop/index.tsx | 53 ++++++++------------ 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 976b541d1..ce219d897 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -7,39 +7,53 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; -import { ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal, openModalLazy } from "@utils/modal"; +import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { Button, Forms, React, TextInput } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; +let url, message, username, avatar_url = ""; -// TODO: Create Modal and add stuff +// TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) function WebhookMessageModal(props: ModalProps) { return + Webhook URL + { + v = url; + }} + /> Webhook Message { - // content = value; + v = message; }} /> Webhook Username { - // content = value; + v = username; }} /> Webhook Avatar URL { - // content = value; + v = avatar_url; }} /> ; @@ -130,33 +144,8 @@ export default definePlugin({ name: "webhook send", 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 - } - ], - async execute(option, ctx) { - const webhookUrl = findOption(option, "url", ""); - const content = findOption(option, "content", ""); - const avatarUrl = findOption(option, "avatar-url"); - const username = findOption(option, "username"); - + async execute(_, ctx) { openModal(props => ); - - if (findOption(option, "raw")) { - Native.executeWebhook(webhookUrl, { - webhookMessage: content - }); - } else { - Native.executeWebhook(webhookUrl, { - content: content, - username: username, - avatar_url: avatarUrl - }); - } sendBotMessage(ctx.channel.id, { content: "Your webhook message has been executed." }); From f045554bfe4b5edf368e800e8dae137497b53d0d Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:51:25 -0400 Subject: [PATCH 093/100] yay its undefined for some reason --- src/plugins/webhookManager.desktop/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index ce219d897..7c950a6e9 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -12,7 +12,7 @@ import { Button, Forms, React, TextInput } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; -let url, message, username, avatar_url = ""; +let url, message, username, avatarUrl = ""; // TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) function WebhookMessageModal(props: ModalProps) { @@ -23,6 +23,7 @@ function WebhookMessageModal(props: ModalProps) { placeholder={"https://discord.com/api/webhooks/1235349630980722698/QQv06cMyTurEIU8nQsZRQMKxdmnnN6FA8Eaa9zbDqGwqeeACx9UAS6CcnVt7B3v8r8t2"} onChange={v => { v = url; + console.log(url); // why the FUCK is it undefined. }} /> Webhook Message @@ -43,7 +44,7 @@ function WebhookMessageModal(props: ModalProps) { { - v = avatar_url; + v = avatarUrl; }} /> From c93f694faf7500ae85a742c62f27672ca118f472 Mon Sep 17 00:00:00 2001 From: byeoon <47872200+byeoon@users.noreply.github.com> Date: Tue, 11 Jun 2024 09:08:15 -0400 Subject: [PATCH 094/100] found switch / checkbox element --- src/plugins/webhookManager.desktop/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 7c950a6e9..a6c150059 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -8,7 +8,7 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; -import { Button, Forms, React, TextInput } from "@webpack/common"; +import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; @@ -26,6 +26,11 @@ function WebhookMessageModal(props: ModalProps) { console.log(url); // why the FUCK is it undefined. }} /> + { }} // maybe switch? don't use shitcode where i make an int and set it to 2 and then check if the int is 2 thats too much shitcode. + >Send as Raw JSON Webhook Message Date: Wed, 12 Jun 2024 17:32:49 -0400 Subject: [PATCH 095/100] test --- src/plugins/webhookManager.desktop/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index a6c150059..17b7e1bf7 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -13,6 +13,7 @@ import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; let url, message, username, avatarUrl = ""; +let jsonMode = false; // TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) function WebhookMessageModal(props: ModalProps) { @@ -26,11 +27,6 @@ function WebhookMessageModal(props: ModalProps) { console.log(url); // why the FUCK is it undefined. }} /> - { }} // maybe switch? don't use shitcode where i make an int and set it to 2 and then check if the int is 2 thats too much shitcode. - >Send as Raw JSON Webhook Message + { + v = jsonMode; + console.log("hi"); + }} // maybe switch? don't use shitcode where i make an int and set it to 2 and then check if the int is 2 thats too much shitcode. + >Send as Raw JSON Webhook Username Date: Fri, 21 Jun 2024 20:11:30 -0400 Subject: [PATCH 096/100] YAY this should work!! --- src/plugins/webhookManager.desktop/index.tsx | 46 ++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 17b7e1bf7..82e70da16 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -8,31 +8,35 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; -import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; +import { Button, Forms, React, Switch, TextInput, useState } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; let url, message, username, avatarUrl = ""; let jsonMode = false; +const [params, setParams] = useState({ content: "", username: "", avatarUrl: "", url: "" }); + +const onURL = (content: string) => setParams(prev => ({ ...prev, url })); +const onContent = (content: string) => setParams(prev => ({ ...prev, content })); +const onUsername = (username: string) => setParams(prev => ({ ...prev, username })); +const onAvatar = (avatarUrl: string) => setParams(prev => ({ ...prev, avatarUrl })); + // TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) function WebhookMessageModal(props: ModalProps) { return Webhook URL { - v = url; - console.log(url); // why the FUCK is it undefined. - }} + placeholder={"Webhook URL"} + value={params.url} + onChange={onURL} /> Webhook Message { - v = message; - }} + placeholder={"Content"} + value={params.content} + onChange={onContent} /> Send as Raw JSON Webhook Username { - v = username; - }} + placeholder={"Username"} + value={params.username} + onChange={onUsername} /> Webhook Avatar URL { - v = avatarUrl; - }} + placeholder={"Image URL"} + value={params.avatarUrl} + onChange={onAvatar} /> From 5e52a34205005c254cf67477296278c3d1fc8dde Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 21 Jun 2024 20:31:05 -0400 Subject: [PATCH 097/100] hewlp vinneie vnecord no work --- src/plugins/webhookManager.desktop/index.tsx | 46 ++++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 82e70da16..17b7e1bf7 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -8,35 +8,31 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; -import { Button, Forms, React, Switch, TextInput, useState } from "@webpack/common"; +import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; let url, message, username, avatarUrl = ""; let jsonMode = false; -const [params, setParams] = useState({ content: "", username: "", avatarUrl: "", url: "" }); - -const onURL = (content: string) => setParams(prev => ({ ...prev, url })); -const onContent = (content: string) => setParams(prev => ({ ...prev, content })); -const onUsername = (username: string) => setParams(prev => ({ ...prev, username })); -const onAvatar = (avatarUrl: string) => setParams(prev => ({ ...prev, avatarUrl })); - // TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) function WebhookMessageModal(props: ModalProps) { return Webhook URL { + v = url; + console.log(url); // why the FUCK is it undefined. + }} /> Webhook Message { + v = message; + }} /> Send as Raw JSON Webhook Username { + v = username; + }} /> Webhook Avatar URL { + v = avatarUrl; + }} /> From ec4e97b1879f69de8cf86aa5a335c81883b94ba2 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:12:59 -0400 Subject: [PATCH 098/100] might fully work now!! --- src/plugins/webhookManager.desktop/index.tsx | 79 +++++++++++--------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 17b7e1bf7..36084de92 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -8,61 +8,70 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; -import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; +import { Button, Forms, React, Switch, TextInput, useState } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; -let url, message, username, avatarUrl = ""; +let url, content, username, avatarUrl = ""; let jsonMode = false; -// TODO: fix webhooks not sending, fix probable undefined when null issue, add sending as raw again (wanted to make it a checkbox but i cant find checkbox) +// TODO: add sending as raw function WebhookMessageModal(props: ModalProps) { + const [params, setParams] = useState({ content: "", username: "", avatarUrl: "", url: "", jsonMode: false }); + + const onURL = (url: string) => setParams(prev => ({ ...prev, url })); + const onContent = (content: string) => setParams(prev => ({ ...prev, content })); + const onUsername = (username: string) => setParams(prev => ({ ...prev, username })); + const onAvatar = (avatarUrl: string) => setParams(prev => ({ ...prev, avatarUrl })); + const onSwitch = (jsonMode: boolean) => setParams(prev => ({ ...prev, jsonMode })); + + return Webhook URL { - v = url; - console.log(url); // why the FUCK is it undefined. - }} + placeholder={"Webhook URL"} + value={params.url} + onChange={onURL} /> Webhook Message { - v = message; - }} + placeholder={"Content"} + value={params.content} + onChange={onContent} + /> + Webhook Username + + Webhook Avatar URL + { - v = jsonMode; - console.log("hi"); - }} // maybe switch? don't use shitcode where i make an int and set it to 2 and then check if the int is 2 thats too much shitcode. + onChange={onSwitch} >Send as Raw JSON - Webhook Username - { - v = username; - }} - /> - Webhook Avatar URL - { - v = avatarUrl; - }} - /> From 0561b3890ace265f4b5168c6b786b25f999efd38 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:16:05 -0400 Subject: [PATCH 099/100] fix thing no work --- src/plugins/webhookManager.desktop/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 36084de92..03f907440 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -68,7 +68,9 @@ function WebhookMessageModal(props: ModalProps) { } else { Native.executeWebhook(params.url, { - content: params.content + webhookMessage: params.content, + username: params.username, + avatar_url: params.avatarUrl }); } From cb4be3d77b64072d4337be1af2799baed13b3830 Mon Sep 17 00:00:00 2001 From: byron <47872200+byeoon@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:18:43 -0400 Subject: [PATCH 100/100] wtf lint --- src/plugins/webhookManager.desktop/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/webhookManager.desktop/index.tsx b/src/plugins/webhookManager.desktop/index.tsx index 03f907440..65540082b 100644 --- a/src/plugins/webhookManager.desktop/index.tsx +++ b/src/plugins/webhookManager.desktop/index.tsx @@ -8,8 +8,8 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; -import { Button, Forms, React, Switch, TextInput, useState } from "@webpack/common"; import definePlugin, { PluginNative } from "@utils/types"; +import { Button, Forms, React, Switch, TextInput, useState } from "@webpack/common"; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative; let url, content, username, avatarUrl = ""; @@ -59,7 +59,7 @@ function WebhookMessageModal(props: ModalProps) { >Send as Raw JSON