-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Added searchanime command that sends an embed containing all po…
…ssible info about the anime
- Loading branch information
Showing
4 changed files
with
182 additions
and
667 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const { embedMessage } = require("../../modules/embedSimple"); | ||
const { getAnimeInfo } = require("../../modules/get-anime-details"); | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
const { logger } = require("../../modules/logger"); | ||
|
||
module.exports = { | ||
name: "searchanime", | ||
args: true, | ||
aliases: ["san"], | ||
description: "Searches for an Anime on Myanimelist", | ||
usage: "san || searchanime", | ||
async run(message, args, client) { | ||
const searchString = args.join(" "); | ||
if (!searchString) | ||
return await message.channel.send({ | ||
embeds: [embedMessage("#9dcc37", "You have to provide an anime name!")], | ||
}); | ||
try { | ||
const Anime = await getAnimeInfo(searchString); | ||
const animeEmbed = { | ||
color: "#9dcc37", | ||
title: `${Anime.titlerom} AKA ${Anime.titleeng ?? `${Anime.titlerom}`}`, | ||
url: `${`https://myanimelist.net/anime/${Anime.malid}`}`, | ||
author: { | ||
name: `${message.member.user.username}`, | ||
icon_url: `${message.member.user.avatarURL()}`, | ||
}, | ||
description: `${Anime.synopsis}`, | ||
thumbnail: { | ||
url: `${Anime.imageUrl}`, | ||
}, | ||
fields: [ | ||
{ | ||
name: "Status", | ||
value: `${Anime.status}`, | ||
}, | ||
{ | ||
name: "Rating", | ||
value: `${Anime.rating}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "Score/Rank", | ||
value: `${Anime.score}/${Anime.rank}`, | ||
}, | ||
{ | ||
name: "Premiered", | ||
value: Anime.premiered, | ||
inline: true, | ||
}, | ||
{ | ||
name: "Episodes Number", | ||
value: `${Anime.episodes ? Anime.episodes : "Unknown"}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "Aired", | ||
value: `${Anime.aired ? Anime.aired : "Unknown"}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "Genres", | ||
value: `${Anime.genres.join(" - ")}`, | ||
inline: true, | ||
}, | ||
], | ||
|
||
timestamp: new Date(), | ||
}; | ||
|
||
await message.channel.send({ embeds: [animeEmbed] }); | ||
} catch (err) { | ||
await message.channel.send({ | ||
embeds: [embedMessage("#9dcc37", `Could not find this Anime, Sry!`)], | ||
}); | ||
logger(err.message, "error"); | ||
console.error(err); | ||
} | ||
}, | ||
data: new SlashCommandBuilder() | ||
.setName("searchanime") | ||
.setDescription("Searches for an Anime") | ||
.addStringOption((option) => | ||
option.setName("name").setRequired(true).setDescription("anime to search") | ||
), | ||
async execute() {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const jikanjs = require("jikanjs"); | ||
const { logger } = require("./logger"); | ||
jikanjs.settings.setBaseURL("https://api.jikan.moe/v3", 3); | ||
|
||
/** | ||
* Searches for an Anime on the Jikan Database | ||
* @param {String} animeName | ||
* @param {String} type | ||
* @returns Object | ||
*/ | ||
|
||
module.exports.getAnimeInfo = async (animeName, type = "anime") => { | ||
try { | ||
const getId = await jikanjs.search(type, animeName, [1]); | ||
const animeId = getId.results[0].mal_id; | ||
if (!animeId) throw new Error("No anime ID was found!"); | ||
const getFullInfo = await jikanjs.loadAnime(animeId, "/"); | ||
const genresArray = getFullInfo.genres.map((element) => element.name); | ||
|
||
return { | ||
malid: getFullInfo.mal_id, | ||
imageUrl: getFullInfo.image_url, | ||
titlerom: getFullInfo.title, | ||
titleeng: getFullInfo.title_english, | ||
episodes: getFullInfo.episodes, | ||
status: getFullInfo.status, | ||
rating: getFullInfo.rating, | ||
score: getFullInfo.score, | ||
rank: getFullInfo.rank, | ||
synopsis: getFullInfo.synopsis, | ||
premiered: getFullInfo.premiered, | ||
genres: genresArray, | ||
aired: getFullInfo.aired.string, | ||
}; | ||
} catch (err) { | ||
logger(err.message, "error"); | ||
throw err; | ||
} | ||
}; |
Oops, something went wrong.