-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.js
43 lines (36 loc) · 1014 Bytes
/
index.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
const TeleBot = require('telebot');
const { spawn } = require('child_process');
const config = require('./config').config();
const { adminUsers } = config;
const bot = new TeleBot(config.botToken);
bot.on('text', (msg) => {
const { id } = msg.from;
msg.reply.text('$:' + msg.text);
if (!adminUsers.includes(id)) {
msg.reply.text('You are not admin!');
return;
}
const words = msg.text.split(' ');
const len = words.length;
let args = [];
if (len > 1) {
args = words.slice(1, len);
}
console.log('args:' + args);
const shell = spawn(words[0], args).on('error', (err) => {
msg.reply.text('error while executing:' + words[0]);
msg.reply.text(err);
});
if (shell) {
shell.stdout.on('data', (data) => {
msg.reply.text(`stdout:\n ${data}`);
});
shell.stderr.on('data', (data) => {
msg.reply.text(`stderr: ${data}`);
});
shell.on('close', (code) => {
msg.reply.text(`shell exited with code ${code}`);
});
}
});
bot.start();