Update index.ts
This commit is contained in:
parent
c7369fe2a9
commit
17409439cb
1 changed files with 132 additions and 145 deletions
|
|
@ -1,157 +1,144 @@
|
||||||
import { defineCorePlugin } from "..";
|
import { registerCommand } from "@vendetta/commands";
|
||||||
|
import { findByProps } from "@vendetta/metro";
|
||||||
|
|
||||||
export default defineCorePlugin({
|
const { sendBotMessage } = findByProps("sendBotMessage");
|
||||||
manifest: {
|
const messageUtil = findByProps("sendMessage", "editMessage");
|
||||||
id: "lovefemboys",
|
const MessageActions = findByProps("sendMessage", "receiveMessage");
|
||||||
name: "LoveFemboys",
|
const BotMessage = findByProps("createBotMessage");
|
||||||
version: "1.0.0",
|
const Avatars = findByProps("BOT_AVATARS");
|
||||||
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");
|
async function fetchRedditImage(nsfw: boolean, sort: string) {
|
||||||
const messageUtil = findByProps("sendMessage", "editMessage");
|
try {
|
||||||
const MessageActions = findByProps("sendMessage", "receiveMessage");
|
const subreddit = nsfw ? "femboys" : "femboy";
|
||||||
const BotMessage = findByProps("createBotMessage");
|
const response = await fetch(
|
||||||
const Avatars = findByProps("BOT_AVATARS");
|
`https://www.reddit.com/r/${subreddit}/${sort}.json?limit=100`
|
||||||
const { registerCommand } = findByProps("registerCommand");
|
).then((r) => r.json());
|
||||||
|
|
||||||
function sendReply(channelId: string, content: string, embeds: any[]) {
|
const post = response.data?.children?.[
|
||||||
const msg = BotMessage.createBotMessage({ channelId, content: "", embeds });
|
Math.floor(Math.random() * response.data?.children?.length)
|
||||||
msg.author.username = "Astolfo";
|
]?.data;
|
||||||
msg.author.avatar = "Astolfo";
|
|
||||||
Avatars.BOT_AVATARS.Astolfo =
|
|
||||||
"https://i.pinimg.com/736x/50/77/1f/50771f45b1c015cfbb8b0853ba7b8521.jpg";
|
|
||||||
if (content) msg.content = content;
|
|
||||||
MessageActions.receiveMessage(channelId, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchRedditImage(nsfw: boolean, sort: string) {
|
if (!post) return null;
|
||||||
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 post = response.data?.children?.[
|
const authorData = await fetch(
|
||||||
Math.floor(Math.random() * response.data?.children?.length)
|
`https://www.reddit.com/u/${post.author}/about.json`
|
||||||
]?.data;
|
).then((r) => r.json());
|
||||||
|
|
||||||
if (!post) return null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const authorData = await fetch(
|
function sendReply(channelId: string, content: string, embeds: any[]) {
|
||||||
`https://www.reddit.com/u/${post.author}/about.json`
|
const msg = BotMessage.createBotMessage({ channelId, content: "", embeds });
|
||||||
).then((r) => r.json());
|
msg.author.username = "Astolfo";
|
||||||
|
msg.author.avatar = "Astolfo";
|
||||||
|
Avatars.BOT_AVATARS.Astolfo =
|
||||||
|
"https://i.pinimg.com/736x/50/77/1f/50771f45b1c015cfbb8b0853ba7b8521.jpg";
|
||||||
|
if (content) msg.content = content;
|
||||||
|
MessageActions.receiveMessage(channelId, msg);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
const unregister = registerCommand({
|
||||||
url: (post.url_overridden_by_dest ?? post.url)?.replace(/.gifv$/g, ".gif"),
|
name: "lovefemboys",
|
||||||
title: post.title,
|
displayName: "lovefemboys",
|
||||||
permalink: post.permalink,
|
description: "Get an image of a femboy",
|
||||||
author: post.author,
|
displayDescription: "Get an image of a femboy",
|
||||||
subreddit: post.subreddit,
|
// @ts-ignore
|
||||||
width: post.preview?.images?.[0]?.source?.width,
|
applicationId: "-1",
|
||||||
height: post.preview?.images?.[0]?.source?.height,
|
inputType: 1,
|
||||||
authorIcon: authorData?.data?.icon_img?.split("?")[0],
|
type: 1,
|
||||||
};
|
options: [
|
||||||
} catch {
|
{
|
||||||
return null;
|
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 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 ?? "hot";
|
||||||
|
const silent: boolean = options.get("silent")?.value ?? true;
|
||||||
|
|
||||||
|
if (!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)) {
|
||||||
|
sendBotMessage(ctx.channel.id, "Incorrect sorting type. Valid options are: `best`, `hot`, `new`, `rising`, `top`, `controversial`.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nsfw && !ctx.channel.nsfw_) {
|
||||||
|
sendBotMessage(ctx.channel.id, "This channel is not marked as NSFW. Use an NSFW channel instead.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const post = await fetchRedditImage(nsfw, sort);
|
||||||
|
|
||||||
|
if (!post) {
|
||||||
|
sendBotMessage(ctx.channel.id, "No image found. Try again later.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (silent) {
|
||||||
|
sendReply(ctx.channel.id, "", [
|
||||||
|
{
|
||||||
|
type: "rich",
|
||||||
|
title: post.title,
|
||||||
|
url: `https://reddit.com${post.permalink}`,
|
||||||
|
author: {
|
||||||
|
name: `u/${post.author} • r/${post.subreddit}`,
|
||||||
|
proxy_icon_url: post.authorIcon,
|
||||||
|
icon_url: post.authorIcon,
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
proxy_url: post.url,
|
||||||
|
url: post.url,
|
||||||
|
width: post.width,
|
||||||
|
height: post.height,
|
||||||
|
},
|
||||||
|
color: "0xf4b8e4",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
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!! 🥺🥺🥺");
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
|
||||||
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 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 ?? "hot";
|
|
||||||
const silent: boolean = options.get("silent")?.value ?? true;
|
|
||||||
|
|
||||||
if (!["best", "hot", "new", "rising", "top", "controversial"].includes(sort)) {
|
|
||||||
sendBotMessage(ctx.channel.id, "Incorrect sorting type. Valid options are: `best`, `hot`, `new`, `rising`, `top`, `controversial`.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsfw && !ctx.channel.nsfw_) {
|
|
||||||
sendBotMessage(ctx.channel.id, "This channel is not marked as NSFW. Use an NSFW channel instead.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const post = await fetchRedditImage(nsfw, sort);
|
|
||||||
|
|
||||||
if (!post) {
|
|
||||||
sendBotMessage(ctx.channel.id, "No image found. Try again later.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silent) {
|
|
||||||
sendReply(ctx.channel.id, "", [
|
|
||||||
{
|
|
||||||
type: "rich",
|
|
||||||
title: post.title,
|
|
||||||
url: `https://reddit.com${post.permalink}`,
|
|
||||||
author: {
|
|
||||||
name: `u/${post.author} • r/${post.subreddit}`,
|
|
||||||
proxy_icon_url: post.authorIcon,
|
|
||||||
icon_url: post.authorIcon,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
proxy_url: post.url,
|
|
||||||
url: post.url,
|
|
||||||
width: post.width,
|
|
||||||
height: post.height,
|
|
||||||
},
|
|
||||||
color: "0xf4b8e4",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
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 {
|
||||||
|
onUnload: () => unregister(),
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue