character favoriting

master
Kit Kasune 3 years ago
parent 6ca62cf066
commit 6c003df8f7
  1. 10
      commands/anime/anime.js
  2. 57
      commands/anime/char.js
  3. 8
      models/charfav.js
  4. 1
      util/anime/charsearch.js

@ -183,6 +183,11 @@ module.exports = {
} }
if (['s', 'search'].includes(args[0].trim().toLowerCase())) { if (['s', 'search'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What anime would you like to search for?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await ans(message, client, args.join(" ").trim().toLowerCase()); let asr = await ans(message, client, args.join(" ").trim().toLowerCase());
if (asr === 0) { if (asr === 0) {
return message.channel.send("That search returned no results! Try again?"); return message.channel.send("That search returned no results! Try again?");
@ -195,6 +200,11 @@ module.exports = {
} }
if (['v', 'view'].includes(args[0].trim().toLowerCase())) { if (['v', 'view'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What anime would you like to view?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await ans(message, client, args.join(" ").trim().toLowerCase(), -700); let asr = await ans(message, client, args.join(" ").trim().toLowerCase(), -700);
if (asr === 0) { if (asr === 0) {
return message.channel.send("That search returned no results! Try again?"); return message.channel.send("That search returned no results! Try again?");

@ -3,6 +3,7 @@ const Discord = require('discord.js');
const UserData = require('../../models/user'); const UserData = require('../../models/user');
const Char = require('../../models/char'); const Char = require('../../models/char');
const AniData = require('../../models/anime'); const AniData = require('../../models/anime');
const CF = require('../../models/charfav');
const {Tag} = require('../../util/tag'); const {Tag} = require('../../util/tag');
const {TagFilter} = require('../../util/tagfilter'); const {TagFilter} = require('../../util/tagfilter');
@ -184,6 +185,11 @@ module.exports = {
} }
if (['s', 'search'].includes(args[0].trim().toLowerCase())) { if (['s', 'search'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What character would you like to search for?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await chs(message, client, args.join(" ").trim().toLowerCase(), -100000); let asr = await chs(message, client, args.join(" ").trim().toLowerCase(), -100000);
if (asr === 0) { if (asr === 0) {
return message.channel.send("That search returned no results! Try again?"); return message.channel.send("That search returned no results! Try again?");
@ -196,6 +202,11 @@ module.exports = {
} }
if (['v', 'view'].includes(args[0].trim().toLowerCase())) { if (['v', 'view'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What character would you like to view?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await chs(message, client, args.join(" ").trim().toLowerCase(), -700); let asr = await chs(message, client, args.join(" ").trim().toLowerCase(), -700);
if (asr === 0) { if (asr === 0) {
return message.channel.send("That search returned no results! Try again?"); return message.channel.send("That search returned no results! Try again?");
@ -220,5 +231,51 @@ module.exports = {
let asr = await chs(message, client, client.misc.cache.chars.random(), -100000); let asr = await chs(message, client, client.misc.cache.chars.random(), -100000);
return await message.channel.send({embeds: [asr.embed]}); return await message.channel.send({embeds: [asr.embed]});
} }
if (['l', 'love', 'favorite', 'fav'].includes(args[0].toLowerCase())) {
args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What character would you like to add to your favorites list?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await chs(message, client, args.join(" ").trim().toLowerCase(), -700);
let fn;
if (asr === 0) {
return message.channel.send("That search returned no results! Try again?");
} else if (asr instanceof Pagination) {
await asr.start({user: message.author.id, startPage: 1, endTime: 60000});
await asr.message.react('✅');
await message.channel.send("React with :white_check_mark: when you've found the character you want!");
let arc;
try {arc = await asr.message.awaitReactions({filter: (r, u) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});}
catch {return message.channel.send("Looks like you didn't find the character 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.chars.get(asr.getCurrentPage().title.trim());
asr.stop();
}
else {return message.reply("Looks like you didn't find the character you were looking for.");}
} else {
await message.channel.send({embeds: [asr.embed]});
let conf = await ask(message, "Is this the character you meant?", 60000);
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 message.channel.send("Well, I've got nothing, then. If that doesn't match the character you're looking for then I would try again with a more narrow search.");}
fn = asr.id;
}
let cf = await CF.findOne({uid: message.author.id}) || new CF({uid: message.author.id});
if (cf.loved.includes(fn)) {return message.channel.send("Look like that character is already on your loved list!");}
let tfc = await Char.findOne({id: fn});
tfc.loved += 1;
tfc.markModified('loved');
tfc.save();
cf.loved.push(fn);
cf.markModified('loved');
cf.save();
return message.channel.send(`I've added **${tfc.name}** to your loved/favorited character list!`);
}
if (['loved', 'favorites', 'favs'].includes(args[0].toLowerCase())) {
}
} }
}; };

@ -0,0 +1,8 @@
const mongoose = require('mongoose');
const cf = new mongoose.Schema({
uid: {type: String, unique: true},
loved: {type: [String], default: []}
});
module.exports = mongoose.model('charfav', cf);

@ -16,6 +16,7 @@ module.exports = async (message, client, search, threshold=-10000, type='top') =
.setAuthor('Character Search', message.author.avatarURL()) .setAuthor('Character Search', message.author.avatarURL())
.setDescription(`**Name:** ${cch.name}`) .setDescription(`**Name:** ${cch.name}`)
.addField('Other', `**Anime**: ${forceAni ? cch.anime : `${ani.name} | ${ani.japname} | \`${ani.id}\``}\n\n**Gender**: ${cch.gender}\n`) .addField('Other', `**Anime**: ${forceAni ? cch.anime : `${ani.name} | ${ani.japname} | \`${ani.id}\``}\n\n**Gender**: ${cch.gender}\n`)
.addField("Loved by", `**${cch.loved}** Natsuki user${cch.loved === 1 ? '' : 's'}!\n\`char love ${cch.name}\``)
.setColor("c375f0") .setColor("c375f0")
.setImage(cch.thumbnail) .setImage(cch.thumbnail)
.setFooter('Natsuki', client.user.avatarURL()) .setFooter('Natsuki', client.user.avatarURL())

Loading…
Cancel
Save