From a9aaf9fbbc8aa5ffe18158a5e8b5727a6af755a1 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Mon, 20 Dec 2021 02:46:28 -0700 Subject: [PATCH] anime search char name rendering --- commands/anime/char.js | 7 ++++++- util/anime/anisearch.js | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/commands/anime/char.js b/commands/anime/char.js index f37ba76..9e1053d 100644 --- a/commands/anime/char.js +++ b/commands/anime/char.js @@ -144,7 +144,7 @@ module.exports = { .setTitle(`New Character -> ${options.name}`) .setDescription(`${queue ? 'Requested' : 'Added'} by ${message.author.tag}`) .addField('Info', `**Name:** ${options.name}`) - .addField('Other', `**Anime**: ${aniData.name} | ${aniData.japname} | \`${aniData.id}\`\n\n**Gender**: ${options.gender}\n`) + .addField('Other', `**Anime**: ${forceAni ? options.anime : `${aniData.name} | ${aniData.japname} | \`${aniData.id}\``}\n\n**Gender**: ${options.gender}\n`) .setColor("c375f0") .setImage(options.thumbnail) .setFooter('Natsuki', client.user.avatarURL()) @@ -165,6 +165,11 @@ module.exports = { while (true) {options.id = require('../../util/makeid')(4); if (!await Char.findOne({id: options.id})) {break;}} if (!queue) {options.queued = false;} await new Char(options).save(); + if (aniData) { + aniData.characters.push(options.id); + aniData.markModified('characters'); + aniData.save(); + } return message.author.send(`Your character has been ${!queue ? "added" : "submitted"}`); } else { return message.author.send("Oh, okay. I'll discard that then!"); diff --git a/util/anime/anisearch.js b/util/anime/anisearch.js index fa62197..ac81b46 100644 --- a/util/anime/anisearch.js +++ b/util/anime/anisearch.js @@ -2,12 +2,18 @@ const fz = require('fuzzysort'); const Discord = require('discord.js'); const Ani = require('../../models/anime'); +const Char = require('../../models/char'); const {Pagination} = require("../../util/pagination"); module.exports = async (message, client, search, threshold=-10000, type='top') => { const me = async (ani) => { let an = await Ani.findOne({id: client.misc.cache.anime.get(ani)}); + let chs = []; + for (let i = 0; i < an.characters.length; i++) { + let tch = await Char.findOne({id: an.characters[i]}); + if (tch) {chs.push(tch.name);} + } return {embed: new Discord.MessageEmbed() .setTitle(an.name) .setAuthor('Anime Search', message.author.avatarURL()) @@ -15,7 +21,7 @@ module.exports = async (message, client, search, threshold=-10000, type='top') = .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.join(", ")}\n**Tags:** ${an.tags.join(", ")}\n**Characters:** ${an.characters}\n**Stream this at:** ${an.streamAt}`) + .addField('Other', `**Genre(s):** ${an.genres.join(", ")}\n**Tags:** ${an.tags.join(", ")}\n**Characters:** ${chs.join(", ")}\n**Stream this at:** ${an.streamAt.join(" ")}`) .setColor("c375f0") .setImage(an.thumbnail) .setFooter('Natsuki', client.user.avatarURL())