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