2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 19:37:14 +00:00

45 lines
1001 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 { getWarns, unwarn } = require('../../stores/user');
2017-09-21 13:57:49 +04:30
const unwarnHandler = async ({ message, reply, state }) => {
const { isAdmin, user } = state;
if (!isAdmin) return null;
2017-09-21 13:57:49 +04:30
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(
`${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
`<b>for:</b>\n\n${allWarns[allWarns.length - 1]}` +
` (${allWarns.length - 1}/3)`,
2017-09-21 13:57:49 +04:30
replyOptions);
};
module.exports = unwarnHandler;