From fccc263eae05e7d123a4dc271cc98ce336444e53 Mon Sep 17 00:00:00 2001 From: Pavan Jadhaw Date: Tue, 17 Jul 2018 11:26:00 +0530 Subject: [PATCH] [tsh] make default shell os dependent --- app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index a5cba87..766b93e 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,6 @@ const { spawn } = require('child_process'); const { EOL } = require('os'); +const os = require('os'); const Telegraf = require('telegraf'); const { path } = require('./util/index.js'); @@ -21,18 +22,24 @@ const bot = new Telegraf(config.botApiKey); const sessions = []; sessions.history = []; -bot.use((ctx, next) => +bot.use((ctx, next) => validator(ctx) .then(next) .catch(responder.fail( `Username Not authenticated!` ))); +// get os info +const home = os.homedir(); +const hostname = os.hostname(); +const username = os.userInfo().username; +const defaultShell = os.platform() === 'win32' ? 'cmd.exe' : 'bash'; + bot.command('start', ctx => { - ctx.replyWithHTML('Welcome to tsh -- Telegram Shell!'); - const newProc = spawn('bash', { - cwd: '/home' + ctx.replyWithHTML(`Welcome to tsh -- Telegram Shell!

You are now connected to ${hostname} as ${username}`); + const newProc = spawn(defaultShell, { + cwd: home }); newProc.stdout.setEncoding('utf8'); sessions.push(newProc);