some improvements

This commit is contained in:
Thomas Ruoff
2022-10-26 22:24:39 +02:00
parent ff048bfb51
commit b30b4995cb
3 changed files with 16 additions and 27 deletions

View File

@@ -20,8 +20,8 @@ function mail(email, name, pick) {
Du darfst dieses Jahr >> ${pick} << beschenken!
Viele lieben Grüße
Dein treuer Weihnachtswichtel™
Viele liebe Grüße
Dein Weihnachtswichtel™
`
},
(err, info) => {
@@ -59,7 +59,7 @@ const run = async () => {
throw new Error("input file empty");
}
people.forEach(drawer => {
people.forEach((drawer, index) => {
let picked;
let pickable = people.filter(
@@ -70,7 +70,7 @@ const run = async () => {
);
if (pickable.length === 0) {
throw new Error("ohhh, noone left for ", drawer.name);
throw new Error(`ohhh shoot. None left for ${drawer.name}. Just try to roll again...`);
}
let pickIndex = Math.floor(Math.random() * pickable.length);
@@ -78,16 +78,18 @@ const run = async () => {
pickable[pickIndex].picked = true;
});
console.log('Yay, I could draw someone for everybody! Writing ./picks.txt');
fs.writeFileSync(
`./picks.txt`,
people.map(({ name, pick }) => `${name} picked ${pick}`).join("\n")
);
if (!send) {
console.log("DryRun: did not send emails. To send pass --send option");
console.log("DRY RUN: did not send emails! To send pass --send option");
return;
}
people.forEach(p => mail(p.email, p.name, p.pick));
};
run();
run().catch((e) => console.error(`Error: ${e.message}`));