forked from dmitriym09/calendar-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.mjs
40 lines (34 loc) · 907 Bytes
/
send.mjs
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
import fs from 'fs';
import yargs from 'yargs';
import { sendMsg } from './helpers/telegram.mjs';
import WSEvent from './types/wsevent.mjs';
/**
* CLI-интерфейс.
*/
export default async function () {
const events = yargs.argv._.map(file =>
sendMsg(
WSEvent.fromYaml(fs.readFileSync(file, 'utf-8')),
yargs.argv.token,
yargs.argv.channel,
yargs.argv.proxy,
),
);
if (events.length == 0) {
console.error('Events is empty!');
process.exit(0);
}
try {
const results = await Promise.all(events);
if (!results.every(res => res.status == 200)) {
console.error(results);
process.exit(2);
} else {
console.log(results);
process.exit(0);
}
} catch (err) {
console.error(err);
process.exit(1);
}
}