mirror of
https://github.com/tomru/wichteln.git
synced 2026-03-03 06:27:15 +01:00
some improvements
This commit is contained in:
14
wichteln.js
14
wichteln.js
@@ -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}`));
|
||||
|
||||
Reference in New Issue
Block a user