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

Anime command, Jikan MAL API #33

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
84 changes: 84 additions & 0 deletions src/commands/Anime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { Command } = require('@dyno.gg/dyno-core');
const superagent = require('superagent');


class Anime extends Command {
constructor(...args) {
super(...args);

this.name = 'anime';
this.aliases = ['animu'];
this.module = 'Fun';
this.description = 'Get info about an anime';
this.usage = 'anime <anime>';
this.example = 'anime acchi kocchi';
this.cooldown = 5000;
this.expectedArgs = 1;
}

async execute({ message, args }) {
let msg = await this.sendMessage(message.channel, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg is not reassigned, in that case it's better to use const instead of let

embed: {
color: 0x337fd5,
thumbnail: {
url: 'https://cdn.discordapp.com/emojis/397911964988342282.gif',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord CDNs can't be trusted, as the content may dissapear without further notice, or someone may delete the emoji.
I have uploaded that to our own CDN, mind chaning the link? https://cdn.dyno.gg/fun/discord_loading.gif

},
title: 'Looking for an anime...',
},
});
let res;
let anime;

try {
res = await superagent.get(`https://api.jikan.me/search/anime/${args.slice(1).join(' ')}/1`);
anime = res.body.result[0];
} catch (err) {
return msg.edit({
content: `${this.utils.emoji.error} I couldn't find any.`,
embed: {},
});
}
return msg.edit({
embed: {
author: {
name: `${anime.title}`,
url: `${anime.url}`,
icon_url: 'https://myanimelist.cdn-dena.com/img/sp/icon/apple-touch-icon-256.png',
},
color: 0x337fd5,
thumbnail: {
url: anime.image_url,
},
timestamp: new Date(),
fields: [{
name: 'Episodes',
value: `${anime.episodes}`,
inline: true,
},
{
name: 'Type',
value: `${anime.type}`,
inline: true,
},
{
name: 'Score',
value: `${anime.score}`,
inline: true,
},
{
name: 'Members',
value: `${anime.members}`,
inline: true,
},
{
name: 'Description',
value: `${anime.description}`,
inline: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the last field and the biggest, I think it makes sense for it to not be inline and take up a whole row

},
],
},
});
}
}

module.exports = Anime;
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ exports.CatFacts = require('./CatFacts');
exports.Slots = require('./Slots');
exports.Weather = require('./Weather');
exports.Github = require('./Github');
exports.Anime = require('./Anime');