diff --git a/app.js b/app.js index e9474b3..4815471 100644 --- a/app.js +++ b/app.js @@ -31,19 +31,15 @@ sessions.history = []; const getSession = sessionFinder(sessions); -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'; +// Validate bot's master +bot.use(validator); + bot.command('start', ctx => { const newProc = spawn(defaultShell, { diff --git a/lib/validator.js b/lib/validator.js index 3fa2007..743f7fc 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -1,10 +1,15 @@ const { path } = require('../util/index.js'); const config = require('../config.js'); +const responder = require('./responseHandler.js'); const validate = - ctx => { + (ctx, next) => { if(!path(['update', 'message', 'from', 'id'], ctx)) return Promise.reject(ctx); - return (ctx.update.message.from.id === config.masterID) ? Promise.resolve(ctx) : Promise.reject(ctx); - } + return ((ctx.update.message.from.id === config.masterID) + ? Promise.resolve(ctx) + : Promise.reject(ctx)) + .then(next) + .catch(responder.fail('Username not authenticated.')); + }; module.exports = validate;