2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { link } = require('../../utils/tg');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
// Bot
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { replyOptions } = require('../../bot/options');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
// DB
|
2017-10-06 16:34:23 +03:30
|
|
|
|
const { getWarns, unwarn } = require('../../stores/user');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-10-06 16:34:23 +03:30
|
|
|
|
const unwarnHandler = async ({ message, reply, state }) => {
|
|
|
|
|
const { isAdmin, user } = state;
|
2017-10-06 16:40:49 +03:30
|
|
|
|
if (!isAdmin) return null;
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-09-25 12:40:04 +03:30
|
|
|
|
const userToUnwarn = message.reply_to_message
|
|
|
|
|
? message.reply_to_message.from
|
|
|
|
|
: message.commandMention
|
|
|
|
|
? message.commandMention
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
if (!userToUnwarn) {
|
|
|
|
|
return reply('ℹ️ <b>Reply to a message or mention a user.</b>',
|
|
|
|
|
replyOptions);
|
|
|
|
|
}
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-09-27 12:34:26 +03:30
|
|
|
|
const allWarns = await getWarns(userToUnwarn);
|
|
|
|
|
|
|
|
|
|
if (!allWarns) {
|
|
|
|
|
return reply(`ℹ️ ${link(userToUnwarn)} <b>already has no warnings.</b>`,
|
|
|
|
|
replyOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await unwarn(userToUnwarn);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
return reply(
|
2017-10-06 16:34:23 +03:30
|
|
|
|
`❎ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
|
2017-09-27 12:34:26 +03:30
|
|
|
|
`<b>for:</b>\n\n${allWarns[allWarns.length - 1]}` +
|
2017-10-06 16:34:23 +03:30
|
|
|
|
` (${allWarns.length - 1}/3)`,
|
2017-09-21 13:57:49 +04:30
|
|
|
|
replyOptions);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = unwarnHandler;
|