From ce7a3379291ebed4aa3cb6333b0b7b8d06340d71 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 18 Feb 2024 14:39:00 +0100 Subject: [PATCH] Updated anime command --- src/commands/anime.ts | 84 +++++++++++++++++++++++++++--------- src/commands/anime/search.ts | 68 ----------------------------- 2 files changed, 63 insertions(+), 89 deletions(-) delete mode 100644 src/commands/anime/search.ts diff --git a/src/commands/anime.ts b/src/commands/anime.ts index ad08231..a0bb926 100644 --- a/src/commands/anime.ts +++ b/src/commands/anime.ts @@ -1,46 +1,88 @@ import { SlashCommandBuilder } from "discord.js" import { ICommand } from "interfaces" -import search from "./anime/search" import { devMessage, embedColor } from "config/options" +import { anilist } from "anilist" +import { capitalizeFirstLetter } from "utils/functions/funcs" export = { name: "anime", description: "Anime subcommands", public: true, - dev: true, + dev: false, 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) - ) + .setDescription("Search for anime using anilist API") + .addStringOption(option => + option + .setName("query") + .setDescription("The anime to search for") + .setRequired(true) ) .setDMPermission(false), async execute(interaction) { - const subcommand = interaction.options.getSubcommand() + await interaction.deferReply() + const query = interaction.options.getString("query")! - if (subcommand === "search") { - search(interaction) - return + const data = anilist.query.media() + .arguments({ search: query, type: "ANIME" }) + .withTitles("english", "romaji") + .withDescription() + .withCoverImage("medium") + .withDuration() + .withGenres() + .withAverageScore() + .withMeanScore() + .withEpisodes() + .withId() + .withStartDate("year", "month", "day") + .withEndDate("year", "month", "day") + .withSeason() + .withSiteUrl() + const anime = await data.fetch() + + if (!anime) { + await interaction.editReply({ + embeds: [{ + description: "No anime found", + color: embedColor + }] + }) } - await interaction.reply({ + 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" + const animeEpisodesRaw = anime.episodes + " episodes" + " | " + anime.duration + " minute episodes" + const animeEpisodes = anime.episodes ? animeEpisodesRaw : "No episodes available" + const animeStartDate = [anime.startDate?.day || "??", anime.startDate?.month || "??", anime.startDate?.year || "????"].join(".") + const animeEndDate = [anime.endDate?.day || "??", anime.endDate?.month || "??", anime.endDate?.year || "????"].join(".") + const animeSeasonRaw = capitalizeFirstLetter(anime.season ?? "null") + " " + anime.startDate?.year + const animeSeason = anime.season ? animeSeasonRaw : "No season available" + + await interaction.editReply({ embeds: [{ - description: "This command is currently under development", + title: romaji + " | " + english, + url: anime.siteUrl || "", + description: ` + **Description:** ${animeDescription} + + **Genres:** ${anime.genres.join(", ")} + **Avg. Score:** ${anime.averageScore || "No score available"} + **Mean Score:** ${anime.meanScore || "No score available"} + **Episodes:** ${animeEpisodes || "No episodes available"} + **Season:** ${animeSeason} + **Start Date:** ${animeStartDate} + **End Date:** ${animeEndDate} + `, color: embedColor, + thumbnail: { + url: anime.coverImage?.medium || "" + }, footer: { - text: interaction.guild!.name + " | " + devMessage, - icon_url: interaction.guild!.iconURL() || undefined + text: "ID: " + anime.id + " | " + devMessage } }] }) diff --git a/src/commands/anime/search.ts b/src/commands/anime/search.ts deleted file mode 100644 index b78a43a..0000000 --- a/src/commands/anime/search.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { ChatInputCommandInteraction } from "discord.js" -import { anilist } from "anilist" -import { embedColor } from "config/options" -import { capitalizeFirstLetter } from "utils/functions/funcs" - -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() - .withEpisodes() - .withId() - .withStartDate("year", "month", "day") - .withEndDate("year", "month", "day") - .withSeason() - 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" - const animeEpisodesRaw = anime.episodes + " episodes" + " | " + anime.duration + " minute episodes" - const animeEpisodes = anime.episodes ? animeEpisodesRaw : "No episodes available" - const animeStartDate = [anime.startDate?.day || "??", anime.startDate?.month || "??", anime.startDate?.year || "????"].join(".") - const animeEndDate = [anime.endDate?.day || "??", anime.endDate?.month || "??", anime.endDate?.year || "????"].join(".") - const animeSeasonRaw = capitalizeFirstLetter(anime.season ?? "null") + " " + anime.startDate?.year - const animeSeason = anime.season ? animeSeasonRaw : "No season 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"} - **Episodes:** ${animeEpisodes || "No episodes available"} - **Season:** ${animeSeason} - **Start Date:** ${animeStartDate} - **End Date:** ${animeEndDate} - `, - color: embedColor, - thumbnail: { - url: anime.coverImage?.medium || "" - }, - footer: { - text: "ID: " + anime.id - } - }] - }) -} \ No newline at end of file