removed unneeded / unreachable code, changed 'rawjson' to just 'raw', working on attachment sending as well

This commit is contained in:
byron 2024-03-15 21:18:53 -04:00
parent 8a09cb533b
commit 736fef879e

View file

@ -12,7 +12,6 @@ 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");
let sourceGuildGet;
export default definePlugin({ export default definePlugin({
name: "WebhookManager", name: "WebhookManager",
description: "Manage your webhooks easily; delete, send messages, get detailed info and more.", 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()) await fetch("" + webhookUrl).then(response => response.json())
.then(response => { .then(response => {
WMLogger.info(JSON.stringify(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, { sendBotMessage(ctx.channel.id, {
content: `This webhook was created by <@${response.user.id}>.`, content: `This webhook was created by <@${response.user.id}>.`,
embeds: [ embeds: [
@ -94,7 +81,6 @@ export default definePlugin({
author: { author: {
// @ts-ignore // @ts-ignore
icon_url: `https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.png`, 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, name: response.name,
url: "" url: ""
}, },
@ -103,10 +89,7 @@ export default definePlugin({
Webhook Token: ${response.token} Webhook Token: ${response.token}
Webhook Type: ${response.type} Webhook Type: ${response.type}
Channel ID: ${response.channel_id} Channel ID: ${response.channel_id}
Server ID: ${response.guild_id} Server ID: ${response.guild_id}`
${sourceGuildGet}
Creator UserID: ${response.user.id}`
}] }]
}); });
}); });
@ -142,7 +125,13 @@ export default definePlugin({
required: false 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", description: "Send message as raw JSON",
type: ApplicationCommandOptionType.BOOLEAN, type: ApplicationCommandOptionType.BOOLEAN,
required: false required: false
@ -153,13 +142,13 @@ export default definePlugin({
const webhookUrl = findOption(option, "url"); const webhookUrl = findOption(option, "url");
const webhookMessage = findOption(option, "message"); const webhookMessage = findOption(option, "message");
let webhookUsername = findOption(option, "username"); let webhookUsername = findOption(option, "username");
if (findOption(option, "rawjson")) { if (findOption(option, "raw")) {
Native.executeWebhook("" + webhookUrl, { Native.executeWebhook("" + webhookUrl, {
webhookMessage webhookMessage
}); });
} }
else { else {
fetch("" + webhookUrl).then(response => response.json().then(response => { if (webhookUsername === "") { webhookUsername = response.name; } })); webhookUsername = undefined;
Native.executeWebhook("" + webhookUrl, { Native.executeWebhook("" + webhookUrl, {
content: webhookMessage, content: webhookMessage,