Update index.ts

This commit is contained in:
OTKUSteyler 2026-06-16 20:56:11 +02:00 • committed by GitHub
parent 972c87ec33
commit a7073e3e8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,12 +1,23 @@
import { registerCommand } from "@vendetta/commands";
import { findByProps } from "@vendetta/metro";
import { fetchRedditImage } from "./utils";
import { defineCorePlugin } from "..";
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 findByProps = (...props: string[]) =>
(globalThis as any).vendetta?.metro?.findByProps(...props);
const { sendBotMessage } = findByProps("sendBotMessage");
const messageUtil = findByProps("sendMessage", "editMessage");
const MessageActions = findByProps("sendMessage", "receiveMessage");
const BotMessage = findByProps("createBotMessage");
const Avatars = findByProps("BOT_AVATARS");
const { registerCommand } = findByProps("registerCommand");
function sendReply(channelId: string, content: string, embeds: any[]) {
const msg = BotMessage.createBotMessage({ channelId, content: "", embeds });
@ -18,13 +29,47 @@ function sendReply(channelId: string, content: string, embeds: any[]) {
MessageActions.receiveMessage(channelId, msg);
}
const DEFAULT_SORT = "hot";
async function fetchRedditImage(nsfw: boolean, sort: string) {
try {
const subreddit = nsfw ? "femboys" : "femboy";
const response = await fetch(
`https://www.reddit.com/r/${subreddit}/${sort}.json?limit=100`
).then((r) => r.json());
const lovefemboys = registerCommand({
const post = response.data?.children?.[
Math.floor(Math.random() * response.data?.children?.length)
]?.data;
if (!post) return null;
const authorData = await fetch(
`https://www.reddit.com/u/${post.author}/about.json`
).then((r) => r.json());
return {
url: (post.url_overridden_by_dest ?? post.url)?.replace(/.gifv$/g, ".gif"),
title: post.title,
permalink: post.permalink,
author: post.author,
subreddit: post.subreddit,
width: post.preview?.images?.[0]?.source?.width,
height: post.preview?.images?.[0]?.source?.height,
authorIcon: authorData?.data?.icon_img?.split("?")[0],
};
} catch {
return null;
}
}
this._unregister = registerCommand({
name: "lovefemboys",
displayName: "lovefemboys",
description: "Get an image of a femboy",
displayDescription: "Get an image of a femboy",
// @ts-ignore
applicationId: "-1",
inputType: 1,
type: 1,
options: [
{
name: "nsfw",
@ -51,14 +96,11 @@ const lovefemboys = registerCommand({
type: 5,
},
],
// @ts-ignore
applicationId: "-1",
inputType: 1,
type: 1,
execute: async function (args, ctx) {
const options = new Map(args.map((o) => [o.name, o]));
execute: async (args: any[], ctx: any) => {
try {
const options = new Map(args.map((o: any) => [o.name, o]));
const nsfw: boolean = options.get("nsfw")?.value ?? false;
const sort: string = options.get("sort")?.value ?? DEFAULT_SORT;
const sort: string = options.get("sort")?.value ?? "hot";
const silent: boolean = options.get("silent")?.value ?? true;
if (!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)) {
@ -102,7 +144,14 @@ const lovefemboys = registerCommand({
const fixNonce = Date.now().toString();
messageUtil.sendMessage(ctx.channel.id, { content: post.url }, void 0, { nonce: fixNonce });
}
} catch (err) {
console.error("[LoveFemboys] Error:", err);
sendBotMessage(ctx.channel.id, "ERROR 😭😭😭 Check debug logs!! 🥺🥺🥺");
}
},
});
},
onUnload() {
this._unregister?.();
},
});
export default lovefemboys;