fix embed color not being blue, fix webhook profile picture not appearing, fix deleting webhooks not working, general code and QoL improvements

This commit is contained in:
byron 2024-05-01 18:02:14 -04:00
parent 6d704d603e
commit 28f70e2942
2 changed files with 11 additions and 24 deletions

View file

@ -8,7 +8,6 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption,
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import definePlugin, { PluginNative } from "@utils/types"; import definePlugin, { PluginNative } from "@utils/types";
import { RestAPI } from "@webpack/common";
const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative<typeof import("./native")>; const Native = VencordNative.pluginHelpers.WebhookManager as PluginNative<typeof import("./native")>;
const WMLogger = new Logger("WebhookManager"); const WMLogger = new Logger("WebhookManager");
@ -32,18 +31,8 @@ export default definePlugin({
} }
], ],
execute: async (option, ctx) => { execute: async (option, ctx) => {
const res = await RestAPI.delete({ url: "" + findOption(option, "url") });
try { try {
if (res.ok) { await fetch("" + findOption(option, "url"), { method: 'DELETE' }).then(() => sendBotMessage(ctx.channel.id, { content: "The webhook has deleted successfully." }));
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
});
}
} }
catch (error) { catch (error) {
sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
@ -70,18 +59,22 @@ export default definePlugin({
.then(response => { .then(response => {
WMLogger.info(JSON.stringify(response)); WMLogger.info(JSON.stringify(response));
sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
content: `This webhook was created by <@${response.user.id}>.`, content: `This webhook was created by ${response.user?.name}.`,
embeds: [ embeds: [
{ {
// @ts-ignore
title: "Webhook Information", title: "Webhook Information",
color: "#00007d", color: "1323",
//@ts-ignore
author: { author: {
// @ts-ignore
icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`,
name: response.name, name: response.name,
url: "" 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: ` description: `
Webhook ID: ${response.id} Webhook ID: ${response.id}
Webhook Token: ${response.token} Webhook Token: ${response.token}

View file

@ -13,13 +13,7 @@ export function executeWebhook(_, url: string, body: object) {
throw new Error("This URL is not a valid webhook."); throw new Error("This URL is not a valid webhook.");
} }
const req = https.request(url, const req = https.request(url, { method: "POST", headers: { "Content-Type": "application/json", } });
{
method: "POST",
headers: {
"Content-Type": "application/json",
}
});
req.write(JSON.stringify(body)); req.write(JSON.stringify(body));
req.end(); req.end();
} }