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 { 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: "",
|
||||||
|
|
@ -27,18 +53,31 @@ function sendReply(channelID, content, embed) {
|
||||||
MessageActions.receiveMessage(channel, msg);
|
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",
|
name: "lovefemboys",
|
||||||
displayName: "lovefemboys",
|
displayName: "lovefemboys",
|
||||||
description: "Get an image of a femboy",
|
description: "Get an image of a femboy",
|
||||||
displayDescription: "Get an image of a femboy",
|
displayDescription: "Get an image of a femboy",
|
||||||
|
applicationId: "-1",
|
||||||
|
inputType: 1,
|
||||||
|
type: 1,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "nsfw",
|
name: "nsfw",
|
||||||
displayName: "nsfw",
|
displayName: "nsfw",
|
||||||
description: "Get the result from r/femboys instead of r/femboy (NSFW)",
|
description: "Get the result from r/femboys instead of r/femboy (NSFW)",
|
||||||
displayDescription:
|
displayDescription: "Get the result from r/femboys instead of r/femboy (NSFW)",
|
||||||
"Get the result from r/femboys instead of r/femboy (NSFW)",
|
|
||||||
required: false,
|
required: false,
|
||||||
type: 5,
|
type: 5,
|
||||||
},
|
},
|
||||||
|
|
@ -59,73 +98,42 @@ export const lovefemboysCommand = {
|
||||||
type: 5,
|
type: 5,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
applicationId: "-1",
|
execute: async (args: any[], ctx: any) => {
|
||||||
inputType: 1,
|
|
||||||
type: 1,
|
|
||||||
execute: async (args, ctx) => {
|
|
||||||
try {
|
try {
|
||||||
// Some code taken from enmity gotfemboys plugin by spinfal & was modified with the help of meqativ
|
const nsfw = args.find((a) => a.name === "nsfw")?.value;
|
||||||
const nsfw = args.find((arg) => arg.name === "nsfw")?.value;
|
let sort = args.find((a) => a.name === "sort")?.value;
|
||||||
let sort = args.find((arg) => arg.name === "sort")?.value;
|
const silent = args.find((a) => a.name === "silent")?.value;
|
||||||
const silent = args.find((arg) => arg.name === "silent")?.value;
|
|
||||||
|
|
||||||
if (typeof sort === "undefined") sort = storage.sortdefs;
|
if (typeof sort === "undefined") sort = storage.sortdefs;
|
||||||
if (
|
if (!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)) {
|
||||||
!["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`.", []);
|
||||||
) {
|
|
||||||
sendReply(
|
|
||||||
ctx.channel.id,
|
|
||||||
"Incorrect sorting type. Valid options are\n`best`, `hot`, `new`, `rising`, `top`, `controversial`.",
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show NSFW warning popup only when nsfw option is selected
|
|
||||||
if (nsfw) {
|
if (nsfw) {
|
||||||
const shouldProceed = await new Promise((resolve) => {
|
const ok = await showConfirm(
|
||||||
alerts.showConfirmationAlert({
|
"⚠️ NSFW Content Warning",
|
||||||
title: "⚠️ NSFW Content Warning",
|
"This command will send NSFW content from r/femboys. Are you sure you want to continue?"
|
||||||
content:
|
);
|
||||||
"This command will send NSFW (Not Safe For Work) content from r/femboys. Are you sure you want to continue?",
|
if (!ok) return;
|
||||||
confirmText: "Yes, Continue",
|
|
||||||
onConfirm: () => resolve(true),
|
|
||||||
cancelText: "Cancel",
|
|
||||||
onCancel: () => resolve(false),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!shouldProceed) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
`https://www.reddit.com/r/femboy/${sort}.json?limit=100`,
|
`https://www.reddit.com/r/femboy${nsfw ? "s" : ""}/${sort}.json?limit=100`
|
||||||
).then((res) => res.json());
|
).then((r) => r.json());
|
||||||
|
|
||||||
if (!ctx.channel.nsfw_ && nsfw && storage.nsfwwarn && !(silent ?? true)) {
|
if (!ctx.channel.nsfw_ && nsfw && storage.nsfwwarn && !(silent ?? true)) {
|
||||||
sendReply(
|
sendReply(ctx.channel.id, "This channel is not marked as NSFW.", []);
|
||||||
ctx.channel.id,
|
|
||||||
"This channel is not marked as NSFW\n(You can disable this check in plugin settings)",
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsfw) {
|
response = response.data?.children?.[
|
||||||
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)
|
Math.floor(Math.random() * response.data?.children?.length)
|
||||||
]?.data;
|
]?.data;
|
||||||
|
|
||||||
const author = await fetch(
|
const author = await fetch(
|
||||||
`https://www.reddit.com/u/${response?.author}/about.json`,
|
`https://www.reddit.com/u/${response?.author}/about.json`
|
||||||
).then((res) => res.json());
|
).then((r) => r.json());
|
||||||
|
|
||||||
if (silent ?? true) {
|
if (silent ?? true) {
|
||||||
sendReply(ctx.channel.id, "", [
|
sendReply(ctx.channel.id, "", [
|
||||||
|
|
@ -139,12 +147,8 @@ export const lovefemboysCommand = {
|
||||||
icon_url: author?.data.icon_img.split("?")[0],
|
icon_url: author?.data.icon_img.split("?")[0],
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
proxy_url:
|
proxy_url: response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ?? response?.url?.replace(/.gifv$/g, ".gif"),
|
||||||
response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ??
|
url: response?.url_overridden_by_dest?.replace(/.gifv$/g, ".gif") ?? response?.url?.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,
|
width: response?.preview?.images?.[0]?.source?.width,
|
||||||
height: response?.preview?.images?.[0]?.source?.height,
|
height: response?.preview?.images?.[0]?.source?.height,
|
||||||
},
|
},
|
||||||
|
|
@ -155,20 +159,19 @@ export const lovefemboysCommand = {
|
||||||
const fixNonce = Date.now().toString();
|
const fixNonce = Date.now().toString();
|
||||||
MessageActions.sendMessage(
|
MessageActions.sendMessage(
|
||||||
ctx.channel.id,
|
ctx.channel.id,
|
||||||
{
|
{ content: response?.url_overridden_by_dest ?? response?.url },
|
||||||
content: response?.url_overridden_by_dest ?? response?.url,
|
|
||||||
},
|
|
||||||
void 0,
|
void 0,
|
||||||
{ nonce: fixNonce },
|
{ nonce: fixNonce }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[LoveFemboys] Error:", err);
|
console.error("[LoveFemboys] Error:", err);
|
||||||
sendReply(
|
sendReply(ctx.channel.id, "ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺", []);
|
||||||
ctx.channel.id,
|
|
||||||
"ERROR !!!!!!!!!!!! 😭😭😭 Check debug logs!! 🥺🥺🥺",
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
},
|
||||||
|
onUnload() {
|
||||||
|
this._unregister?.();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue