way more stable char commands

master
Kit Kasune 3 years ago
parent e49b609c97
commit 56858145e8
  1. 20
      .idea/workspace.xml
  2. 119
      commands/anime/char.js
  3. 12
      commands/anime/charimage.js
  4. 4
      util/cache/char.js

@ -5,17 +5,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="start on 0th page for anime paginations"> <list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="start on 0th page for anime paginations">
<change beforePath="$PROJECT_DIR$/commands/anime/anime.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/anime.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/animeimage.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/animeimage.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/animenick.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/animenick.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/char.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/char.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/commands/anime/char.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/char.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/charimage.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/charimage.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/commands/anime/charimage.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/charimage.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/charnick.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/charnick.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/cache/char.js" beforeDir="false" afterPath="$PROJECT_DIR$/util/cache/char.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/haswatched.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/haswatched.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/highvalue.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/highvalue.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/lovechar.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/lovechar.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/watched.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/watched.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/watchlist.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/watchlist.js" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -161,7 +154,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1642551387709</updated> <updated>1642551387709</updated>
</task> </task>
<option name="localTasksCounter" value="7" /> <task id="LOCAL-00007" summary="start on 0th page for anime paginations">
<created>1642551629134</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1642551629134</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">

@ -47,7 +47,8 @@ module.exports = {
new Tag(['img', 'image', 'i'], 'images', 'listAppend'), new Tag(['img', 'image', 'i'], 'images', 'listAppend'),
new Tag(['loveInterest', 'dating', 'married', 'li'], 'loveInterest', 'append'), new Tag(['loveInterest', 'dating', 'married', 'li'], 'loveInterest', 'append'),
new Tag(['gender', 'g', 'sex'], 'gender', 'append'), new Tag(['gender', 'g', 'sex'], 'gender', 'append'),
new Tag(['nickname', 'nn', 'nick'], 'nicknames', 'listAppend') new Tag(['nickname', 'nn', 'nick'], 'nicknames', 'listAppend'),
new Tag(['force', 'f'], 'force', 'toggle')
]).test(args.slice(1).join(' ')); ]).test(args.slice(1).join(' '));
if (Object.keys(options).length) { if (Object.keys(options).length) {
@ -60,7 +61,7 @@ module.exports = {
let att = Array.from(message.attachments.keys()); let att = Array.from(message.attachments.keys());
if (message.attachments.size > 1) { if (message.attachments.size > 1) {
for (let i = 1; i < att.length; i++) { for (let i = 1; i < att.length; i++) {
options.images.push(message.attachments.get(att[i].url)); options.images.push(message.attachments.get(att[i]).url);
} }
} }
options.thumbnail = message.attachments.get(att[0]).url; options.thumbnail = message.attachments.get(att[0]).url;
@ -191,57 +192,59 @@ module.exports = {
.setImage(options.thumbnail) .setImage(options.thumbnail)
.setFooter({text: "Natsuki", iconURL: client.user.avatarURL()}) .setFooter({text: "Natsuki", iconURL: client.user.avatarURL()})
.setTimestamp(); .setTimestamp();
try { const addChar = async () => {
am = await dmch.send({embeds: [amEmbed]}); while (true) {options.id = require('../../util/makeid')(4); if (!await Char.findOne({id: options.id})) {break;}}
await am.react('👍').catch(() => {}); if (!queue) {
await am.react('👎').catch(() => {}); amEmbed.addField("Reviewed", `Reviewed and submitted by <@${message.author.id}>`);
} catch {return dmch.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");} client.misc.cache.chars.set(options.name, options.id);
try { client.misc.cache.charsID.set(options.id, options.name);
let rc = am.createReactionCollector({filter: (r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, max: 1, time: 60000}); }
rc.on("collect", async r => { else {amEmbed.addField("ID", options.id);}
if (r.emoji.name !== '👎') { amEmbed.setAuthor({name: !queue ? "Character Added" : "Character Submitted", iconURL: message.author.avatarURL()});
while (true) {options.id = require('../../util/makeid')(4); if (!await Char.findOne({id: options.id})) {break;}} if (!queue) {options.queued = false;}
if (!queue) { await new Char(options).save();
amEmbed.addField("Reviewed", `Reviewed and submitted by <@${message.author.id}>`); if (aniData) {
client.misc.cache.chars.set(options.name, options.id); aniData.characters.push(options.id);
client.misc.cache.charsID.set(options.id, options.name); aniData.markModified('characters');
} aniData.save();
else {amEmbed.addField("ID", options.id);} }
amEmbed.setAuthor({name: !queue ? "Character Added" : "Character Submitted", iconURL: message.author.avatarURL()}); client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('932177797705781308').send({embeds: [amEmbed]}).catch(() => {})).catch(() => {});
if (!queue) {options.queued = false;} if (options.images && options.images.length) {
await new Char(options).save(); let imagesEmbed = new Discord.MessageEmbed()
if (aniData) { .setAuthor({name: message.author.username, iconURL: message.author.avatarURL()})
aniData.characters.push(options.id); .setTitle(`New Image${client.utils.s(options.images.length)} ${queue ? "Submitted" : "Added"}`)
aniData.markModified('characters'); .setDescription(`For **${options.name}** | \`${options.id}\` from ${client.misc.cache.animeID.get(options.anime)}`)
aniData.save(); .setThumbnail(options.thumbnail)
.setImage(options.images[0])
.setColor('c375f0')
.setTimestamp()
.setFooter({text: "Natsuki"})
if (options.images.length > 1) {imagesEmbed.addField("Images", options.images.join("\n"));}
client.guilds.cache.get('762707532417335296').channels.cache.get('932177850239422494').send({
embeds: [imagesEmbed], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {});
}
if (am) {am.delete().catch(() => {});}
return dmch.send(`Your character${options.images.length ? `, and ${options.gender === 'Male' ? 'his' : options.gender === 'Female' ? 'her' : 'their'} ${options.images.length} ${client.utils.as(options.images.length, 'image')},` : ''} has been ${!queue ? "added" : "submitted"}`);
};
if (!options.force) {
try {
am = await dmch.send({embeds: [amEmbed]});
await am.react('👍').catch(() => {});
await am.react('👎').catch(() => {});
} catch {return dmch.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");}
try {
let rc = am.createReactionCollector({filter: (r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, max: 1, time: 60000});
rc.on("collect", async r => {
if (r.emoji.name !== '👎') {
await addChar();
} else {
return dmch.send("Oh, okay. I'll discard that then!");
} }
client.guilds.fetch('762707532417335296') });
.then(g => g.channels.cache.get('932177797705781308').send({embeds: [amEmbed]}) rc.on("end", collected => {if (!collected.size) {return message.author.send("Looks like you ran out of time! Try again?");}});
.then(nchm => {if (options.images && options.images.length) { } catch {return message.author.send("Hmm... there was some kind of error when I tried to submit that character. Try again, and if it keeps not working, then go yell at my devs!");}
let imagesEmbed = new Discord.MessageEmbed() } else {await addChar();}
.setAuthor({name: message.author.username, iconURL: message.author.avatarURL()})
.setTitle(`New Image ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${options.name}** | \`${options.id}\` from ${client.misc.cache.animeID.get(options.anime)}`)
.setThumbnail(options.thumbnail)
.setImage(options.images[0])
.setColor('c375f0')
.setTimestamp()
.setFooter({text: "Natsuki"})
if (options.images.length > 1) {imagesEmbed.addField("Images", options.images.join("\n"));}
nchm.guild.channels.cache.get('932177850239422494').send({
embeds: [imagesEmbed], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {});
}})
.catch(() => {})
);
am.delete().catch(() => {});
return dmch.send(`Your character has been ${!queue ? "added" : "submitted"}`);
} else {
return dmch.send("Oh, okay. I'll discard that then!");
}
});
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 character. Try again, and if it keeps not working, then go yell at my devs!");}
return; return;
} }
@ -379,14 +382,16 @@ 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 character you want!"); let noticeDel = 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) => ['✅', '⏹'].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 character you were looking for.");} catch {return message.reply("Looks like you didn't find the character you were looking for.");}
collected = arc.first().emoji.name; let 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());
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 character you were looking for.");} else {return message.reply("Looks like you didn't find the character you were looking for.");}
} else {fn = asr.id;} } else {fn = asr.id;}
@ -402,7 +407,7 @@ module.exports = {
ch.images.push(ch.thumbnail); ch.images.push(ch.thumbnail);
let pages = ch.images.map(im => new Discord.MessageEmbed() let pages = ch.images.map(im => new Discord.MessageEmbed()
.setTitle(ch.name) .setTitle(ch.name)
.setDescription(`**Name:** ${ch.name}`) .setDescription(`**Name:** ${ch.name} -> ${ch.images.length} ${client.utils.as(ch.images.length, 'image')}`)
.addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`) .addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`)
.setColor("c375f0") .setColor("c375f0")
.setImage(im) .setImage(im)
@ -410,7 +415,7 @@ module.exports = {
if (pages.length > 1) { if (pages.length > 1) {
let pag = new Pagination(message.channel, pages, message, client, true); let pag = new Pagination(message.channel, pages, message, client, true);
return await pag.start({user: message.author.id, time: 60000}); return await pag.start({user: message.author.id, time: 60000});
} else {return message.channel.send(pages[0].setTimestamp());} } else {return message.channel.send({embeds: [pages[0].setTimestamp()]});}
} else { } else {
args.shift(); args.shift();
let images = []; let images = [];

@ -39,14 +39,16 @@ 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 character you want!"); let noticeDel = 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) => ['✅', '⏹'].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 character you were looking for.");} catch {return message.reply("Looks like you didn't find the character you were looking for.");}
collected = arc.first().emoji.name; let 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());
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 character you were looking for.");} else {return message.reply("Looks like you didn't find the character you were looking for.");}
} else {fn = asr.id;} } else {fn = asr.id;}
@ -62,7 +64,7 @@ module.exports = {
ch.images.push(ch.thumbnail); ch.images.push(ch.thumbnail);
let pages = ch.images.map(im => new Discord.MessageEmbed() let pages = ch.images.map(im => new Discord.MessageEmbed()
.setTitle(ch.name) .setTitle(ch.name)
.setDescription(`**Name:** ${ch.name}`) .setDescription(`**Name:** ${ch.name} -> ${ch.images.length} ${client.utils.as(ch.images.length, 'image')}`)
.addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`) .addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`)
.setColor("c375f0") .setColor("c375f0")
.setImage(im) .setImage(im)
@ -70,7 +72,7 @@ module.exports = {
if (pages.length > 1) { if (pages.length > 1) {
let pag = new Pagination(message.channel, pages, message, client, true); let pag = new Pagination(message.channel, pages, message, client, true);
return await pag.start({user: message.author.id, time: 60000}); return await pag.start({user: message.author.id, time: 60000});
} else {return message.channel.send(pages[0].setTimestamp());} } else {return message.channel.send({embeds: [pages[0].setTimestamp()]});}
} else { } else {
args.shift(); args.shift();
let images = []; let images = [];

@ -20,11 +20,11 @@ module.exports = async (client, spinner) => {
client.misc.cache.charsID.set(char.id, char.name); client.misc.cache.charsID.set(char.id, char.name);
client.misc.cache.charsNum++; client.misc.cache.charsNum++;
client.misc.cache.charsLove.set(char.id, char.loved); client.misc.cache.charsLove.set(char.id, char.loved);
let hasNull = false; /*let hasNull = false;
char.images.forEach((image, index) => { char.images.forEach((image, index) => {
if (image === null) {char.images.splice(index, 1); hasNull = true;} if (image === null) {char.images.splice(index, 1); hasNull = true;}
}); });
if (hasNull) {char.markModified('images'); await char.save();} if (hasNull) {char.markModified('images'); await char.save();}*/
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`}); spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`});
amount++; amount++;
} }

Loading…
Cancel
Save