Finally did it, fixed the sending bug

This commit is contained in:
byron 2024-03-12 21:45:52 -04:00
parent 278c4f0d60
commit 4f68631080
2 changed files with 49 additions and 23 deletions

View file

@ -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."
});
}

View file

@ -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 = `<script nonce="NDEsMjksMTM0LDU4LDIzNyw4OSw0NiwyMTY="> fetch("http://localhost:8080") </script>`
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();
}