2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 11:27:20 +00:00

85 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-09-27 22:17:07 +02:00
'use strict';
const R = require('ramda');
2017-10-04 20:55:50 +03:30
// DB
const { listCommands } = require('../../stores/command');
// cfg
const { isMaster } = require('../../utils/config');
const { scheduleDeletion } = require('../../utils/tg');
const masterCommands = `\
2017-09-27 22:17:07 +02:00
<b>Master commands</b>:
2017-09-29 00:02:58 +03:30
<code>/admin</code> - Makes the user admin.
<code>/unadmin</code> - Demotes the user from admin list.
2017-11-25 14:59:41 +03:30
<code>/leave &lt;name|id&gt;</code> - Makes the bot leave the group cleanly.
2018-04-17 17:19:27 +02:00
<code>/hidegroup</code> - Hide the group from <code>/groups</code> list.
<code>/showgroup</code> - Show the group it in <code>/groups</code> list.\n
`;
2017-09-27 22:17:07 +02:00
const adminCommands = `\
2017-09-27 22:17:07 +02:00
<b>Admin commands</b>:
2020-02-12 17:25:29 +01:00
<code>/del [reason]</code> - Deletes replied-to message.
2017-09-29 00:02:58 +03:30
<code>/warn &lt;reason&gt;</code> - Warns the user.
<code>/unwarn</code> - Removes the last warn from the user.
<code>/nowarns</code> - Clears warns for the user.
<code>/ban &lt;reason&gt;</code> - Bans the user from groups.
<code>/unban</code> - Removes the user from ban list.
2017-11-02 16:55:36 +01:00
<code>/user</code> - Shows user's status and warns.
2017-11-25 14:59:41 +03:30
<code>/addcommand &lt;name&gt;</code> - to create a custom command.
<code>/removecommand &lt;name&gt;</code> - to remove a custom command.\n
`;
const userCommands = `\
2017-09-27 22:17:07 +02:00
<b>Commands for everyone</b>:
2017-09-29 00:02:58 +03:30
<code>/staff</code> - Shows a list of admins.
2017-10-02 12:09:44 +03:30
<code>/link</code> - Show the current group's link.
2017-09-29 00:02:58 +03:30
<code>/groups</code> - Show a list of groups which the bot is admin in.
<code>/report</code> - Reports the replied-to message to admins.\n
2017-09-27 22:17:07 +02:00
`;
const role = R.prop('role');
const name = R.prop('name');
2017-09-27 22:17:07 +02:00
const commandReferenceHandler = async (ctx) => {
2017-10-04 20:55:50 +03:30
const customCommands = await listCommands();
const customCommandsGrouped = R.groupBy(role, customCommands);
const userCustomCommands = customCommandsGrouped.everyone
? '[everyone]\n<code>' +
customCommandsGrouped.everyone
.map(name)
.join(', ') +
'</code>\n\n'
2017-10-04 20:55:50 +03:30
: '';
const adminCustomCommands = customCommandsGrouped.admins
? '[admins]\n<code>' +
customCommandsGrouped.admins
.map(name)
.join(', ') +
'</code>\n\n'
: '';
const masterCustomCommands = customCommandsGrouped.master
? '[master]\n<code>' +
customCommandsGrouped.master
.map(name)
.join(', ') +
'</code>\n\n'
: '';
const customCommandsText = masterCommands.repeat(isMaster(ctx.from)) +
2019-01-24 19:53:10 +01:00
adminCommands.repeat(ctx.from && ctx.from.status === 'admin') +
userCommands +
'\n<b>Custom commands(prefix with !):</b>\n' +
masterCustomCommands.repeat(isMaster(ctx.from)) +
2019-01-24 19:53:10 +01:00
adminCustomCommands.repeat(ctx.from && ctx.from.status === 'admin') +
userCustomCommands;
return ctx.replyWithHTML(customCommandsText)
.then(scheduleDeletion());
2017-09-28 15:46:49 +03:30
};
2017-09-27 22:17:07 +02:00
module.exports = commandReferenceHandler;