2017-11-02 00:04:22 +03:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { parse, strip } = require('../../utils/parse');
|
2019-04-06 20:58:56 +02:00
|
|
|
|
const { escapeHtml, scheduleDeletion } = require('../../utils/tg');
|
2017-11-02 00:04:22 +03:30
|
|
|
|
|
|
|
|
|
// Bot
|
|
|
|
|
const { replyOptions } = require('../../bot/options');
|
|
|
|
|
|
|
|
|
|
// DB
|
2017-11-02 16:54:17 +01:00
|
|
|
|
const { getUser } = require('../../stores/user');
|
2017-11-02 00:04:22 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const getWarnsHandler = async ({ from, message, reply }) => {
|
|
|
|
|
if (!from) {
|
|
|
|
|
return reply(
|
|
|
|
|
'ℹ️ <b>This command is not available in channels.</b>',
|
|
|
|
|
replyOptions
|
|
|
|
|
).then(scheduleDeletion());
|
|
|
|
|
}
|
2017-11-02 00:04:22 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { targets } = parse(message);
|
2017-11-02 15:30:54 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (targets.length > 1) {
|
|
|
|
|
return reply(
|
|
|
|
|
'ℹ️ <b>Specify one user to promote.</b>',
|
|
|
|
|
replyOptions
|
|
|
|
|
).then(scheduleDeletion());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const theUser = targets.length && from.status === 'admin'
|
|
|
|
|
? await getUser(strip(targets[0]))
|
|
|
|
|
: from;
|
|
|
|
|
|
|
|
|
|
if (!theUser) {
|
|
|
|
|
return reply(
|
|
|
|
|
'❓ <b>User unknown.</b>',
|
|
|
|
|
replyOptions
|
|
|
|
|
).then(scheduleDeletion());
|
|
|
|
|
}
|
2017-11-02 00:04:22 +03:30
|
|
|
|
|
2017-11-05 20:41:31 +03:30
|
|
|
|
const { first_name, id, last_name, status, username, warns } = theUser;
|
|
|
|
|
|
2019-04-06 20:58:56 +02:00
|
|
|
|
const userName = '<b>Name:</b> ' +
|
|
|
|
|
`<code>${escapeHtml(first_name)} ${escapeHtml(last_name)}</code>\n`;
|
2017-11-05 20:41:31 +03:30
|
|
|
|
const userId = `<b>ID:</b> <code>${id}</code>\n`;
|
|
|
|
|
const userStatus = `<b>Status:</b> <code>${status}</code>\n`;
|
|
|
|
|
const userUsername = username
|
|
|
|
|
? `<b>Username:</b> @${username}\n`
|
|
|
|
|
: '';
|
|
|
|
|
const banReason = theUser.ban_reason
|
2019-04-06 20:58:56 +02:00
|
|
|
|
? '\n🚫 <b>Ban reason:</b>\n' +
|
|
|
|
|
`<code>${escapeHtml(theUser.ban_reason)}</code>`
|
2017-11-05 20:41:31 +03:30
|
|
|
|
: '';
|
|
|
|
|
const userWarns = warns.length
|
|
|
|
|
? '\n<b>⚠️ Warns:</b>\n' + warns
|
2019-04-06 20:58:56 +02:00
|
|
|
|
.map((warn, i) => `${i + 1}. ${escapeHtml(warn.reason || warn)}`)
|
2017-11-05 20:41:31 +03:30
|
|
|
|
.join('\n') + '\n'
|
|
|
|
|
: '';
|
2017-11-02 00:04:22 +03:30
|
|
|
|
|
|
|
|
|
return reply(
|
2017-11-05 20:41:31 +03:30
|
|
|
|
userName +
|
|
|
|
|
userStatus +
|
|
|
|
|
userId +
|
|
|
|
|
userUsername +
|
|
|
|
|
userWarns +
|
|
|
|
|
banReason,
|
2017-11-02 00:04:22 +03:30
|
|
|
|
replyOptions
|
2018-11-20 11:47:30 +05:30
|
|
|
|
).then(scheduleDeletion());
|
2017-11-02 00:04:22 +03:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = getWarnsHandler;
|