2017-09-27 22:17:07 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-08-15 12:44:06 +02:00
|
|
|
const R = require('ramda');
|
|
|
|
|
2017-10-04 20:55:50 +03:30
|
|
|
// DB
|
|
|
|
const { listCommands } = require('../../stores/command');
|
|
|
|
|
2018-08-15 12:44:06 +02:00
|
|
|
// cfg
|
|
|
|
const { isMaster } = require('../../utils/config');
|
|
|
|
|
2018-04-17 17:35:20 +02:00
|
|
|
const { scheduleDeletion } = require('../../utils/tg');
|
|
|
|
|
2018-08-15 12:44:06 +02:00
|
|
|
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 <name|id></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.
|
2018-08-15 12:44:06 +02:00
|
|
|
<code>/showgroup</code> - Show the group it in <code>/groups</code> list.\n
|
|
|
|
`;
|
2017-09-27 22:17:07 +02:00
|
|
|
|
2018-08-15 12:44:06 +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 <reason></code> - Warns the user.
|
|
|
|
<code>/unwarn</code> - Removes the last warn from the user.
|
|
|
|
<code>/nowarns</code> - Clears warns for the user.
|
2020-06-29 15:07:12 +02:00
|
|
|
<code>/permit</code> - Permits the user to advertise once, within 24 hours.
|
2017-09-29 00:02:58 +03:30
|
|
|
<code>/ban <reason></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 <name></code> - to create a custom command.
|
2018-08-15 12:44:06 +02:00
|
|
|
<code>/removecommand <name></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.
|
2023-10-23 11:55:49 +02:00
|
|
|
<code>/report [reason]</code> - Reports the replied-to message to admins, reason is optional.\n
|
2017-09-27 22:17:07 +02:00
|
|
|
`;
|
2018-08-15 12:44:06 +02:00
|
|
|
const role = R.prop('role');
|
|
|
|
const name = R.prop('name');
|
2017-09-27 22:17:07 +02:00
|
|
|
|
2020-03-10 22:10:48 +01:00
|
|
|
/** @param { import('../../typings/context').ExtendedContext } ctx */
|
2018-08-15 12:44:06 +02:00
|
|
|
const commandReferenceHandler = async (ctx) => {
|
2017-10-04 20:55:50 +03:30
|
|
|
const customCommands = await listCommands();
|
2018-08-15 12:44:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
: '';
|
2018-08-15 12:44:06 +02:00
|
|
|
|
|
|
|
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') +
|
2018-08-15 12:44:06 +02:00
|
|
|
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') +
|
2018-08-15 12:44:06 +02:00
|
|
|
userCustomCommands;
|
|
|
|
|
|
|
|
return ctx.replyWithHTML(customCommandsText)
|
2018-11-20 11:47:30 +05:30
|
|
|
.then(scheduleDeletion());
|
2017-09-28 15:46:49 +03:30
|
|
|
};
|
2017-09-27 22:17:07 +02:00
|
|
|
|
|
|
|
module.exports = commandReferenceHandler;
|