'use strict'; const R = require('ramda'); // DB const { listCommands } = require('../../stores/command'); // cfg const { isMaster } = require('../../utils/config'); const { scheduleDeletion } = require('../../utils/tg'); const masterCommands = `\ Master commands: /admin - Makes the user admin. /unadmin - Demotes the user from admin list. /leave <name|id> - Makes the bot leave the group cleanly. /hidegroup - Hide the group from /groups list. /showgroup - Show the group it in /groups list.\n `; const adminCommands = `\ Admin commands: /warn <reason> - Warns the user. /unwarn - Removes the last warn from the user. /nowarns - Clears warns for the user. /ban <reason> - Bans the user from groups. /unban - Removes the user from ban list. /user - Shows user's status and warns. /addcommand <name> - to create a custom command. /removecommand <name> - to remove a custom command.\n `; const userCommands = `\ Commands for everyone: /staff - Shows a list of admins. /link - Show the current group's link. /groups - Show a list of groups which the bot is admin in. /report - Reports the replied-to message to admins.\n `; const role = R.prop('role'); const name = R.prop('name'); const commandReferenceHandler = async (ctx) => { const customCommands = await listCommands(); const customCommandsGrouped = R.groupBy(role, customCommands); const userCustomCommands = customCommandsGrouped.everyone ? '[everyone]\n' + customCommandsGrouped.everyone .map(name) .join(', ') + '\n\n' : ''; const adminCustomCommands = customCommandsGrouped.admins ? '[admins]\n' + customCommandsGrouped.admins .map(name) .join(', ') + '\n\n' : ''; const masterCustomCommands = customCommandsGrouped.master ? '[master]\n' + customCommandsGrouped.master .map(name) .join(', ') + '\n\n' : ''; const customCommandsText = masterCommands.repeat(isMaster(ctx.from)) + adminCommands.repeat(ctx.from.status === 'admin') + userCommands + '\nCustom commands(prefix with !):\n' + masterCustomCommands.repeat(isMaster(ctx.from)) + adminCustomCommands.repeat(ctx.from.status === 'admin') + userCustomCommands; return ctx.replyWithHTML(customCommandsText) .then(scheduleDeletion); }; module.exports = commandReferenceHandler;