anime searching now actually works yay

master
Kit Kasune 3 years ago
parent 9aaa88c60e
commit 2ba3bfd0fe
  1. 13
      commands/anime/anime.js
  2. 42
      commands/anime/char.js
  3. 20
      util/anime/anisearch.js

@ -18,6 +18,7 @@ module.exports = {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}anime <>\``);}
let queue = false;
let options = {};
let dmch;
if (['a', 'add', 'n', 'new'].includes(args[0])) {
let tu = await UserData.findOne({uid: message.author.id});
if (!tu || !tu.staff) {
@ -65,7 +66,7 @@ module.exports = {
if (message.guild) {await mesg.channel.send("Check your DMs!");}
function clearDM() {client.misc.activeDMs.delete(message.author.id);}
let dmch = mesg.channel;
dmch = mesg.channel;
options.name = await ask(mesg, "What is the anime's name?", 60000, true); if (!options.name) {return;}
if (options.name.length > 75) {clearDM(); return dmch.send("The anime name can't be more than 75 characters!");}
@ -141,20 +142,20 @@ module.exports = {
let amEmbed = new Discord.MessageEmbed()
.setTitle(`New Anime -> ${options.name}`)
.setDescription(`${queue ? 'Requested' : 'Added'} by ${message.author.tag}`)
.addField('Info', `**Name:** ${options.name}\n**Japanese Name:** ${options.japname}\n\n**Publishers:** ${foptions.publishers}\n**Studios:** ${foptions.studios}`)
.addField('Info', `**Name:** ${options.name}\n**Japanese Name:** ${options.japname}\n\n**Publishers:** ${foptions.publishers.join(", ")}\n**Studios:** ${foptions.studios.join(", ")}`)
.addField('Description', options.plot)
.addField('Length', `**# of Seasons:** ${options.seasons}\n**# of Episodes:** ${options.episodes}`)
.addField('Airing', `**Began:** ${options.airStartDate}\n**Ended:** ${options.isComplete ? options.airEndDate : 'This anime is still airing!'}`)
.addField('Other', `**Genre(s):** ${foptions.genres}\n**Tags:** ${foptions.tags}\n**Characters:** ${foptions.characters}\n**Stream this at:** ${foptions.streamAt}`)
.addField('Other', `**Genre(s):** ${foptions.genres.join(", ")}\n**Tags:** ${foptions.tags.join(", ")}\n**Characters:** ${foptions.characters}\n**Stream this at:** ${foptions.streamAt}`)
.setColor("c375f0")
.setImage(options.thumbnail)
.setFooter('Natsuki', client.user.avatarURL())
.setTimestamp();
try {
am = await message.channel.send({embeds: [amEmbed]});
am = await dmch.send({embeds: [amEmbed]});
await am.react('👍');
await am.react('👎');
} catch {return message.channel.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");}
} catch {return dmch.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");}
try {
let rc = am.createReactionCollector({filter: (r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, max: 1, time: 60000});
rc.on("collect", async r => {
@ -171,7 +172,7 @@ module.exports = {
}
});
rc.on("end", collected => {if (!collected.size) {return message.author.send("Looks like you ran out of time! Try again?");}});
} catch {return message.channel.send("Hmm... there was some kind of error when I tried to submit that anime. Try again, and if it keeps not working, then go yell at my devs!");}
} catch {return message.author.send("Hmm... there was some kind of error when I tried to submit that anime. Try again, and if it keeps not working, then go yell at my devs!");}
}
}
};

@ -2,6 +2,7 @@ const Discord = require('discord.js');
const UserData = require('../../models/user');
const Char = require('../../models/char');
const AniData = require('../../models/anime');
const {Tag} = require('../../util/tag');
const {TagFilter} = require('../../util/tagfilter');
@ -26,7 +27,9 @@ module.exports = {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}char\``);}
let queue = false;
let forceAni = false;
let options = {};
let dmch;
if (['a', 'add', 'n', 'new'].includes(args[0])) {
let tu = await UserData.findOne({uid: message.author.id});
if (!tu || !tu.staff) {
@ -67,28 +70,40 @@ module.exports = {
if (message.guild) {await mesg.channel.send("Check your DMs!");}
function clearDM() {client.misc.activeDMs.delete(message.author.id);}
let dmch = mesg.channel;
dmch = mesg.channel;
options.name = await ask(mesg, "What is the character's name?", 60000, true); if (!options.name) {return;}
if (options.name.length > 75) {clearDM(); return dmch.send("The character name can't be more than 75 characters!");}
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;}
options.anime = await ask(mesg, "What anime (or game) did the character appear in? If the character is an OC, say 'none'", 60000, 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 (asr === 0) {
let conf = await ask(mesg, "That search returned no results. Would you like me to put the anime you specified down anyways? Otherwise, I'll abandon this process, and we can try again.", 60000, true);
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) {
clearDM();
return dmch.send("Okay! You can try remaking the character if you'd like.");
} else {
forceAni = true;
fn = options.anime;
}
}
else {
} else if (asr instanceof Pagination) {
await asr.start({user: message.author.id, startPage: 1, endTime: 60000});
await asr.message.react('✅');
await dmch.send("React with :white_check_mark: when you've found the anime you want!");
let arc;
try {arc = await asr.message.awaitReactions({filter: (r, u) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});}
catch {return dmch.send("Looks like you didn't find the anime you were looking for, so I went ahead and ended the character creation for you.");}
collected = arc.first().emoji.name;
if (collected === '✅') {fn = client.misc.cache.anime.get(asr.getCurrentPage().title.trim());}
else {return dmch.send("Looks like you didn't find the anime you were looking for, so I went ahead and ended the character creation for you.");}
} else {
await dmch.send({embeds: [asr.embed]});
let conf = await ask(mesg, "Is this the anime you meant?");
let conf = await ask(mesg, "Is this the anime you meant?", 60000, true);
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.");}
@ -121,20 +136,21 @@ module.exports = {
}
}
if (!options.characters) {options.characters = [];}
let aniData = await AniData.findOne({id: options.anime});
let amEmbed = new Discord.MessageEmbed()
.setTitle(`New Character -> ${options.name}`)
.setDescription(`${queue ? 'Requested' : 'Added'} by ${message.author.tag}`)
.addField('Info', `**Name:** ${options.name}`)
.addField('Other', `**Anime**: ${options.anime}\n**Gender**: ${options.gender}\n`)
.addField('Other', `**Anime**: ${aniData.name} | ${aniData.japname} | \`${aniData.id}\`\n\n**Gender**: ${options.gender}\n`)
.setColor("c375f0")
.setImage(options.thumbnail)
.setFooter('Natsuki', client.user.avatarURL())
.setTimestamp();
try {
am = await message.channel.send({embeds: [amEmbed]});
am = await dmch.send({embeds: [amEmbed]});
await am.react('👍');
await am.react('👎');
} catch {return message.channel.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");}
} catch {return dmch.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");}
try {
let rc = am.createReactionCollector({filter: (r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, max: 1, time: 60000});
rc.on("collect", async r => {
@ -151,7 +167,7 @@ module.exports = {
}
});
rc.on("end", collected => {if (!collected.size) {return message.author.send("Looks like you ran out of time! Try again?");}});
} catch {return message.channel.send("Hmm... there was some kind of error when I tried to submit that character. Try again, and if it keeps not working, then go yell at my devs!");}
} catch {return message.author.send("Hmm... there was some kind of error when I tried to submit that character. Try again, and if it keeps not working, then go yell at my devs!");}
}
}
};

@ -6,27 +6,31 @@ 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}`)
.setDescription(`**Name:** ${an.name}\n**Japanese Name:** ${an.japname}\n\n**Publishers:** ${an.publishers.join(", ")}\n**Studios:** ${an.studios.join(", ")}`)
.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}`)
.addField('Other', `**Genre(s):** ${an.genres.join(", ")}\n**Tags:** ${an.tags.join(", ")}\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 attF = await Ani.findOne({id: search.trim().toLowerCase()});
if (attF) {return await me(res[0]);}
const res = fz.go(search, Array.from(client.misc.cache.anime.keys()), {limit: 10}).sort((a,b)=>a.score-b.score).map(k => k.target);
if (res.length === 0) {return 0;}
else 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;
await res.forEach(ca => tp.push(me(ca)));
tp = await Promise.all(tp);
return new Pagination(message.channel, tp.map(k => k.embed), message, client, true);
} else {return await me(res[0]);}
}
Loading…
Cancel
Save