Deathnote custom victim text, victim-mention parsing

master
Kit Kasune 4 years ago
parent 82d83a38eb
commit 87be188c64
  1. 47
      commands/deathnote.js

@ -57,23 +57,38 @@ module.exports = {
if (!message.guild) {return message.reply("Unfortunately, this is a **guild-only** command!");}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}deathnote <@member> [method of death]\``);}
if (args[0] == "kill" || args[0] == "k") {args.shift();} // if someone adds in 'kill' it'll remove it and act like it wasn't there, proceeding as normal.
if (!mention) {return message.reply("You have to write their name down in order to kill them! (In other words, please mention the user whose name you wish to write.)");}
if (!args[0].trim().match(/^<@(?:\!?)\d+>$/)) {return message.reply("You have to mention someone!");}
if (mention.id == message.author.id) {return message.reply("Hehe I won't let you write your own name in the notebook! Just leave it somewhere for a few days and someone else will take it. Maybe they'll write your name...");} // users can't mention themselves
if (mention.id == client.user.id) {return message.reply("You can't kill me! Little did you know, I'm actually a death god!");}
//if (!args[0].trim().match(/^<@(?:\!?)\d+>$/)) {return message.reply("You have to mention someone!");}
if (mention && mention.id == message.author.id) {return message.reply("Hehe I won't let you write your own name in the notebook! Just leave it somewhere for a few days and someone else will take it. Maybe they'll write your name...");} // users can't mention themselves
if (mention && mention.id == client.user.id) {return message.reply("You can't kill me! Little did you know, I'm actually a death god!");}
//TODO if bot is mentioned maybe
let death = deaths[Math.floor(Math.random() * deaths.length)]; //kill method
let reptype = responses[Object.keys(responses)[Math.floor(Math.random() * Object.keys(responses).length)]]; // report type
let title = reptype.titles[Math.floor(Math.random() * reptype.titles.length)];
let pretext = before[Math.floor(Math.random() * before.length)];
let options = new TagFilter([new Tag(['method', '-m', 'cause', '-c'], 'method', 'append')]).test(args.splice(0, 1).join(" "));
if (options.method.length) {death = options.method;}
let options = new TagFilter([
new Tag(['method', '-m', 'cause', '-c'], 'method', 'append'),
new Tag(['victim', 'v', 'against', 'a', 'name', 'n'], 'victim', 'append')
]).test(args.join(" "));
if (options.method && options.method.length) {death = options.method;}
let victim = message.mentions.members.first();
if (!mention && (!options.victim || !options.victim.length)) {return message.reply("You have to write their name down in order to kill them! (In other words, please mention the user whose name you wish to write.)");}
if (options.victim && options.victim.length) {
let vargs = options.victim.trim().split(/\s+/g);
let nvargs = [];
let varg; for (varg of vargs) {
if (varg.match(/^<@(?:\!?)\d+>$/)) {
nvargs.push(message.guild.members.cache.has(varg.slice(varg.search(/\d/), varg.search('>'))) ? message.guild.members.cache.get(varg.slice(varg.search(/\d/), varg.search('>'))).displayName : varg);
} else {nvargs.push(varg);}
}
options.victim = nvargs.join(" ").trim();
}
let victim = options.victim && options.victim.length ? options.victim : message.mentions.members.first().displayName;
let killer = message.member;
let pretext = before[Math.floor(Math.random() * before.length)].replace(/{p}/g, victim);
let note = await message.channel.send(new Discord.MessageEmbed()
.setDescription(pretext)
.setColor('c375f0')
@ -84,22 +99,22 @@ module.exports = {
await require('../util/wait')(2500);
let text = reptype.texts[Math.floor(Math.random() * reptype.texts.length)]
.replace(/{p}/g, victim.displayName) //{p} = victim
.replace(/{pa}/g, victim.displayName.toLowerCase().endsWith('s') ? `${victim.displayName}'` : `${victim.displayName}'s`) //{pa} = victim but with a formatted apostrophe like "WubzyGD's"
.replace(/{p}/g, victim) //{p} = victim
.replace(/{pa}/g, victim.toLowerCase().endsWith('s') ? `${victim}'` : `${victim}'s`) //{pa} = victim but with a formatted apostrophe like "WubzyGD's"
.replace(/{c}/g, death) // {c} = death method
.replace(/{w}/g, killer.displayName) // {w} = killer or writer
.replace(/{ds}/g, moment().format("h:mm a")); // {ds} = date small, basically just the time.
// Create and format the kill text
//TODO message before sending then edit that message i.e. "A name is being written..." then wait 5s
return note.edit(new Discord.MessageEmbed()
let finalEmbed = new Discord.MessageEmbed()
.setAuthor(title, message.author.avatarURL())
.setThumbnail(mention.avatarURL({size: 1024}))
.setDescription(text)
.setColor('c375f0')
.setFooter("Natsuki")
.setTimestamp()
);
.setTimestamp();
if (mention) {finalEmbed.setThumbnail(mention.avatarURL({size: 1024}));}
return note.edit(finalEmbed);
}
};
Loading…
Cancel
Save