2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 03:17:09 +00:00

70 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
// Utils
const { parse, strip } = require('../../utils/parse');
2017-11-05 22:10:52 +03:30
const { scheduleDeletion } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
2017-11-02 16:54:17 +01:00
const { getUser } = require('../../stores/user');
const getWarnsHandler = async ({ from, message, reply }) => {
if (!from) {
return reply(
' <b>This command is not available in channels.</b>',
replyOptions
).then(scheduleDeletion());
}
const { targets } = parse(message);
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-05 20:41:31 +03:30
const { first_name, id, last_name, status, username, warns } = theUser;
const userName = `<b>Name:</b> <code>${first_name} ${last_name}</code>\n`;
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
? `\n🚫 <b>Ban reason:</b>\n<code>${theUser.ban_reason}</code>`
: '';
const userWarns = warns.length
? '\n<b>⚠️ Warns:</b>\n' + warns
.map((warn, i) => `${i + 1}. ${warn.reason || warn}`)
2017-11-05 20:41:31 +03:30
.join('\n') + '\n'
: '';
return reply(
2017-11-05 20:41:31 +03:30
userName +
userStatus +
userId +
userUsername +
userWarns +
banReason,
replyOptions
).then(scheduleDeletion());
};
module.exports = getWarnsHandler;