const config = require('./config').config();
const TeleBot = require('telebot');
const bot = new TeleBot(config.botToken);
const { spawn } = require('child_process');
const adminUsers = config.adminUsers;

bot.on('text', (msg) => {
    const id = msg.from.id;
    msg.reply.text('$:'+msg.text);
    if(adminUsers.indexOf(id) < 0){
        msg.reply.text('You are not admin!');
        return;
    }
    let words = msg.text.split(" ");
    let len = words.length;
    let args = [];
    if (len > 1 ){
        args = words.slice(1, len);
        
    } 
    console.log('args:'+args);

    const shell = spawn(words[0],args);
    
    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();
@@ -199,16 +199,18 @@
 Users;%0A%0A
+%0A%0A
 bot.on('
@@ -619,27 +619,182 @@
 0%5D,args)
-;%0A    %0A    
+.on('error', function( err )%7B %0A        %09%09msg.reply.text('error while executing:'+words%5B0%5D);%0A        %09%09msg.reply.text(err);%0A        %09%7D);%0A    %0A    if(shell)%7B%0A    %0A    %09
 shell.st
@@ -821,32 +821,33 @@
 a) =%3E %7B%0A        
+%09
 msg.reply.text(%60
@@ -863,32 +863,33 @@
  $%7Bdata%7D%60);%0A    
+%09
 %7D);%0A    %0A    she
@@ -881,24 +881,25 @@
 );%0A    %0A    
+%09
 shell.stderr
@@ -922,32 +922,33 @@
 a) =%3E %7B%0A        
+%09
 msg.reply.text(%60
@@ -966,24 +966,25 @@
 ata%7D%60);%0A    
+%09
 %7D);%0A    %0A   
@@ -984,16 +984,17 @@
    %0A    
+%09
 shell.on
@@ -1015,32 +1015,33 @@
 e) =%3E %7B%0A        
+%09
 msg.reply.text(%60
@@ -1078,19 +1078,26 @@
 %60);%0A    
+%09
 %7D);
+%0A    %7D
 %0A%0A%7D%0A);%0A%0A

add error handling on executing wrong commands