From 0747287fd6844288c3c7158ac232e1411c7ff625 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 15 Feb 2024 21:42:43 +0100 Subject: [PATCH] Added first anime command --- src/commands/anime.ts | 49 +++++++++++++++++++++++++++++++++ src/commands/anime/search.ts | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/commands/anime.ts create mode 100644 src/commands/anime/search.ts diff --git a/src/commands/anime.ts b/src/commands/anime.ts new file mode 100644 index 0000000..795e700 --- /dev/null +++ b/src/commands/anime.ts @@ -0,0 +1,49 @@ +import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js" +import { Command } from "interfaces" +import search from "./anime/search" +import { devMessage, embedColor } from "config/options" + +export = { + name: "anime", + description: "Anime subcommands", + public: true, + dev: true, + subcommands: true, + + data: new SlashCommandBuilder() + .setName("anime") + .setDescription("Anime subcommands") + .addSubcommand(subcommand => + subcommand + .setName("search") + .setDescription("Search for an anime") + .addStringOption(option => + option + .setName("query") + .setDescription("The anime to search for") + .setRequired(true) + ) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + const subcommand = interaction.options.getSubcommand() + + if (subcommand === "search") { + search(interaction) + return + } + + await interaction.reply({ + embeds: [{ + description: "This command is currently under development", + color: embedColor, + footer: { + text: interaction.guild!.name + " | " + devMessage, + icon_url: interaction.guild!.iconURL() || undefined + } + }] + }) + } +} as Command \ No newline at end of file diff --git a/src/commands/anime/search.ts b/src/commands/anime/search.ts new file mode 100644 index 0000000..8b26034 --- /dev/null +++ b/src/commands/anime/search.ts @@ -0,0 +1,52 @@ +import { ChatInputCommandInteraction } from "discord.js" +import { anilist } from "anilist" +import { embedColor } from "config/options" + +export default async function search(interaction: ChatInputCommandInteraction) { + await interaction.deferReply() + const query = interaction.options.getString("query")! + + const data = anilist.query.media() + .arguments({ search: query, type: "ANIME" }) + .withTitles("english", "romaji") + .withDescription() + .withCoverImage("medium") + .withDuration() + .withGenres() + .withAverageScore() + .withMeanScore() + const anime = await data.fetch() + + if (!anime) { + await interaction.editReply({ + embeds: [{ + description: "No anime found", + color: embedColor + }] + }) + } + + const romaji = anime.title?.romaji || "Romaji not available" + const english = anime.title?.english || "English not available" + const animeDescription = anime.description?.replaceAll("
", "\n").slice(0, 256) + "..." || "No description available" + + await interaction.editReply({ + embeds: [{ + title: romaji + " | " + english, + description: ` + **Description:** ${animeDescription} + + **Genres:** ${anime.genres.join(", ")} + **Avg. Score:** ${anime.averageScore || "No score available"} + **Mean Score:** ${anime.meanScore || "No score available"} + `, + color: embedColor, + thumbnail: { + url: anime.coverImage?.medium || "" + }, + footer: { + text: anime.duration?.toString() + " minute episodes" || "No duration available" + } + }] + }) +} \ No newline at end of file