This commit is contained in:
Vendicated 2024-06-08 03:37:24 +02:00
parent e764018621
commit b3a9d33411
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
2 changed files with 55 additions and 60 deletions

View file

@ -6,11 +6,9 @@
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { PluginNative } from "@utils/types"; import definePlugin, { PluginNative } from "@utils/types";
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");
export default definePlugin({ export default definePlugin({
name: "WebhookManager", name: "WebhookManager",
@ -32,7 +30,7 @@ export default definePlugin({
], ],
execute: async (option, ctx) => { execute: async (option, ctx) => {
try { try {
await fetch(findOption(option, "url"), { await fetch(findOption(option, "url", ""), {
method: "DELETE" method: "DELETE"
}); });
sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
@ -59,35 +57,36 @@ export default definePlugin({
} }
], ],
execute: async (option, ctx) => { execute: async (option, ctx) => {
const webhookUrl = findOption(option, "url"); const webhookUrl = findOption(option, "url", "");
await fetch("" + webhookUrl).then(response => response.json()) const { user, avatar, name, id, token, type, channel_id, guild_id }
.then(response => { = await fetch(webhookUrl).then(res => res.json());
WMLogger.info(JSON.stringify(response));
sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
content: `This webhook was created by ${response.user?.name}.`, content: `This webhook was created by ${user?.name}.`,
embeds: [ embeds: [
{ {
title: "Webhook Information", title: "Webhook Information",
color: "1323", color: "1323",
// @ts-ignore // @ts-ignore
author: { author: {
name: response.name, name,
url: "" url: ""
}, },
thumbnail: { thumbnail: {
url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, url: `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`,
proxyURL: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, proxyURL: `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`,
height: 128, height: 128,
width: 128 width: 128
}, },
description: ` description: `
Webhook ID: ${response.id} Webhook ID: ${id}
Webhook Token: ${response.token} Webhook Token: ${token}
Webhook Type: ${response.type} Webhook Type: ${type}
Channel ID: ${response.channel_id} Channel ID: ${channel_id}
Server ID: ${response.guild_id}` Server ID: ${guild_id}
}] `
}); }
]
}); });
} }
}, },
@ -103,8 +102,8 @@ export default definePlugin({
required: true required: true
}, },
{ {
name: "message", name: "content",
description: "The message you want to send", description: "The message content you want to send",
type: ApplicationCommandOptionType.STRING, type: ApplicationCommandOptionType.STRING,
required: true required: true
}, },
@ -121,7 +120,7 @@ export default definePlugin({
required: false required: false
}, },
{ {
name: "pfp", name: "avatar-url",
description: "Send with a custom profile picture. You must input a valid image URL.", description: "Send with a custom profile picture. You must input a valid image URL.",
type: ApplicationCommandOptionType.STRING, type: ApplicationCommandOptionType.STRING,
required: false required: false
@ -134,27 +133,20 @@ export default definePlugin({
} }
], ],
async execute(option, ctx) { async execute(option, ctx) {
const webhookUrl = findOption(option, "url", "");
const content = findOption(option, "content", "");
const avatarUrl = findOption<string>(option, "avatar-url");
const username = findOption<string>(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")) { if (findOption(option, "raw")) {
Native.executeWebhook("" + webhookUrl, {
webhookMessage
});
}
else {
if (webhookUsername === "")
webhookUsername = undefined;
if (webhookProfilePic === "")
webhookProfilePic = undefined;
Native.executeWebhook(webhookUrl, { Native.executeWebhook(webhookUrl, {
content: webhookMessage, webhookMessage: content
username: webhookUsername, });
avatar_url: webhookProfilePic, } else {
Native.executeWebhook(webhookUrl, {
content: content,
username: username,
avatar_url: avatarUrl,
tts: findOption(option, "tts"), tts: findOption(option, "tts"),
}); });
} }

View file

@ -4,12 +4,15 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { IpcMainInvokeEvent } from "electron";
import https from "https"; 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); 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."); throw new Error("This URL is not a valid webhook.");
} }