add anime to your watchlist

master
Kit Kasune 3 years ago
parent 785547c2e6
commit 287f22dea1
  1. 49
      commands/anime/anime.js
  2. 18
      commands/anime/char.js
  3. 11
      models/anifav.js
  4. 17
      util/anime/anisearch.js

@ -2,6 +2,7 @@ const Discord = require('discord.js');
const UserData = require('../../models/user'); const UserData = require('../../models/user');
const AniData = require('../../models/anime'); const AniData = require('../../models/anime');
const AF = require('../../models/anifav');
const {TagFilter} = require("../../util/tagfilter"); const {TagFilter} = require("../../util/tagfilter");
const {Tag} = require ("../../util/tag"); const {Tag} = require ("../../util/tag");
@ -181,6 +182,7 @@ module.exports = {
rc.on("end", collected => {if (!collected.size) {return message.author.send("Looks like you ran out of time! Try again?");}}); rc.on("end", collected => {if (!collected.size) {return message.author.send("Looks like you ran out of time! Try again?");}});
} 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!");} } 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!");}
} }
if (['s', 'search'].includes(args[0].trim().toLowerCase())) { if (['s', 'search'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) { if (!args[0]) {
@ -198,6 +200,7 @@ module.exports = {
} }
return; return;
} }
if (['v', 'view'].includes(args[0].trim().toLowerCase())) { if (['v', 'view'].includes(args[0].trim().toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) { if (!args[0]) {
@ -215,6 +218,7 @@ module.exports = {
} }
return; return;
} }
if (['reject'].includes(args[0].trim().toLowerCase())) { if (['reject'].includes(args[0].trim().toLowerCase())) {
let tu = await UserData.findOne({uid: message.author.id}); let tu = await UserData.findOne({uid: message.author.id});
if (!tu || !tu.staff) {await message.channel.send("Since you aren't a Natsuki Staff member, you can't reject anime submissions!");} if (!tu || !tu.staff) {await message.channel.send("Since you aren't a Natsuki Staff member, you can't reject anime submissions!");}
@ -225,9 +229,54 @@ module.exports = {
.then(() => {return message.channel.send("I got that submission out of here!");}) .then(() => {return message.channel.send("I got that submission out of here!");})
.catch(() => {return message.reply("It seems that submission wasn't deleted for some reason. \*insert head scratching*");}); .catch(() => {return message.reply("It seems that submission wasn't deleted for some reason. \*insert head scratching*");});
} }
if (['r', 'rand', 'random', 'any'].includes(args[0].toLowerCase())) { if (['r', 'rand', 'random', 'any'].includes(args[0].toLowerCase())) {
let asr = await ans(message, client, client.misc.cache.anime.random(), -100000); let asr = await ans(message, client, client.misc.cache.anime.random(), -100000);
return await message.channel.send({embeds: [asr.embed]}); return await message.channel.send({embeds: [asr.embed]});
} }
if (['w', 'watched'].includes(args[0].toLowerCase())) {
args.shift();
if (!args[0]) {
let tempchar = await ask(message, "What anime would you like to add to your finished list?", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
let asr = await ans(message, client, args.join(" ").trim().toLowerCase(), -700, 0);
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 anime you want!");
let arc;
try {arc = await asr.message.awaitReactions({filter: (r, u) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});}
catch {return message.reply("Looks like you didn't find the anime you were looking for.");}
collected = arc.first().emoji.name;
if (collected === '✅') {
fn = client.misc.cache.anime.get(asr.getCurrentPage().title.trim());
asr.stop();
}
else {return message.reply("Looks like you didn't find the anime you were looking for.");}
} else {
await message.channel.send({embeds: [asr.embed]});
let conf = await ask(message, "Is this the anime 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 anime you're looking for then I would try again with a more narrow search.");}
fn = asr.id;
}
let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.id});
if (af.watched.includes(fn)) {return message.channel.send("Looks like that anime is already on your finished list!");}
let tfc = await AniData.findOne({id: fn});
tfc.watchers += 1;
tfc.markModified('watchers');
tfc.save();
af.watched.push(fn);
af.markModified('watched');
af.save();
return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!`);
}
} }
}; };

@ -15,18 +15,18 @@ const {Pagination} = require('../../util/pagination');
module.exports = { module.exports = {
name: "char", name: "char",
aliases: ['ch', 'character'], aliases: ['ch', 'character'],
/*meta: { meta: {
category: 'Anime', category: 'Anime',
description: "", description: "Get info on and view anime characters",
syntax: '` <>`', syntax: '`char <add|view|search|random|love|loved>`',
extra: null extra: null
},*/ },
help: new Discord.MessageEmbed() help: new Discord.MessageEmbed()
.setTitle("Help -> Characters") .setTitle("Help -> Characters")
.setDescription("Incomplete command, please stand by <3") .setDescription("Incomplete command, please stand by <3")
.addField("Syntax", "`char`"), .addField("Syntax", "`char <add|view|search|random|love|loved>`"),
async execute(message, msg, args, cmd, prefix, mention, client) { async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}char\``);} if (!args.length) {return message.channel.send(`Syntax: \`${prefix}char <add|view|search|random|love|loved>\``);}
let queue = false; let queue = false;
let forceAni = false; let forceAni = false;
@ -248,7 +248,7 @@ module.exports = {
await message.channel.send("React with :white_check_mark: when you've found the character you want!"); await message.channel.send("React with :white_check_mark: when you've found the character you want!");
let arc; let arc;
try {arc = await asr.message.awaitReactions({filter: (r, u) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});} 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.");} catch {return message.reply("Looks like you didn't find the character you were looking for.");}
collected = arc.first().emoji.name; collected = arc.first().emoji.name;
if (collected === '✅') { if (collected === '✅') {
fn = client.misc.cache.chars.get(asr.getCurrentPage().title.trim()); fn = client.misc.cache.chars.get(asr.getCurrentPage().title.trim());
@ -264,7 +264,7 @@ module.exports = {
fn = asr.id; fn = asr.id;
} }
let cf = await CF.findOne({uid: message.author.id}) || new CF({uid: message.author.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!");} if (cf.loved.includes(fn)) {return message.channel.send("Looks like that character is already on your loved list!");}
let tfc = await Char.findOne({id: fn}); let tfc = await Char.findOne({id: fn});
tfc.loved += 1; tfc.loved += 1;
tfc.markModified('loved'); tfc.markModified('loved');
@ -289,5 +289,7 @@ module.exports = {
.setTimestamp() .setTimestamp()
]}); ]});
} }
return message.channel.send(`Invalid arg! Syntax: \`${prefix}char <add|view|search|random|love|loved>\``);
} }
}; };

