anime searching. this is literal hell

master
Kit Kasune 3 years ago
parent 8b80225340
commit 880d07e300
  1. 23
      commands/anime/char.js
  2. 32
      util/anime/anisearch.js

@ -6,6 +6,8 @@ const Char = require('../../models/char');
const {Tag} = require('../../util/tag');
const {TagFilter} = require('../../util/tagfilter');
const ask = require('../../util/ask');
const ans = require('../../util/anime/anisearch');
const {Pagination} = require('../../util/pagination');
module.exports = {
name: "char",
@ -73,6 +75,27 @@ module.exports = {
options.anime = await ask(mesg, "What anime (or game) did the character appear in? If the character is an OC, say 'none'", 6000, true); if (!options.anime) {return;}
if (options.anime.length > 75) {clearDM(); return dmch.send("The anime name can't be more than 75 characters!");}
if (options.anime.trim().toLowerCase() === 'none') {options.anime = null;}
else {
let asr = await ans(mesg, client, options.anime.trim().toLowerCase());
if (asr instanceof Pagination) {
await dmch.send({embeds: [asr.pages[0]]});
let conf = await ask(mesg, "Is this the anime you meant?");
if (!['y', 'yes', 'ye', 'n', 'no'].includes(conf.trim().toLowerCase())) {clearDM(); return dmch.send("You must specify yes or no! Please try again.");}
conf = ['y', 'yes', 'ye'].includes(conf.trim().toLowerCase());
if (!conf) {
}
}
else {
await dmch.send({embeds: [asr.embed]});
let conf = await ask(mesg, "Is this the anime you meant?");
if (!['y', 'yes', 'ye', 'n', 'no'].includes(conf.trim().toLowerCase())) {clearDM(); return dmch.send("You must specify yes or no! Please try again.");}
conf = ['y', 'yes', 'ye'].includes(conf.trim().toLowerCase());
if (!conf) {return mesg.channel.send("Well, I've got nothing, then. If that doesn't match the anime you're looking for then I would try again with a more narrow search.");}
fn = asr.id;
}
options.anime = fn;
}
options.gender = await ask(mesg, "What is the character's gender?", 60000, true); if (!options.name) {return;}
if (options.gender.length > 75) {clearDM(); return dmch.send("That's one heck of a gender. Maybe like... abbreviate?");}

@ -0,0 +1,32 @@
const fz = require('fuzzysort');
const Discord = require('discord.js');
const Ani = require('../../models/anime');
const {Pagination} = require("../../util/pagination");
module.exports = async (message, client, search, type='top') => {
const res = fz.go(search, Array.from(client.misc.cache.anime.keys()), {threshold: -300, limit: 10}).sort((a,b)=>a.score-b.score).map(k => k.target);
const me = async (ani) => {
let an = await Ani.findOne({id: client.misc.cache.anime.get(ani)});
return {embed: new Discord.MessageEmbed()
.setTitle(an.name)
.setAuthor('Anime Search', message.author.avatarURL())
.addField('Info', `**Name:** ${an.name}\n**Japanese Name:** ${an.japname}\n\n**Publishers:** ${an.publishers}\n**Studios:** ${an.studios}`)
.addField('Description', an.plot)
.addField('Length', `**# of Seasons:** ${an.seasons}\n**# of Episodes:** ${an.episodes}`)
.addField('Airing', `**Began:** ${an.airStartDate}\n**Ended:** ${an.isComplete ? an.airEndDate : 'This anime is still airing!'}`)
.addField('Other', `**Genre(s):** ${an.genres}\n**Tags:** ${an.tags}\n**Characters:** ${an.characters}\n**Stream this at:** ${an.streamAt}`)
.setColor("c375f0")
.setImage(an.thumbnail)
.setFooter('Natsuki', client.user.avatarURL())
.setTimestamp(), id: an.id};
};
if (res.length > 1) {
let tp = [];
await res.forEach(async ca => tp.push(await me(ca)));
let pag = new Pagination(message.channel, tp.map(k => k.embed), message, client, true);
pag.ids = tp.map(k => k.id);
return pag;
} else {return await me(res[0]);}
}
Loading…
Cancel
Save