Updated search command

This commit is contained in:
2024-02-16 12:36:42 +01:00
parent 3e0bb040ed
commit 0e2caea0ae

View File

@@ -1,6 +1,7 @@
import { ChatInputCommandInteraction } from "discord.js" import { ChatInputCommandInteraction } from "discord.js"
import { anilist } from "anilist" import { anilist } from "anilist"
import { embedColor } from "config/options" import { embedColor } from "config/options"
import { capitalizeFirstLetter } from "utils/functions/funcs"
export default async function search(interaction: ChatInputCommandInteraction) { export default async function search(interaction: ChatInputCommandInteraction) {
await interaction.deferReply() await interaction.deferReply()
@@ -15,6 +16,11 @@ export default async function search(interaction: ChatInputCommandInteraction) {
.withGenres() .withGenres()
.withAverageScore() .withAverageScore()
.withMeanScore() .withMeanScore()
.withEpisodes()
.withId()
.withStartDate("year", "month", "day")
.withEndDate("year", "month", "day")
.withSeason()
const anime = await data.fetch() const anime = await data.fetch()
if (!anime) { if (!anime) {
@@ -29,6 +35,12 @@ export default async function search(interaction: ChatInputCommandInteraction) {
const romaji = anime.title?.romaji || "Romaji not available" const romaji = anime.title?.romaji || "Romaji not available"
const english = anime.title?.english || "English not available" const english = anime.title?.english || "English not available"
const animeDescription = anime.description?.replaceAll("<br>", "\n").slice(0, 256) + "..." || "No description available" const animeDescription = anime.description?.replaceAll("<br>", "\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({ await interaction.editReply({
embeds: [{ embeds: [{
@@ -39,13 +51,17 @@ export default async function search(interaction: ChatInputCommandInteraction) {
**Genres:** ${anime.genres.join(", ")} **Genres:** ${anime.genres.join(", ")}
**Avg. Score:** ${anime.averageScore || "No score available"} **Avg. Score:** ${anime.averageScore || "No score available"}
**Mean Score:** ${anime.meanScore || "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, color: embedColor,
thumbnail: { thumbnail: {
url: anime.coverImage?.medium || "" url: anime.coverImage?.medium || ""
}, },
footer: { footer: {
text: anime.duration?.toString() + " minute episodes" || "No duration available" text: "ID: " + anime.id
} }
}] }]
}) })