Update index.ts
This commit is contained in:
parent
254ef099f6
commit
a4fb30ebbf
1 changed files with 153 additions and 150 deletions
|
|
@ -1,15 +1,41 @@
|
|||
import { defineCorePlugin } from "..";
|
||||
import { findByProps } from "@vendetta/metro";
|
||||
import { storage } from "@vendetta/plugin";
|
||||
import { alerts } from "@vendetta/ui";
|
||||
|
||||
const findByProps = (...props: string[]) =>
|
||||
(window as any).bunny?.metro?.findByProps(...props) ??
|
||||
(window as any).vendetta?.metro?.findByProps(...props);
|
||||
|
||||
const MessageActions = findByProps("sendMessage", "receiveMessage");
|
||||
const Channels = findByProps("getLastSelectedChannelId");
|
||||
const BotMessage = findByProps("createBotMessage");
|
||||
const Avatars = findByProps("BOT_AVATARS");
|
||||
|
||||
function sendReply(channelID, content, embed) {
|
||||
const channel = channelID ?? Channels?.getChannelId?.();
|
||||
// Simple in-memory storage since @vendetta/plugin isn't available in core
|
||||
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({
|
||||
channelId: channel,
|
||||
content: "",
|
||||
|
|
@ -27,18 +53,31 @@ function sendReply(channelID, content, embed) {
|
|||
MessageActions.receiveMessage(channel, msg);
|
||||
}
|
||||
|
||||
export const lovefemboysCommand = {
|
||||
export default defineCorePlugin({
|
||||
manifest: {
|
||||
id: "lovefemboys",
|
||||
name: "LoveFemboys",
|
||||
version: "1.0.0",
|
||||
description: "Get an image of a femboy via slash command",
|
||||
authors: [],
|
||||
},
|
||||
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)",
|
||||
displayDescription: "Get the result from r/femboys instead of r/femboy (NSFW)",
|
||||
required: false,
|
||||
type: 5,
|
||||
},
|
||||
|
|
@ -59,73 +98,42 @@ export const lovefemboysCommand = {
|
|||
type: 5,
|
||||
},
|
||||
],
|
||||
applicationId: "-1",
|
||||
inputType: 1,
|
||||
type: 1,
|
||||
execute: async (args, ctx) => {
|
||||
execute: async (args: any[], ctx: any) => {
|
||||
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;
|
||||
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`.",
|
||||
[],
|
||||
);
|
||||
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;
|
||||
}
|
||||
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/${sort}.json?limit=100`,
|
||||
).then((res) => res.json());
|
||||
`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\n(You can disable this check in plugin settings)",
|
||||
[],
|
||||
);
|
||||
sendReply(ctx.channel.id, "This channel is not marked as NSFW.", []);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nsfw) {
|
||||
response = await fetch(
|
||||
`https://www.reddit.com/r/femboys/${sort}.json?limit=100`,
|
||||
).then((res) => res.json());
|
||||
}
|
||||
|
||||
response =
|
||||
response.data?.children?.[
|
||||
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());
|
||||
`https://www.reddit.com/u/${response?.author}/about.json`
|
||||
).then((r) => r.json());
|
||||
|
||||
if (silent ?? true) {
|
||||
sendReply(ctx.channel.id, "", [
|
||||
|
|
@ -139,12 +147,8 @@ export const lovefemboysCommand = {
|
|||
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"),
|
||||
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,
|
||||
},
|
||||
|
|
@ -155,20 +159,19 @@ export const lovefemboysCommand = {
|
|||
const fixNonce = Date.now().toString();
|
||||
MessageActions.sendMessage(
|
||||
ctx.channel.id,
|
||||
{
|
||||
content: response?.url_overridden_by_dest ?? response?.url,
|
||||
},
|
||||
{ content: response?.url_overridden_by_dest ?? response?.url },
|
||||
void 0,
|
||||
{ nonce: fixNonce },
|
||||
{ nonce: fixNonce }
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[LoveFemboys] Error:", err);
|
||||
sendReply(
|
||||
ctx.channel.id,
|
||||
"ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺",
|
||||
[],
|
||||
);
|
||||
sendReply(ctx.channel.id, "ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺", []);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
onUnload() {
|
||||
this._unregister?.();
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue