add authentication
This commit is contained in:
parent
70db39503f
commit
d2148df68c
|
@ -0,0 +1,15 @@
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
|
function checkUser(userId) {
|
||||||
|
return config.app.authorizedUsers.includes(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function auth(userId, okAuth, koAuth) {
|
||||||
|
if (checkUser(userId)) {
|
||||||
|
okAuth();
|
||||||
|
} else {
|
||||||
|
koAuth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = auth;
|
31
server.js
31
server.js
|
@ -1,36 +1,53 @@
|
||||||
const Telebot = require('telebot');
|
const Telebot = require('telebot');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
const auth = require('./auth');
|
||||||
|
|
||||||
const bot = new Telebot({
|
const bot = new Telebot({
|
||||||
token: config.app.tokenBot,
|
token: config.app.tokenBot,
|
||||||
usePlugins: ['askUser'],
|
usePlugins: ['askUser'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bot.on('/*', (msg) => {
|
||||||
|
bot.sendMessage(msg.from.id, 'qualsiasi');
|
||||||
|
});
|
||||||
|
|
||||||
bot.on('/start', (msg) => {
|
bot.on('/start', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, utils.templateStart(), { parseMode: 'Markdown' });
|
auth(msg.from.id, () => {
|
||||||
bot.event('/help', msg);
|
bot.sendMessage(msg.from.id, utils.templateStart(), { parseMode: 'Markdown' });
|
||||||
|
bot.event('/help', msg);
|
||||||
|
},
|
||||||
|
() => bot.sendMessage(msg.from.id, utils.templateUnauthorizedUser(), { parseMode: 'Markdown' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('/help', (msg) => {
|
bot.on('/help', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, utils.templateHelp(), { parseMode: 'Markdown' });
|
auth(msg.from.id, () => {
|
||||||
|
bot.sendMessage(msg.from.id, utils.templateHelp(), { parseMode: 'Markdown' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('/list', (msg) => {
|
bot.on('/list', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, 'list template');
|
auth(msg.from.id, () => {
|
||||||
|
bot.sendMessage(msg.from.id, 'list template');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('/position', (msg) => {
|
bot.on('/position', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, 'position template');
|
auth(msg.from.id, () => {
|
||||||
|
bot.sendMessage(msg.from.id, 'position template');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('/add', (msg) => {
|
bot.on('/add', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, 'add');
|
auth(msg.from.id, () => {
|
||||||
|
bot.sendMessage(msg.from.id, 'add');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('/remove', (msg) => {
|
bot.on('/remove', (msg) => {
|
||||||
bot.sendMessage(msg.from.id, 'remove');
|
auth(msg.from.id, () => {
|
||||||
|
bot.sendMessage(msg.from.id, 'remove');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue