Skip to content

Instantly share code, notes, and snippets.

@espeon
Last active November 13, 2019 18:03
Show Gist options
  • Select an option

  • Save espeon/d8fc770e5a2102fc8734ed575c5f1b2d to your computer and use it in GitHub Desktop.

Select an option

Save espeon/d8fc770e5a2102fc8734ed575c5f1b2d to your computer and use it in GitHub Desktop.
//this is a klasa function
//yeah.
const { Command } = require("klasa");
var req = require("request");
module.exports = class extends Command {
constructor(...args) {
super(...args, {
name: "anime-m",
enabled: true,
runIn: ["text", "dm"],
aliases: ["a", "anime", "am"],
subcommands: true,
description: "searches for anime",
usageDelim: " ",
usage: "<episode|search|e|s:default> (args:str) [...]"
});
}
async search(message, args) {
console.log(args);
var kitsu = await this.searchKitsu(message, args);
message.channel.send({
embed: {
title: `${kitsu[0].formattedTitle}`,
description: `${kitsu[0].attributes.synopsis}\n—————\nPopularity: #${kitsu[0].attributes.popularityRank}\nRatings: #${kitsu[0].attributes.ratingRank}\nContent Rating: ${kitsu[0].attributes.ageRating}`,
url: `https://kitsu.io/anime/${kitsu[0].attributes.slug}`,
color: 2708478,
footer: {
text: "カンボット by kanbaru#7887 | kitsu.io"
},
thumbnail: {
url: `${kitsu[0].attributes.posterImage.original}`
}
}
});
}
async episode(message, args) {
console.log(args);
var kitsu = await this.searchKitsu(message, args);
}
async e(message, args) {
this.episode(message, args);
}
async s(message, args) {
this.search(message, args);
}
//more modular shite
async searchKitsu(message, args) {
//kitsu link, requests a search for var `args`
let link = `https://kitsu.io/api/edge/anime?filter[text]=${args}`;
//epic promise, returns json to parent function
return new Promise(resolve => {
req(link, function(error, response, body) {
let kitsu = JSON.parse(body);
//checks if english title is the same as japanese title
let name_rom = kitsu.data[0].attributes.titles.en_jp.toUpperCase().replace("-", " ");
kitsu.data[0].formattedTitle = kitsu.data[0].attributes.titles.en_jp
if (typeof kitsu.data[0].attributes.titles.en != "undefined") {
let name_eng = kitsu.data[0].attributes.titles.en.toUpperCase().replace("-", " ");
console.log(kitsu.data[0].attributes.titles.en.toUpperCase().replace("-", " "))
if (name_rom === name_eng) {
kitsu[0].data.formattedTitle = kitsu.data[0].attributes.titles.en_jp
} else {
kitsu.data[0].formattedTitle = kitsu.data[0].attributes.titles.en_jp + " / " + kitsu.data[0].attributes.titles.en
}
}
console.log(kitsu.data[0].attributes.titles.en_jp.toUpperCase().replace("-", " "))
console.log(kitsu.data.formattedTitle)
//if data is undefined, send message back
if (kitsu.data[0] == undefined) {
return message.channel.send(
"It seems this anime may not be on Kitsu"
);
} else {
//otherwise return the data back to parent
resolve(kitsu.data);
}
});
});
}
async searchWS(message, args) {
//ws link, requests a search for var `args`
let link = `https://www.wonderfulsubs.com/api/v1/media/search?options=summary&q=${args}`;
//epic promise, returns json to parent function
return new Promise(resolve => {
req(link, function(error, response, body) {
let tw = JSON.parse(body);
console.log(tw.data[0]);
//if data is undefined, send message back
if (tw.data[0] == undefined) {
return message.channel.send(
"It seems this anime may not be on Kitsu"
);
} else {
//otherwise return the data back to parent
resolve(tw.data);
}
});
});
}
async getEpisodeofSeries(message, episode, kitsu) {
console.log(kitsu)
//gets kitsu episode list
let link = `https://kitsu.io/api/edge/anime/${kitsu.id}/episodes`;
//epic promise, returns json to parent function
return new Promise(resolve => {
req(link, function(error, response, body) {
//parse json and "choose" episode
let kitsuEpisodes = JSON.parse(body);
kitsuEpisodes = kitsuEpisodes[episode]
//if data is undefined, send message back
if (kitsuEpisodes.data[0] == undefined) {
return message.channel.send(
"It seems this episode may not be on Kitsu"
);
} else {
//otherwise return the data back to parent
resolve(kitsuEpisodes.data);
}
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment