TgRouting/deamon/router/rights.js

24 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// rights.js
/**
* Проверка, есть ли у пользователя доступ к боту по его имени
* @param {Array<Object>} availableBots — массив объектов ботов { name, commands, … }
* @param {string} botName — название бота для проверки
* @returns {boolean}
*/
export function checkUserBotRights(availableBots, botName) {
return availableBots.some(b => b.name === botName);
}
/**
* Проверка, есть ли у пользователя доступ к конкретной команде бота
* @param {Array<Object>} availableBots — массив объектов ботов { name, commands, … }
* @param {string} botName — название бота
* @param {string} commandName — команда (поле `command`) для проверки
* @returns {boolean}
*/
export function checkUserCommandRights(availableBots, botName, commandName) {
const bot = availableBots.find(b => b.name === botName);
return !!(bot && bot.commands.some(cmd => cmd.command === commandName));
}