add starting to secret santa... probably

master
Kit Kasune 4 years ago
parent 0db25f4478
commit a8288aef1f
  1. 1
      commands/pull.js
  2. 39
      commands/secretsanta.js
  3. 20
      template.js
  4. 15
      test.js

@ -24,6 +24,7 @@ module.exports = {
} else { } else {
console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`VCS Pull successful`)}\n`); console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`VCS Pull successful`)}\n`);
} }
return message.channel.send(`Done with ${stderr || error ? 'an error' : 'no errors'}!`);
}); });
} }
}; };

@ -145,25 +145,32 @@ module.exports = {
if (tss.started) {return message.channel.send("Your Secret Santa is already started!");} if (tss.started) {return message.channel.send("Your Secret Santa is already started!");}
if (tss.members.length < 3) {return message.channel.send("You need to have at least 3 members in order to start.");} if (tss.members.length < 3) {return message.channel.send("You need to have at least 3 members in order to start.");}
let dm = []; let cm; let rm; let rm2; let dm = []; let rm;
while (true) { let m; for (m of tss.members) {dm.push({name: m.id, assignedTo: null});}
rm = tss.members[Math.floor(Math.random() * tss.members.length)]; for (m of dm) {
rm2 = tss.members[Math.floor(Math.random() * tss.members.length)]; while (true) {
if (rm.id !== rm2.id) { let rm = tss.members[Math.floor(Math.random() * tss.members.length)];
dm.push([rm, rm2]); let exists = false;
break; let cdm; for (cdm of dm) {if (!exists) {exists = cdm.assignedTo === rm.id;}}
if (!exists && rm.id !== m.name) {dm[dm.indexOf(m)] = {name: m.name, assignedTo: rm.id}; break;}
} }
} }
let i; for (i=0;i<tss.members.length;i++) { tss.assignments = dm;
cm = tss.members[i]; tss.started = true;
let c = false; tss.save();
let t; for (t of dm) {if (t[0].id === cm.id) {c = true;}}
if (!c) { for (m of tss.members) {
dm.push([dm[dm.length - 1], cm]); let mem = await client.users.fetch(m.id);
} let assignmentt; let a; for (a of tss.assignments) {if (a.name === m.id) {assignmentt = a.assignedTo; break;}}
let assignment; let tm; for (tm of tss.members) {if (tm.id === assignmentt) {assignment = tm; break;}}
await mem.send(`The secret santa has been started!\nYou've been assigned to **${assignment.name}**. They've written the following about what they want:\n\`${assignment.info}\`\n\nThe host has said this about when you should when you should have your gifts purchased and when you'll do gift exchange:\n\`${tss.end}\`\n\nThe following info is written on how much to spend on gifts: \n\`${tss.spend}\``)
.catch(async () => {
let host = await client.users.fetch(tss.owner);
await host.send(`There was a problem sending ${mem.name} their info. Please tell that member that they have been assigned to \`${assignment.name}\` and that they want \`${assignment.info}\`.`);
});
} }
let mg; let asg = []; for (mg of dm) {asg.push({name: mg[0].id, assignedTo: mg[1].id});} message.channel.send("**The secret santa has been started!** Everyone should have their assignments.");
tss.assignments = asg;
} }
} }
}; };

@ -3,6 +3,16 @@ const Discord = require('discord.js');
module.exports = { module.exports = {
name: "", name: "",
aliases: [], aliases: [],
meta: {
category: "",
perms: "",
staff: false,
vip: "",
serverPerms: [],
writtenBy: "",
serverOnly: false
},
tags: [],
help: new Discord.MessageEmbed() help: new Discord.MessageEmbed()
.setTitle("Help -> ") .setTitle("Help -> ")
.setDescription("") .setDescription("")
@ -19,6 +29,16 @@ const Discord = require('discord.js');
module.exports = { module.exports = {
name: "", name: "",
aliases: [], aliases: [],
meta: {
category: "",
perms: "",
staff: false,
vip: "",
serverPerms: [],
writtenBy: "",
serverOnly: false
},
tags: [],
help: "", help: "",
async execute(message, msg, args, cmd, prefix, mention, client) { async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}\``);} if (!args.length) {return message.channel.send(`Syntax: \`${prefix}\``);}

@ -34,9 +34,16 @@ let tss = {
assignments: [] assignments: []
} }
let dm = []; let cm; let rm; let rm2; let dm = []; let rm;
let m; for (m of tss.members) {dm.push({name: m.id, assignedTo: null});}
let mg; let asg = []; for (mg of dm) {asg.push({name: mg[0].id, assignedTo: mg[1].id});} for (m of dm) {
tss.assignments = asg; while (true) {
let rm = tss.members[Math.floor(Math.random() * tss.members.length)];
let exists = false;
let cdm; for (cdm of dm) {if (!exists) {exists = cdm.assignedTo === rm.id;}}
if (!exists && rm.id !== m.name) {dm[dm.indexOf(m)] = {name: m.name, assignedTo: rm.id}; break;}
}
}
tss.assignments = dm;
console.log(tss); console.log(tss);
Loading…
Cancel
Save