Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (71 loc) · 4.28 KB
/
Copy pathindex.js
File metadata and controls
83 lines (71 loc) · 4.28 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
82
83
import defaultExport, * as schedule from 'node-schedule'
import * as child from 'child_process';
import * as dotenv from 'dotenv'
//Are we in Docker?
//Checks if env variable is present from Dockerfile
if (process.env.ISDOCKER != "true" ) {
dotenv.config()
}
console.log('\n'+
'\n'+'▓█████::██▒:::█▓▓█████::██▀███::▓██:::██▓:██░:██::▒█████:::█::::██::██▀███:::▄▄▄▄::::▒█████::▄▄▄█████▓'+
'\n'+'▓█:::▀:▓██░:::█▒▓█:::▀:▓██:▒:██▒:▒██::██▒▓██░:██▒▒██▒::██▒:██::▓██▒▓██:▒:██▒▓█████▄:▒██▒::██▒▓::██▒:▓▒'+
'\n'+'▒███::::▓██::█▒░▒███:::▓██:░▄█:▒::▒██:██░▒██▀▀██░▒██░::██▒▓██::▒██░▓██:░▄█:▒▒██▒:▄██▒██░::██▒▒:▓██░:▒░'+
'\n'+'▒▓█::▄:::▒██:█░░▒▓█::▄:▒██▀▀█▄::::░:▐██▓░░▓█:░██:▒██:::██░▓▓█::░██░▒██▀▀█▄::▒██░█▀::▒██:::██░░:▓██▓:░:'+
'\n'+'░▒████▒:::▒▀█░::░▒████▒░██▓:▒██▒::░:██▒▓░░▓█▒░██▓░:████▓▒░▒▒█████▓:░██▓:▒██▒░▓█::▀█▓░:████▓▒░::▒██▒:░:'+
'\n'+'░░:▒░:░:::░:▐░::░░:▒░:░░:▒▓:░▒▓░:::██▒▒▒::▒:░░▒░▒░:▒░▒░▒░:░▒▓▒:▒:▒:░:▒▓:░▒▓░░▒▓███▀▒░:▒░▒░▒░:::▒:░░:::'+
'\n'+':░:░::░:::░:░░:::░:░::░::░▒:░:▒░:▓██:░▒░::▒:░▒░:░::░:▒:▒░:░░▒░:░:░:::░▒:░:▒░▒░▒:::░:::░:▒:▒░:::::░::::'+
'\n'+':::░::::::::░░:::::░:::::░░:::░::▒:▒:░░:::░::░░:░░:░:░:▒:::░░░:░:░:::░░:::░::░::::░:░:░:░:▒::::░::::::'+
'\n'+':::░::░::::::░:::::░::░:::░::::::░:░::::::░::░::░::::░:░:::::░::::::::░::::::░::::::::::░:░:::::::::::'+
'\n'+'::::::::::::░::::::::::::::::::::░:░::::::::::::::::::::::::::::::::::::::::::::::░:::::::::::::::::::'+
'\n')
console.log('Welcome to EveryHourBot Bot.\nVersion 2.0.0\n\n'+
'Module Status:\n'+
'Use Mastodon: '+process.env.USE_MASTODON +'\n'+
'Use BlueSky: '+process.env.USE_BLUESKY+'\n'+
'Use Twitter: '+process.env.USE_TWITTER+'\n'+
'Debug Mode Enabled: '+process.env.DEBUG_MODE+'\n'
);
const rule = new schedule.RecurrenceRule();
rule.minute = 0;
//Needs to be defined in a global scope
let filePath
let filePayload
//We need to wrap child_process.fork in a promise
//And also define the file generation module for better manipulation
function getFileToServe() {
const fileGen = child.fork('./ehb_modules/generate_file.js')
return new Promise((resolveFunc) => {
fileGen.on('message', (m) => {
filePath = m
})
fileGen.on('exit', code => {
if (code != 0){
throw new Error('File generator module has encountered an error! EHB will now close.');
} else {
resolveFunc(code)
}
})
});
}
async function getPayload(){
await getFileToServe()
return filePath
}
async function runJob() {
let timestamp = Date.now();
console.log('Starting new run at UNIX time '+timestamp)
const filePayload = await getPayload()
if(process.env.USE_MASTODON == "true") {child.fork('./ehb_modules/mastodon.js').send(filePayload)}
if(process.env.USE_BLUESKY == "true") {child.fork('./ehb_modules/bluesky.js').send(filePayload)}
if(process.env.USE_TWITTER == "true") {child.fork('./ehb_modules/twitter.js').send(filePayload)}
}
if(process.env.DEBUG_MODE == "true"){
console.log('!!!!!!DEBUG MODE ON --- BYPASSING TIMER AND EXITING AFTER EXECUTION!!!!!!')
runJob()
}
else{
const job = schedule.scheduleJob(rule, function(){
console.log('\nExecuting modules\n');
runJob()
});
}