Equicord/src/equicordplugins/cuteAnimeGirls/index.ts

60 lines
1.7 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { EquicordDevs } from "@utils/constants";
import { ApplicationCommandOptionType } from "../../api/Commands";
import definePlugin from "../../utils/types";
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
async function fetchReddit(sub: string) {
const res = await fetch(`https://www.reddit.com/r/${sub}/top.json?limit=100&t=all`);
const resp = await res.json();
try {
const { children } = resp.data;
const r = rand(0, children.length - 1);
return children[r].data.url;
} catch (err) {
console.error(resp);
console.error(err);
}
return "";
}
export default definePlugin({
name: "CuteAnimeGirls",
authors: [EquicordDevs.ShadyGoat],
description: "Add a command to send cute anime girls in the chat",
commands: [{
name: "anime-girls",
description: "Send cute anime girls",
options: [
{
name: "cat",
description: "If set, this will send exclusively cute anime cat girls",
type: ApplicationCommandOptionType.BOOLEAN,
required: false,
},
],
async execute(args) {
let sub = "cuteanimeboys";
if (args.length > 0) {
const v = args[0].value as any as boolean;
if (v) {
sub = "animecatboys";
}
}
return {
content: await fetchReddit(sub),
};
},
}]
});