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

46 lines
1003 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 { isAdmin, getWarns, unwarn } = 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 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-09-24 23:24:34 +03:30
`${link(message.from)} <b>pardoned</b> ${link(userToUnwarn)} ` +
`<b>for:</b>\n\n${allWarns[allWarns.length - 1]}` +
2017-10-04 20:58:12 +03:30
`(${allWarns.length - 1}/3)`,
2017-09-21 13:57:49 +04:30
replyOptions);
};
module.exports = unwarnHandler;