@ -0,0 +1,11 @@
const mongoose = require('mongoose');
const af = new mongoose.Schema({
uid: {type: String, unique: true},
watched: {type: [String], default: []},
liked: {type: [String], default: []},
toWatch: {type: [String], default: []},
ratings: {type: [Object], default: {}}
});
module.exports = mongoose.model('anifav', af);

@ -6,7 +6,7 @@ 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='full') => {
const me = async (ani) => { const me = async (ani) => {
let an = ani.plot ? ani : await Ani.findOne({id: client.misc.cache.anime.get(ani)}); let an = ani.plot ? ani : await Ani.findOne({id: client.misc.cache.anime.get(ani)});
let chs = []; let chs = [];
@ -14,18 +14,21 @@ module.exports = async (message, client, search, threshold=-10000, type='top') =
let tch = await Char.findOne({id: an.characters[i]}); let tch = await Char.findOne({id: an.characters[i]});
if (tch) {chs.push(tch.name);} if (tch) {chs.push(tch.name);}
} }
return {embed: new Discord.MessageEmbed() let rte = new Discord.MessageEmbed()
.setTitle(an.name) .setTitle(an.name)
.setAuthor('Anime Search', message.author.avatarURL()) .setAuthor('Anime Search', message.author.avatarURL())
.setDescription(`**Name:** ${an.name}\n**Japanese Name:** ${an.japname}\n\n**Publishers:** ${an.publishers.join(", ")}\n**Studios:** ${an.studios.join(", ")}`) .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.join(", ")}\n**Tags:** ${an.tags.join(", ")}\n**Characters:** ${chs.join(", ")}\n**Stream this at:** ${an.streamAt.join(", ")}`)
.setColor("c375f0") .setColor("c375f0")
.setImage(an.thumbnail) .setImage(an.thumbnail)
.setFooter('Natsuki', client.user.avatarURL()) .setFooter('Natsuki', client.user.avatarURL())
.setTimestamp(), id: an.id}; .setTimestamp()
if (type === 'full') {
rte.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:** ${chs.join(", ")}\n**Stream this at:** ${an.streamAt.join(", ")}`)
}
return {embed: rte, id: an.id};
}; };
let attF = await Ani.findOne({id: search.trim().toLowerCase()}); let attF = await Ani.findOne({id: search.trim().toLowerCase()});

Loading…
Cancel
Save