'use strict';
// Utils
const { link } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { getWarns, unwarn } = require('../../stores/user');
const unwarnHandler = async ({ message, reply, state }) => {
const { isAdmin, user } = state;
if (!isAdmin) return null;
const userToUnwarn = message.reply_to_message
? message.reply_to_message.from
: message.commandMention
? message.commandMention
: null;
if (!userToUnwarn) {
return reply('ℹ️ Reply to a message or mention a user.',
replyOptions);
}
const allWarns = await getWarns(userToUnwarn);
if (!allWarns) {
return reply(`ℹ️ ${link(userToUnwarn)} already has no warnings.`,
replyOptions);
}
await unwarn(userToUnwarn);
return reply(
`❎ ${link(user)} pardoned ${link(userToUnwarn)} ` +
`for:\n\n${allWarns[allWarns.length - 1]}` +
` (${allWarns.length - 1}/3)`,
replyOptions);
};
module.exports = unwarnHandler;