2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-26 11:57:09 +00:00

40 lines
896 B
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
const { link } = require('../../utils/tg');
2017-09-21 13:57:49 +04:30
// Bot
const { replyOptions } = require('../../bot/options');
2017-09-21 13:57:49 +04:30
// DB
const Warn = require('../../stores/warn');
2017-09-27 00:11:20 +03:30
const { isAdmin } = require('../../stores/user');
2017-09-21 13:57:49 +04:30
const unwarnHandler = async ({ message, reply }) => {
2017-09-27 00:11:20 +03:30
if (!await isAdmin(message.from)) {
2017-09-21 13:57:49 +04:30
return null;
}
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
const allWarns = await Warn.getWarns(userToUnwarn);
2017-09-21 13:57:49 +04:30
const warn = await Warn.unwarn(userToUnwarn);
return reply(
2017-09-24 23:24:34 +03:30
`${link(message.from)} <b>pardoned</b> ${link(userToUnwarn)} ` +
`<b>for:</b>\n\n${warn} (${allWarns.length}/3)`,
2017-09-21 13:57:49 +04:30
replyOptions);
};
module.exports = unwarnHandler;