Updated anime command
This commit is contained in:
@@ -1,46 +1,88 @@
|
|||||||
import { SlashCommandBuilder } from "discord.js"
|
import { SlashCommandBuilder } from "discord.js"
|
||||||
import { ICommand } from "interfaces"
|
import { ICommand } from "interfaces"
|
||||||
import search from "./anime/search"
|
|
||||||
import { devMessage, embedColor } from "config/options"
|
import { devMessage, embedColor } from "config/options"
|
||||||
|
import { anilist } from "anilist"
|
||||||
|
import { capitalizeFirstLetter } from "utils/functions/funcs"
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
name: "anime",
|
name: "anime",
|
||||||
description: "Anime subcommands",
|
description: "Anime subcommands",
|
||||||
public: true,
|
public: true,
|
||||||
dev: true,
|
dev: false,
|
||||||
subcommands: true,
|
subcommands: true,
|
||||||
|
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("anime")
|
.setName("anime")
|
||||||
.setDescription("Anime subcommands")
|
.setDescription("Search for anime using anilist API")
|
||||||
.addSubcommand(subcommand =>
|
.addStringOption(option =>
|
||||||
subcommand
|
option
|
||||||
.setName("search")
|
.setName("query")
|
||||||
.setDescription("Search for an anime")
|
.setDescription("The anime to search for")
|
||||||
.addStringOption(option =>
|
.setRequired(true)
|
||||||
option
|
|
||||||
.setName("query")
|
|
||||||
.setDescription("The anime to search for")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.setDMPermission(false),
|
.setDMPermission(false),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const subcommand = interaction.options.getSubcommand()
|
await interaction.deferReply()
|
||||||
|
const query = interaction.options.getString("query")!
|
||||||
|
|
||||||
if (subcommand === "search") {
|
const data = anilist.query.media()
|
||||||
search(interaction)
|
.arguments({ search: query, type: "ANIME" })
|
||||||
return
|
.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("<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({
|
||||||
embeds: [{
|
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,
|
color: embedColor,
|
||||||
|
thumbnail: {
|
||||||
|
url: anime.coverImage?.medium || ""
|
||||||
|
},
|
||||||
footer: {
|
footer: {
|
||||||
text: interaction.guild!.name + " | " + devMessage,
|
text: "ID: " + anime.id + " | " + devMessage
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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("<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({
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user