Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and Enhance the 'anime' Command #157

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 61 additions & 55 deletions Prefix Commands/Anime/anime.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
const { MessageEmbed } = require('discord.js');
const Scraper = require('mal-scraper');

const config = require('config'); // Make sure you have your 'config' module imported.

module.exports = {
help: {
name: 'anime',
aliases: ['anime'],
description: 'Shows Information about an Anime.',
category: __dirname.split("Commands\\")[1]
},
run: async (client, message, args) => {

let Text = args.join(" ");

if (!Text) return message.channel.send(`Please Give Something!`);

if (Text.length > 200) return message.channel.send(`Text Limit - 200`);

let Msg = await message.channel.send(`**Searching It For You ${emotes.load}**`);

let Replaced = Text.replace(/ /g, " ");

await Msg.delete();

let Anime;

let Embed;

try {

Anime = await Scraper.getInfoFromName(Replaced);

if (!Anime.genres[0]) Anime.genres[0] = "None";

Embed = new MessageEmbed()
.setColor(config.embedcolor)
.setURL(Anime.url)
.setTitle(Anime.title)
.setDescription(Anime.synopsis)
.addField(`Type`, Anime.type, true)
.addField(`Status`, Anime.status, true)
.addField(`Premiered`, Anime.premiered, true)
.addField(`Episodes`, Anime.episodes, true)
.addField(`Duration`, Anime.duration, true)
.addField(`Popularity`, Anime.popularity, true)
.addField(`Genres`, Anime.genres.join(", "))
.setThumbnail(Anime.picture)
.setFooter(`Score - ${Anime.score}`)
.setTimestamp();

} catch (error) {
console.log(error)
return message.channel.send(`No Anime Found!`)

};

return message.channel.send(Embed);
},
help: {
name: 'anime',
aliases: ['anime'],
description: 'Shows information about an anime.',
category: __dirname.split("Commands\\")[1]
},
run: async (client, message, args) => {
// Get the anime name from the user's input.
const animeName = args.join(" ");

// Check if the user provided an anime name.
if (!animeName) {
return message.channel.send(`Please provide the name of an anime.`);
}

// Limit the length of the anime name to prevent potential issues.
if (animeName.length > 200) {
return message.channel.send(`Anime name is too long (max 200 characters).`);
}

try {
// Use a loading message while fetching anime information.
let msg = await message.channel.send(`Searching for information...`);

// Fetch anime information.
const animeInfo = await Scraper.getInfoFromName(animeName);

// Handle cases where anime information is not available.
if (!animeInfo.title) {
return message.channel.send(`No anime found with the provided name.`);
}

// Create an embed to display anime information.
const embed = new MessageEmbed()
.setColor(config.embedcolor)
.setURL(animeInfo.url)
.setTitle(animeInfo.title)
.setDescription(animeInfo.synopsis)
.addField(`Type`, animeInfo.type, true)
.addField(`Status`, animeInfo.status, true)
.addField(`Premiered`, animeInfo.premiered, true)
.addField(`Episodes`, animeInfo.episodes, true)
.addField(`Duration`, animeInfo.duration, true)
.addField(`Popularity`, animeInfo.popularity, true)
.addField(`Genres`, animeInfo.genres.join(", "))
.setThumbnail(animeInfo.picture)
.setFooter(`Score - ${animeInfo.score}`)
.setTimestamp();

// Send the anime information as an embed.
message.channel.send(embed);

// Delete the loading message.
msg.delete();
} catch (error) {
console.error(error);
message.channel.send(`An error occurred while fetching anime information.`);
}
},
};