Browse Source

[refactor] Move validation to validator

master
Muthu Kumar 6 years ago
parent
commit
7d7d7800b1
  1. 10
      app.js
  2. 11
      lib/validator.js

10
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, {

11
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;

Loading…
Cancel
Save