-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·81 lines (64 loc) · 1.97 KB
/
index.js
File metadata and controls
executable file
·81 lines (64 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { promises: fs } = require('fs');
const readme = require('./readme');
const msInOneDay = 1000 * 60 * 60 * 24;
const today = new Date();
function generateNewREADME() {
const readmeRow = readme.split('\n');
function updateIdentifier(identifier, replaceText) {
const identifierIndex = findIdentifierIndex(readmeRow, identifier);
if (!readmeRow[identifierIndex]) return;
readmeRow[identifierIndex] = readmeRow[identifierIndex].replace(
`<#${identifier}>`,
replaceText
);
}
const identifierToUpdate = {
day_before_new_years: getDBNWSentence(),
today_date: getTodayDate(),
gabot_signing: getGabotSigning(),
};
Object.entries(identifierToUpdate).forEach(([key, value]) => {
updateIdentifier(key, value);
});
return readmeRow.join('\n');
}
const moodByDay = {
1: 'hate',
2: 'wickedness',
3: 'pleasure',
4: 'wickedness',
5: 'cruelty',
6: 'horror',
7: 'love',
};
function getGabotSigning() {
const mood = moodByDay[today.getDay() + 1];
return `🤖 This README.md is updated with ${mood}, by Gabot ❤️`;
}
function getTodayDate() {
return today.toDateString();
}
function getMySelf() {
// test if we are in a PAIR DAY
return today.getDate() % 2 === 0
? Math.floor(Math.random() * 2)
? 'penguin 🐧'
: 'bear 🐻'
: 'penguin bear 🐧🐻';
}
function getDBNWSentence() {
const nextYear = today.getFullYear() + 1;
const nextYearDate = new Date(String(nextYear));
const timeUntilNewYear = nextYearDate.getTime() - today.getTime();
const dayUntilNewYear = Math.round(timeUntilNewYear / msInOneDay);
return `**${dayUntilNewYear} day before ${nextYear} ⏱**`;
}
const findIdentifierIndex = (rows, identifier) =>
rows.findIndex((r) => Boolean(r.match(new RegExp(`<#${identifier}>`, 'i'))));
const updateREADMEFile = (text) => fs.writeFile('./README.md', text);
function main() {
const newREADME = generateNewREADME();
console.log(newREADME);
updateREADMEFile(newREADME);
}
main();