'use strict';
// Utils
const { link } = require('../../utils/tg');
const { logError } = require('../../utils/log');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { getWarns, nowarns } = require('../../stores/warn');
const admins = require('../../stores/admin');
const nowarnsHandler = async ({ message, reply }) => {
if (!await admins.isAdmin(message.from)) {
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 warns = await getWarns(userToUnwarn);
if (warns.length < 1) {
return reply(`ℹ️ ${link(userToUnwarn)} already has no warnings.`,
replyOptions);
}
try {
await nowarns(userToUnwarn);
} catch (err) {
logError(process.env.DEBUG)(err);
}
return reply(
`♻️ ${link(message.from)} pardoned ${link(userToUnwarn)} ` +
'for all of their warnings.',
replyOptions);
};
module.exports = nowarnsHandler;