tracking watchlisted anime

master
Kit Kasune 3 years ago
parent 717868a192
commit 9e4aa580a8
  1. 56
      commands/anime/anime.js
  2. 4
      commands/anime/watched.js
  3. 11
      commands/anime/watchlist.js

@ -341,6 +341,36 @@ module.exports = {
if (['w', 'watched'].includes(args[0].toLowerCase())) { if (['w', 'watched'].includes(args[0].toLowerCase())) {
args.shift(); args.shift();
if (args[0] && ['v', 'view'].includes(args[0].toLowerCase())) {
if (mention) {args.shift();}
let user = mention || message.author;
let af = await AF.findOne({uid: user.id});
if (!af || !af.watched.length) {return message.channel.send(`${user.id === message.author.id ? "You haven't" : "That person hasn't"} watched any anime.`);}
let pages = [];
let pl = (Math.floor(af.watched.length / 10) + 1);
for (let i = 0; i < pl; i++) {
let s = '';
for (let x = 0; x < 10; x++) {
if (!af.watched[(i * 10) + x]) {break;}
s += `**${x + (i * 10) + 1}.** ${client.misc.cache.animeID.get(af.watched[(i * 10) + x])}\n`;
}
pages.push(new Discord.MessageEmbed()
.setAuthor({
name: message.guild ? message.guild.members.cache.get(user.id).displayName : user.username,
iconURL: message.guild ? message.guild.members.cache.get(user.id).displayAvatarURL({dynamic: true}) : user.displayAvatarURL({dynamic: true})
})
.setTitle("Finished Anime List")
.setDescription(s)
.setColor('c375f0')
.setTimestamp()
);
}
if (pages.length > 1) {
let pag = new Pagination(message.channel, pages, message, client, true);
return await pag.start({user: message.author.id, time: 60000});
} else {return message.channel.send({embeds: [pages[0].setFooter({text: "Natsuki"})]});}
}
if (!args[0]) { if (!args[0]) {
let tempchar = await ask(message, "What anime would you like to add to your finished list?", 60000, false, true); let tempchar = await ask(message, "What anime would you like to add to your finished list?", 60000, false, true);
if (!tempchar) {return;} if (!tempchar) {return;}
@ -353,33 +383,45 @@ module.exports = {
} else if (asr instanceof Pagination) { } else if (asr instanceof Pagination) {
await asr.start({user: message.author.id, startPage: 0, endTime: 60000}); await asr.start({user: message.author.id, startPage: 0, endTime: 60000});
await asr.message.react('✅'); await asr.message.react('✅');
await message.channel.send("React with :white_check_mark: when you've found the anime you want!"); let noticeDel = await message.channel.send("React with :white_check_mark: when you've found the anime you want!");
let arc; let arc;
try {arc = await asr.message.awaitReactions({filter: (r) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});} try {arc = await asr.message.awaitReactions({filter: (r) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});}
catch {return message.reply("Looks like you didn't find the anime you were looking for.");} catch {return message.reply("Looks like you didn't find the anime you were looking for.");}
collected = arc.first().emoji.name; collected = arc.first().emoji.name;
if (collected === '✅') { if (collected === '✅') {
fn = client.misc.cache.anime.get(asr.getCurrentPage().title.trim()); fn = client.misc.cache.anime.get(asr.getCurrentPage().title.trim());
asr.stop(); await asr.stop();
await asr.message.delete().catch(() => {});
await noticeDel.delete().catch(() => {});
} }
else {return message.reply("Looks like you didn't find the anime you were looking for.");} else {return message.reply("Looks like you didn't find the anime you were looking for.");}
} else { } else {
await message.channel.send({embeds: [asr.embed]}); let preConfEmbed = await message.channel.send({embeds: [asr.embed]});
let conf = await ask(message, "Is this the anime you meant?", 60000); let conf = await ask(message, "Is this the anime you meant?", 60000, undefined, undefined, true);
if (!['y', 'yes', 'ye', 'n', 'no'].includes(conf.trim().toLowerCase())) {clearDM(); return dmch.send("You must specify yes or no! Please try again.");} 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()); conf = ['y', 'yes', 'ye'].includes(conf.trim().toLowerCase());
preConfEmbed.delete().catch(() => {});
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.");} 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;} fn = asr.id;
}
let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.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!");} 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}); let tfc = await AniData.findOne({id: fn});
tfc.watchers += 1; tfc.watchers += 1;
tfc.markModified('watchers'); tfc.markModified('watchers');
tfc.save();
af.watched.push(fn); af.watched.push(fn);
af.markModified('watched'); af.markModified('watched');
let dw = false;
if (af.toWatch.includes(fn)) {
af.toWatch.splice(af.toWatch.indexOf(fn), 1);
af.markModified('toWatch');
tfc.listed--;
tfc.save();
dw = true;
}
af.save(); af.save();
return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!`); tfc.save();
return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!${dw ? " I've also removed it from your watch list for you :p" : ''}`);
} }
if (['nn', 'nickname', 'altname', 'nick', 'an'].includes(args[0].toLowerCase())) { if (['nn', 'nickname', 'altname', 'nick', 'an'].includes(args[0].toLowerCase())) {

@ -86,16 +86,18 @@ module.exports = {
let tfc = await AniData.findOne({id: fn}); let tfc = await AniData.findOne({id: fn});
tfc.watchers += 1; tfc.watchers += 1;
tfc.markModified('watchers'); tfc.markModified('watchers');
tfc.save();
af.watched.push(fn); af.watched.push(fn);
af.markModified('watched'); af.markModified('watched');
let dw = false; let dw = false;
if (af.toWatch.includes(fn)) { if (af.toWatch.includes(fn)) {
af.toWatch.splice(af.toWatch.indexOf(fn), 1); af.toWatch.splice(af.toWatch.indexOf(fn), 1);
af.markModified('toWatch'); af.markModified('toWatch');
tfc.listed--;
tfc.save();
dw = true; dw = true;
} }
af.save(); af.save();
tfc.save();
return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!${dw ? " I've also removed it from your watch list for you :p" : ''}`); return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!${dw ? " I've also removed it from your watch list for you :p" : ''}`);
} }
}; };

