From 57dfc824a09177bdc9e0bf782e8128a54026b0e9 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 24 Dec 2021 01:37:03 -0700 Subject: [PATCH] access chars through nicknames --- util/anime/anisearch.js | 1 + util/anime/charsearch.js | 11 +++++++++-- util/cache.js | 2 +- util/cache/char.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/util/anime/anisearch.js b/util/anime/anisearch.js index c50624d..3060ac1 100644 --- a/util/anime/anisearch.js +++ b/util/anime/anisearch.js @@ -34,6 +34,7 @@ module.exports = async (message, client, search, threshold=-10000, type='full') if (attF) {return await me(attF);} const res = fz.go(search, Array.from(client.misc.cache.anime.keys()), {threshold: threshold, 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 = []; diff --git a/util/anime/charsearch.js b/util/anime/charsearch.js index 732a87b..d72ec35 100644 --- a/util/anime/charsearch.js +++ b/util/anime/charsearch.js @@ -7,10 +7,13 @@ const Char = require('../../models/char'); const {Pagination} = require("../../util/pagination"); module.exports = async (message, client, search, threshold=-10000, type='top') => { + let da = []; const me = async (char) => { + if (da.includes(client.misc.cache.chars.get(char))) {return 0;} let cch = char.anime ? char : await Char.findOne({id: client.misc.cache.chars.get(char)}); let ani = await Ani.findOne({id: cch.anime}); let forceAni = false; if (!ani) {forceAni = true;} + da.push(cch.id); return {embed: new Discord.MessageEmbed() .setTitle(cch.name) .setAuthor('Character Search', message.author.avatarURL()) @@ -27,11 +30,15 @@ module.exports = async (message, client, search, threshold=-10000, type='top') = if (attF) {return await me(attF);} const res = fz.go(search, Array.from(client.misc.cache.chars.keys()), {threshold: threshold, 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(ca => tp.push(me(ca))); + for (let i = 0; i < res.length; i++) { + const tres = await me(res[i]); + if (tres !== 0) {tp.push(tres);} + } tp = await Promise.all(tp); - return new Pagination(message.channel, tp.map(k => k.embed), message, client, true); + return tp.length > 1 ? new Pagination(message.channel, tp.map(k => k.embed), message, client, true) : tp[0]; } else {return await me(res[0]);} } \ No newline at end of file diff --git a/util/cache.js b/util/cache.js index 0b1c67c..df04b91 100644 --- a/util/cache.js +++ b/util/cache.js @@ -37,5 +37,5 @@ module.exports = async (client) => { let ora_chCache = ora("Caching Characters...").start(); await require('./cache/char')(client); ora_chCache.stop(); ora_chCache.clear(); - console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chars.size}`)} ${chalk.blueBright(`characters into lookup registry.`)}`); + console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.charsNum}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`); }; \ No newline at end of file diff --git a/util/cache/char.js b/util/cache/char.js index 0b4ec7b..6968f2a 100644 --- a/util/cache/char.js +++ b/util/cache/char.js @@ -10,7 +10,7 @@ module.exports = async client => { for await (const char of CharData.find()) { if (char.queued !== true) { client.misc.cache.chars.set(char.name, char.id); - chars.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id)); + char.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id)); client.misc.cache.charsID.set(char.id, char.name); client.misc.cache.charsNum++; }