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 name="ChangeListManager">
<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$/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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/charnick.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/charnick.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" />
<change beforePath="$PROJECT_DIR$/util/cache/char.js" beforeDir="false" afterPath="$PROJECT_DIR$/util/cache/char.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -161,7 +154,14 @@
<option name="project" value="LOCAL" />
<updated>1642551387709</updated>
</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 />
</component>
<component name="TypeScriptGeneratedFilesManager">

@ -47,7 +47,8 @@ module.exports = {
new Tag(['img', 'image', 'i'], 'images', 'listAppend'),
new Tag(['loveInterest', 'dating', 'married', 'li'], 'loveInterest', '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(' '));
if (Object.keys(options).length) {
@ -60,7 +61,7 @@ module.exports = {
let att = Array.from(message.attachments.keys());
if (message.attachments.size > 1) {
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;
@ -191,57 +192,59 @@ module.exports = {
.setImage(options.thumbnail)
.setFooter({text: "Natsuki", iconURL: client.user.avatarURL()})
.setTimestamp();
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 !== '👎') {
while (true) {options.id = require('../../util/makeid')(4); if (!await Char.findOne({id: options.id})) {break;}}
if (!queue) {
amEmbed.addField("Reviewed", `Reviewed and submitted by <@${message.author.id}>`);
client.misc.cache.chars.set(options.name, options.id);
client.misc.cache.charsID.set(options.id, options.name);
}
else {amEmbed.addField("ID", options.id);}
amEmbed.setAuthor({name: !queue ? "Character Added" : "Character Submitted", iconURL: message.author.avatarURL()});
if (!queue) {options.queued = false;}
await new Char(options).save();
if (aniData) {
aniData.characters.push(options.id);
aniData.markModified('characters');
aniData.save();
const addChar = async () => {
while (true) {options.id = require('../../util/makeid')(4); if (!await Char.findOne({id: options.id})) {break;}}
if (!queue) {
amEmbed.addField("Reviewed", `Reviewed and submitted by <@${message.author.id}>`);
client.misc.cache.chars.set(options.name, options.id);
client.misc.cache.charsID.set(options.id, options.name);
}
else {amEmbed.addField("ID", options.id);}
amEmbed.setAuthor({name: !queue ? "Character Added" : "Character Submitted", iconURL: message.author.avatarURL()});
if (!queue) {options.queued = false;}
await new Char(options).save();
if (aniData) {
aniData.characters.push(options.id);
aniData.markModified('characters');
aniData.save();
}
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('932177797705781308').send({embeds: [amEmbed]}).catch(() => {})).catch(() => {});
if (options.images && options.images.length) {
let imagesEmbed = new Discord.MessageEmbed()
.setAuthor({name: message.author.username, iconURL: message.author.avatarURL()})
.setTitle(`New Image${client.utils.s(options.images.length)} ${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"));}
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]})
.then(nchm => {if (options.images && options.images.length) {
let imagesEmbed = new Discord.MessageEmbed()
.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!");}
});
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!");}
} else {await addChar();}
return;
}
@ -379,14 +382,16 @@ module.exports = {
} else if (asr instanceof Pagination) {
await asr.start({user: message.author.id, startPage: 0, endTime: 60000});
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;
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.");}
collected = arc.first().emoji.name;
let collected = arc.first().emoji.name;
if (collected === '✅') {
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 {fn = asr.id;}
@ -402,7 +407,7 @@ module.exports = {
ch.images.push(ch.thumbnail);
let pages = ch.images.map(im => new Discord.MessageEmbed()
.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`)
.setColor("c375f0")
.setImage(im)
@ -410,7 +415,7 @@ module.exports = {
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(pages[0].setTimestamp());}
} else {return message.channel.send({embeds: [pages[0].setTimestamp()]});}
} else {
args.shift();
let images = [];

@ -39,14 +39,16 @@ module.exports = {
} else if (asr instanceof Pagination) {
await asr.start({user: message.author.id, startPage: 0, endTime: 60000});
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;
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.");}
collected = arc.first().emoji.name;
let collected = arc.first().emoji.name;
if (collected === '✅') {
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 {fn = asr.id;}
@ -62,7 +64,7 @@ module.exports = {
ch.images.push(ch.thumbnail);
let pages = ch.images.map(im => new Discord.MessageEmbed()
.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`)
.setColor("c375f0")
.setImage(im)
@ -70,7 +72,7 @@ module.exports = {
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(pages[0].setTimestamp());}
} else {return message.channel.send({embeds: [pages[0].setTimestamp()]});}
} else {
args.shift();
let images = [];

@ -20,11 +20,11 @@ module.exports = async (client, spinner) => {
client.misc.cache.charsID.set(char.id, char.name);
client.misc.cache.charsNum++;
client.misc.cache.charsLove.set(char.id, char.loved);
let hasNull = false;
/*let hasNull = false;
char.images.forEach((image, index) => {
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)`)}`});
amount++;
}

Loading…
Cancel
Save