access chars through nicknames

master
Kit Kasune 3 years ago
parent 61ad632994
commit 57dfc824a0
  1. 1
      util/anime/anisearch.js
  2. 11
      util/anime/charsearch.js
  3. 2
      util/cache.js
  4. 2
      util/cache/char.js

@ -34,6 +34,7 @@ module.exports = async (message, client, search, threshold=-10000, type='full')
if (attF) {return await me(attF);} 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); 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;} if (res.length === 0) {return 0;}
else if (res.length > 1) { else if (res.length > 1) {
let tp = []; let tp = [];

@ -7,10 +7,13 @@ const Char = require('../../models/char');
const {Pagination} = require("../../util/pagination"); const {Pagination} = require("../../util/pagination");
module.exports = async (message, client, search, threshold=-10000, type='top') => { module.exports = async (message, client, search, threshold=-10000, type='top') => {
let da = [];
const me = async (char) => { 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 cch = char.anime ? char : await Char.findOne({id: client.misc.cache.chars.get(char)});
let ani = await Ani.findOne({id: cch.anime}); let ani = await Ani.findOne({id: cch.anime});
let forceAni = false; if (!ani) {forceAni = true;} let forceAni = false; if (!ani) {forceAni = true;}
da.push(cch.id);
return {embed: new Discord.MessageEmbed() return {embed: new Discord.MessageEmbed()
.setTitle(cch.name) .setTitle(cch.name)
.setAuthor('Character Search', message.author.avatarURL()) .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);} 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); 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;} if (res.length === 0) {return 0;}
else if (res.length > 1) { else if (res.length > 1) {
let tp = []; 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); 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]);} } else {return await me(res[0]);}
} }

@ -37,5 +37,5 @@ module.exports = async (client) => {
let ora_chCache = ora("Caching Characters...").start(); let ora_chCache = ora("Caching Characters...").start();
await require('./cache/char')(client); await require('./cache/char')(client);
ora_chCache.stop(); ora_chCache.clear(); 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)`)}`);
}; };

@ -10,7 +10,7 @@ module.exports = async client => {
for await (const char of CharData.find()) { for await (const char of CharData.find()) {
if (char.queued !== true) { if (char.queued !== true) {
client.misc.cache.chars.set(char.name, char.id); 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.charsID.set(char.id, char.name);
client.misc.cache.charsNum++; client.misc.cache.charsNum++;
} }

Loading…
Cancel
Save