vvlad1973-telegram-framework
Version:
Current version: *7.9.5*
69 lines (60 loc) • 1.46 kB
JavaScript
/**
* @module bot_commands
*/
/**
* @typedef {Object} module:bot_commands.BotCommand
* @property {string} command
* @property {string} description
*/
/**
* @class Implements structure for operations with Telegram bot's commands
* @extends {Array}
*/
class BotCommandsArray extends Array {
/**
* @returns {module:bot_commands.BotCommand[]}
*/
constructor() {
super();
}
/**
* Method which adds command to bot's commands array
*
* @param {string} command
* @param {string} description
*
* @returns {number|boolean} - If success - length of commands array,
* if fail - false
*/
addCommand(command, description) {
if (!this.isExistsCommand(command)) {
this.push({ command: command, description: description });
return this.length;
} else {
return false;
}
}
/**
* Method which checks exist some command in commands' array
*
* @param {string} command
* @returns {boolean}
*/
isExistsCommand(command) {
return this.find(item => item.command === command);
}
/**
* Method which deletes some command from command's array
*
* @param {string} command
*/
deleteCommand(command) {
this.filter((item, index, array) => {
if (item.command === command) {
array.splice(index, 1);
}
})
}
}
export default BotCommandsArray;