mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-19 22:20:34 +00:00
Finally did it, fixed the sending bug
This commit is contained in:
parent
278c4f0d60
commit
4f68631080
2 changed files with 49 additions and 23 deletions
|
@ -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, findOption, sendBotMessage } from "@api/Commands";
|
||||||
import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage, findOption } from "@api/Commands";
|
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin, { PluginNative } from "@utils/types";
|
||||||
import { RestAPI } from "@webpack/common";
|
import { RestAPI } from "@webpack/common";
|
||||||
|
|
||||||
export let webhookDefaultName;
|
export let webhookDefaultName;
|
||||||
|
@ -34,7 +36,7 @@ export default definePlugin({
|
||||||
execute: async (option, ctx) => {
|
execute: async (option, ctx) => {
|
||||||
const res = await RestAPI.delete({ url: "" + findOption(option, "url") });
|
const res = await RestAPI.delete({ url: "" + findOption(option, "url") });
|
||||||
try {
|
try {
|
||||||
if (res.ok == true) {
|
if (res.ok === true) {
|
||||||
sendBotMessage(ctx.channel.id, {
|
sendBotMessage(ctx.channel.id, {
|
||||||
content: "Webhook deleted successfully."
|
content: "Webhook deleted successfully."
|
||||||
});
|
});
|
||||||
|
@ -105,11 +107,21 @@ export default definePlugin({
|
||||||
type: ApplicationCommandOptionType.STRING,
|
type: ApplicationCommandOptionType.STRING,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
name: "username",
|
||||||
|
description: "Give the webhook a custom name (Leave blank for default).",
|
||||||
|
type: ApplicationCommandOptionType.STRING,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
],
|
],
|
||||||
execute: async (option, ctx) => {
|
execute: async (option, ctx) => {
|
||||||
|
|
||||||
var webhookUrl = findOption(option, "url");
|
var webhookUrl = findOption(option, "url");
|
||||||
var webhookMessage = findOption(option, "message");
|
var webhookMessage = findOption(option, "message");
|
||||||
|
// var webhookUsername = findOption(option, "username");
|
||||||
webhookUrlGLOBAL = webhookUrl;
|
webhookUrlGLOBAL = webhookUrl;
|
||||||
webhookMessageGLOBAL = webhookMessage;
|
webhookMessageGLOBAL = webhookMessage;
|
||||||
await fetch("" + webhookUrl).then(response => response.json())
|
await fetch("" + webhookUrl).then(response => response.json())
|
||||||
|
@ -117,13 +129,14 @@ export default definePlugin({
|
||||||
webhookDefaultName = response.name;
|
webhookDefaultName = response.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
Native.doSomething();
|
Native.executeWebhook("" + webhookUrl, {
|
||||||
|
content: webhookMessage,
|
||||||
|
username: webhookDefaultName,
|
||||||
|
avatar_url: ""
|
||||||
|
});
|
||||||
|
|
||||||
sendBotMessage(ctx.channel.id, {
|
sendBotMessage(ctx.channel.id, {
|
||||||
content: "Message sent.?"
|
content: "Message sent successfully."
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
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)
|
||||||
request.open("POST", "" + webhookUrlGLOBAL);
|
(thank you official vendicated vending machine 2024 real)
|
||||||
request.setRequestHeader('Content-type', 'application/json');
|
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,
|
export function executeWebhook(_, url: string, body: object) {
|
||||||
username: webhookDefaultName ?? "User",
|
const req = https.request(url,
|
||||||
avatar_url: ""
|
{
|
||||||
};
|
method: "POST",
|
||||||
request.send(JSON.stringify(params));
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.write(JSON.stringify(body));
|
||||||
|
req.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue