-
Notifications
You must be signed in to change notification settings - Fork 16
/
cli.js
executable file
·76 lines (63 loc) · 1.65 KB
/
cli.js
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
#!/usr/bin/env node
// https://nodejs.org/api/util.html#utilparseargsconfig
import { parseArgs } from "node:util";
import {LocalBot} from './local_bot.js';
import {CloudBot} from './cloud_bot.js';
(async () => {
// Parse command-line options
const {
values,
positionals
} = parseArgs({
options: {
'data-dir': {type: 'string', default: '.aicombinator'},
'bot': {type: 'string', default: 'mybot1'},
'token': {type: 'string'},
'headless': {type: 'boolean', default: false},
'test': {type: 'boolean', default: false},
'list-apps': {type: 'boolean', default: false},
'version': {type: 'boolean', default: false}
},
allowPositionals: true
});
// Print arguments
// console.log(values, {positionals});
if(values.version){
console.log('aicombinator version: 0.4.1')
return;
}
let cmd = positionals[0];
if(!cmd && values.test){
cmd = "pair device on google sms. Then post on twitter with message hello world from aicombinator. Then fetch the top story from hacker news";
}
if(values['list-apps']) {
console.log("\n\nAvailable apps:\n");
console.log(LocalBot.list_tasks());
}
let bot;
if(!cmd){
console.error(`\nNo command specified`);
return;
} else {
console.log({cmd});
}
let bot_type = values.token ? "cloud" : "local";
if(bot_type == "local"){
bot = await LocalBot.init({
bot_id: values.bot,
data_dir: values['data-dir'],
headless: values.headless
});
} else if (bot_type == "cloud"){
bot = await CloudBot.init({
bot_token: values.token,
headless: values.headless
});
}
try {
await bot.execute_command(cmd);
} catch (err) {
console.error('Error:', err);
}
await bot.finish();
})();