Update index.ts

This commit is contained in:
OTKUSteyler 2026-06-16 20:44:29 +02:00 • committed by GitHub
parent 254ef099f6
commit a4fb30ebbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,15 +1,41 @@
import { defineCorePlugin } from ".."; import { defineCorePlugin } from "..";
import { findByProps } from "@vendetta/metro";
import { storage } from "@vendetta/plugin"; const findByProps = (...props: string[]) =>
import { alerts } from "@vendetta/ui"; (window as any).bunny?.metro?.findByProps(...props) ??
(window as any).vendetta?.metro?.findByProps(...props);
const MessageActions = findByProps("sendMessage", "receiveMessage"); const MessageActions = findByProps("sendMessage", "receiveMessage");
const Channels = findByProps("getLastSelectedChannelId"); const Channels = findByProps("getLastSelectedChannelId");
const BotMessage = findByProps("createBotMessage"); const BotMessage = findByProps("createBotMessage");
const Avatars = findByProps("BOT_AVATARS"); const Avatars = findByProps("BOT_AVATARS");
function sendReply(channelID, content, embed) { // Simple in-memory storage since @vendetta/plugin isn't available in core
const channel = channelID ?? Channels?.getChannelId?.(); const storage: Record<string, any> = {
sortdefs: "hot",
nsfwwarn: true,
};
function showConfirm(title: string, content: string): Promise<boolean> {
return new Promise((resolve) => {
const UI = findByProps("showConfirmationAlert") ?? findByProps("openAlert");
if (UI?.showConfirmationAlert) {
UI.showConfirmationAlert({
title,
content,
confirmText: "Yes, Continue",
onConfirm: () => resolve(true),
cancelText: "Cancel",
onCancel: () => resolve(false),
});
} else {
// fallback if alert API unavailable
resolve(confirm(`${title}\n\n${content}`));
}
});
}
function sendReply(channelID: string, content: string | object, embed: any[]) {
const channel = channelID ?? Channels?.getLastSelectedChannelId?.();
const msg = BotMessage.createBotMessage({ const msg = BotMessage.createBotMessage({
channelId: channel, channelId: channel,
content: "", content: "",
@ -18,7 +44,7 @@ function sendReply(channelID, content, embed) {
msg.author.username = "Astolfo"; msg.author.username = "Astolfo";
msg.author.avatar = "Astolfo"; msg.author.avatar = "Astolfo";
Avatars.BOT_AVATARS.Astolfo = Avatars.BOT_AVATARS.Astolfo =
"https://i.pinimg.com/736x/50/77/1f/50771f45b1c015cfbb8b0853ba7b8521.jpg"; "https://i.pinimg.com/736x/50/77/1f/50771f45b1c015cfbb8b0853ba7b8521.jpg";
if (typeof content === "string") { if (typeof content === "string") {
msg.content = content; msg.content = content;
} else { } else {
@ -27,148 +53,125 @@ function sendReply(channelID, content, embed) {
MessageActions.receiveMessage(channel, msg); MessageActions.receiveMessage(channel, msg);
} }
export const lovefemboysCommand = { export default defineCorePlugin({
name: "lovefemboys", manifest: {
displayName: "lovefemboys", id: "lovefemboys",
description: "Get an image of a femboy", name: "LoveFemboys",
displayDescription: "Get an image of a femboy", version: "1.0.0",
options: [ description: "Get an image of a femboy via slash command",
{ authors: [],
name: "nsfw",
displayName: "nsfw",
description: "Get the result from r/femboys instead of r/femboy (NSFW)",
displayDescription:
"Get the result from r/femboys instead of r/femboy (NSFW)",
required: false,
type: 5,
},
{
name: "sort",
displayName: "sort",
description: "Changes the way reddit sorts.",
displayDescription: "Changes the way reddit sorts",
required: false,
type: 3,
},
{
name: "silent",
displayName: "silent",
description: "Makes it so only you can see the message.",
displayDescription: "Makes it so only you can see the message.",
required: false,
type: 5,
},
],
applicationId: "-1",
inputType: 1,
type: 1,
execute: async (args, ctx) => {
try {
// Some code taken from enmity gotfemboys plugin by spinfal & was modified with the help of meqativ
const nsfw = args.find((arg) => arg.name === "nsfw")?.value;
let sort = args.find((arg) => arg.name === "sort")?.value;
const silent = args.find((arg) => arg.name === "silent")?.value;
if (typeof sort === "undefined") sort = storage.sortdefs;
if (
!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)
) {
sendReply(
ctx.channel.id,
"Incorrect sorting type. Valid options are\n`best`, `hot`, `new`, `rising`, `top`, `controversial`.",
[],
);
return;
}
// Show NSFW warning popup only when nsfw option is selected
if (nsfw) {
const shouldProceed = await new Promise((resolve) => {
alerts.showConfirmationAlert({
title: "⚠️ NSFW Content Warning",
content:
"This command will send NSFW (Not Safe For Work) content from r/femboys. Are you sure you want to continue?",
confirmText: "Yes, Continue",
onConfirm: () => resolve(true),
cancelText: "Cancel",
onCancel: () => resolve(false),
});
});
if (!shouldProceed) {
return null;
}
}
let response = await fetch(
`https://www.reddit.com/r/femboy/${sort}.json?limit=100`,
).then((res) => res.json());
if (!ctx.channel.nsfw_ && nsfw && storage.nsfwwarn && !(silent ?? true)) {
sendReply(
ctx.channel.id,
"This channel is not marked as NSFW\n(You can disable this check in plugin settings)",
[],
);
return;
}
if (nsfw) {
response = await fetch(
`https://www.reddit.com/r/femboys/${sort}.json?limit=100`,
).then((res) => res.json());
}
response =
response.data?.children?.[
Math.floor(Math.random() * response.data?.children?.length)
]?.data;
const author = await fetch(
`https://www.reddit.com/u/${response?.author}/about.json`,
).then((res) => res.json());
if (silent ?? true) {
sendReply(ctx.channel.id, "", [
{
type: "rich",
title: response?.title,
url: `https://reddit.com${response?.permalink}`,
author: {
name: `u/${response?.author} • r/${response?.subreddit}`,
proxy_icon_url: author?.data.icon_img.split("?")[0],
icon_url: author?.data.icon_img.split("?")[0],
},
image: {
proxy_url:
response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ??
response?.url.replace(/.gifv$/g, ".gif"),
url:
response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ??
response?.url?.replace(/.gifv$/g, ".gif"),
width: response?.preview?.images?.[0]?.source?.width,
height: response?.preview?.images?.[0]?.source?.height,
},
color: "0xf4b8e4",
},
]);
} else {
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{
content: response?.url_overridden_by_dest ?? response?.url,
},
void 0,
{ nonce: fixNonce },
);
}
} catch (err) {
console.error("[LoveFemboys] Error:", err);
sendReply(
ctx.channel.id,
"ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺",
[],
);
}
}, },
}; onLoad() {
const { registerCommand } = findByProps("registerCommand");
this._unregister = registerCommand({
name: "lovefemboys",
displayName: "lovefemboys",
description: "Get an image of a femboy",
displayDescription: "Get an image of a femboy",
applicationId: "-1",
inputType: 1,
type: 1,
options: [
{
name: "nsfw",
displayName: "nsfw",
description: "Get the result from r/femboys instead of r/femboy (NSFW)",
displayDescription: "Get the result from r/femboys instead of r/femboy (NSFW)",
required: false,
type: 5,
},
{
name: "sort",
displayName: "sort",
description: "Changes the way reddit sorts.",
displayDescription: "Changes the way reddit sorts",
required: false,
type: 3,
},
{
name: "silent",
displayName: "silent",
description: "Makes it so only you can see the message.",
displayDescription: "Makes it so only you can see the message.",
required: false,
type: 5,
},
],
execute: async (args: any[], ctx: any) => {
try {
const nsfw = args.find((a) => a.name === "nsfw")?.value;
let sort = args.find((a) => a.name === "sort")?.value;
const silent = args.find((a) => a.name === "silent")?.value;
if (typeof sort === "undefined") sort = storage.sortdefs;
if (!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)) {
sendReply(ctx.channel.id, "Incorrect sorting type. Valid options are\n`best`, `hot`, `new`, `rising`, `top`, `controversial`.", []);
return;
}
if (nsfw) {
const ok = await showConfirm(
"⚠️ NSFW Content Warning",
"This command will send NSFW content from r/femboys. Are you sure you want to continue?"
);
if (!ok) return;
}
let response = await fetch(
`https://www.reddit.com/r/femboy${nsfw ? "s" : ""}/${sort}.json?limit=100`
).then((r) => r.json());
if (!ctx.channel.nsfw_ && nsfw && storage.nsfwwarn && !(silent ?? true)) {
sendReply(ctx.channel.id, "This channel is not marked as NSFW.", []);
return;
}
response = response.data?.children?.[
Math.floor(Math.random() * response.data?.children?.length)
]?.data;
const author = await fetch(
`https://www.reddit.com/u/${response?.author}/about.json`
).then((r) => r.json());
if (silent ?? true) {
sendReply(ctx.channel.id, "", [
{
type: "rich",
title: response?.title,
url: `https://reddit.com${response?.permalink}`,
author: {
name: `u/${response?.author} • r/${response?.subreddit}`,
proxy_icon_url: author?.data.icon_img.split("?")[0],
icon_url: author?.data.icon_img.split("?")[0],
},
image: {
proxy_url: response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ?? response?.url?.replace(/.gifv$/g, ".gif"),
url: response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ?? response?.url?.replace(/.gifv$/g, ".gif"),
width: response?.preview?.images?.[0]?.source?.width,
height: response?.preview?.images?.[0]?.source?.height,
},
color: "0xf4b8e4",
},
]);
} else {
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: response?.url_overridden_by_dest ?? response?.url },
void 0,
{ nonce: fixNonce }
);
}
} catch (err) {
console.error("[LoveFemboys] Error:", err);
sendReply(ctx.channel.id, "ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺", []);
}
},
});
},
onUnload() {
this._unregister?.();
},
});