From 287f22dea1cab90c58ab766c7ae86e11c1ad4bdc Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Mon, 20 Dec 2021 18:23:31 -0700 Subject: [PATCH] add anime to your watchlist --- commands/anime/anime.js | 49 +++++++++++++++++++++++++++++++++++++++++ commands/anime/char.js | 20 +++++++++-------- models/anifav.js | 11 +++++++++ util/anime/anisearch.js | 17 ++++++++------ 4 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 models/anifav.js diff --git a/commands/anime/anime.js b/commands/anime/anime.js index 4ea0805..93440e6 100644 --- a/commands/anime/anime.js +++ b/commands/anime/anime.js @@ -2,6 +2,7 @@ const Discord = require('discord.js'); const UserData = require('../../models/user'); const AniData = require('../../models/anime'); +const AF = require('../../models/anifav'); const {TagFilter} = require("../../util/tagfilter"); 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?");}}); } 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())) { args.shift(); if (!args[0]) { @@ -198,6 +200,7 @@ module.exports = { } return; } + if (['v', 'view'].includes(args[0].trim().toLowerCase())) { args.shift(); if (!args[0]) { @@ -215,6 +218,7 @@ module.exports = { } return; } + if (['reject'].includes(args[0].trim().toLowerCase())) { 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!");} @@ -225,9 +229,54 @@ module.exports = { .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*");}); } + if (['r', 'rand', 'random', 'any'].includes(args[0].toLowerCase())) { let asr = await ans(message, client, client.misc.cache.anime.random(), -100000); 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!`); + } } }; diff --git a/commands/anime/char.js b/commands/anime/char.js index d919c65..417c175 100644 --- a/commands/anime/char.js +++ b/commands/anime/char.js @@ -15,19 +15,19 @@ const {Pagination} = require('../../util/pagination'); module.exports = { name: "char", aliases: ['ch', 'character'], - /*meta: { + meta: { category: 'Anime', - description: "", - syntax: '` <>`', + description: "Get info on and view anime characters", + syntax: '`char `', extra: null - },*/ + }, help: new Discord.MessageEmbed() .setTitle("Help -> Characters") .setDescription("Incomplete command, please stand by <3") - .addField("Syntax", "`char`"), + .addField("Syntax", "`char `"), 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 \``);} + let queue = false; let forceAni = false; let options = {}; @@ -248,7 +248,7 @@ module.exports = { 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.");} + catch {return message.reply("Looks like you didn't find the character you were looking for.");} collected = arc.first().emoji.name; if (collected === '✅') { fn = client.misc.cache.chars.get(asr.getCurrentPage().title.trim()); @@ -264,7 +264,7 @@ module.exports = { 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!");} + 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}); tfc.loved += 1; tfc.markModified('loved'); @@ -289,5 +289,7 @@ module.exports = { .setTimestamp() ]}); } + + return message.channel.send(`Invalid arg! Syntax: \`${prefix}char \``); } }; \ No newline at end of file diff --git a/models/anifav.js b/models/anifav.js new file mode 100644 index 0000000..b22c8a8 --- /dev/null +++ b/models/anifav.js @@ -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); \ No newline at end of file diff --git a/util/anime/anisearch.js b/util/anime/anisearch.js index f3713db..4bfa632 100644 --- a/util/anime/anisearch.js +++ b/util/anime/anisearch.js @@ -6,7 +6,7 @@ const Char = require('../../models/char'); 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) => { let an = ani.plot ? ani : await Ani.findOne({id: client.misc.cache.anime.get(ani)}); 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]}); if (tch) {chs.push(tch.name);} } - return {embed: new Discord.MessageEmbed() + let rte = new Discord.MessageEmbed() .setTitle(an.name) .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(", ")}`) - .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") .setImage(an.thumbnail) .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()});