@ -1,6 +1,7 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const AF = require("../../models/anifav"); const AF = require("../../models/anifav");
const AniData = require('../../models/anime');
const {Pagination} = require('../../util/pagination'); const {Pagination} = require('../../util/pagination');
const ask = require('../../util/ask'); const ask = require('../../util/ask');
@ -89,9 +90,13 @@ module.exports = {
let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.id}); let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.id});
if (af.toWatch.includes(fn)) {return message.channel.send("Looks like that anime is already on your watch list!");} if (af.toWatch.includes(fn)) {return message.channel.send("Looks like that anime is already on your watch list!");}
if (af.watched.includes(fn)) {return message.channel.send("That anime is on your **watched** list already...");} if (af.watched.includes(fn)) {return message.channel.send("That anime is on your **watched** list already...");}
const tfc = await AniData.findOne({id: fn});
if (!tfc) {return message.channel.send("Huh... guess that anime just... vanished into thin air? I would go yell at my devs.");}
af.toWatch.push(fn); af.toWatch.push(fn);
af.markModified('toWatch'); af.markModified('toWatch');
af.save(); af.save();
tfc.listed++;
tfc.save();
return message.channel.send(`I've added **${client.misc.cache.animeID.get(fn)}** to your watch list! ${[`Let me know if it's any good when you get around to it :3`, `Hope it's good!`, 'Try not to wait *too* long before you watch it.', `I've heard good things about that one.`][Math.floor(Math.random() * 4)]}`); return message.channel.send(`I've added **${client.misc.cache.animeID.get(fn)}** to your watch list! ${[`Let me know if it's any good when you get around to it :3`, `Hope it's good!`, 'Try not to wait *too* long before you watch it.', `I've heard good things about that one.`][Math.floor(Math.random() * 4)]}`);
} }
@ -132,10 +137,14 @@ module.exports = {
fn = asr.id;} fn = asr.id;}
let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.id}); let af = await AF.findOne({uid: message.author.id}) || new AF({uid: message.author.id});
if (!af.toWatch.includes(fn)) {return message.channel.send("Looks like that anime isn't on your watch list!");} if (!af.toWatch.includes(fn)) {return message.channel.send("Looks like that anime isn't on your watch list!");}
const tfc = await AniData.findOne({id: fn});
if (!tfc) {return message.channel.send("Huh... guess that anime just... vanished into thin air? I would go yell at my devs.");}
af.toWatch.splice(af.toWatch.indexOf(fn), 1); af.toWatch.splice(af.toWatch.indexOf(fn), 1);
af.markModified('toWatch'); af.markModified('toWatch');
af.save(); af.save();
return message.channel.send(`${['Guess it wasn\'t worth the watch after all, huh?', 'Oof. Did you lose interest?', 'Got it, got it.', 'Okie dokie!'][Math.floor(Math.random() * 4)]} I've removed **${client.misc.cache.animeID.get(fn)}** from your watch list.`); tfc.listed--;
tfc.save();
return message.channel.send(`${['Guess it wasn\'t worth the watch after all, huh?', 'Oof. Did you lose interest? Well, either way,', 'Got it, got it.', 'Okie dokie!'][Math.floor(Math.random() * 4)]} I've removed **${client.misc.cache.animeID.get(fn)}** from your watch list.`);
} }
} }
}; };
Loading…
Cancel
Save