2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 10:58:19 +00:00

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-09-21 23:47:26 +04:30
'use strict';
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
2017-09-23 21:49:23 +03:30
const { logError } = require('../../utils/log');
2017-09-21 23:47:26 +04:30
// Bot
const { replyOptions } = require('../../bot/options');
2017-09-21 23:47:26 +04:30
// DB
const { getWarns, nowarns } = require('../../stores/user');
2017-09-21 23:47:26 +04:30
const nowarnsHandler = async ({ message, reply, state }) => {
const { isAdmin, user } = state;
if (!isAdmin) 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
).then(scheduleDeletion);
2017-09-21 23:47:26 +04:30
}
const warns = await getWarns(userToUnwarn);
2017-09-21 23:47:26 +04:30
if (!warns) {
return reply(
` ${link(userToUnwarn)} <b>already has no warnings.</b>`,
replyOptions
);
}
2017-09-23 21:49:23 +03:30
try {
await nowarns(userToUnwarn);
} catch (err) {
logError(err);
2017-09-23 21:49:23 +03:30
}
2017-09-21 23:47:26 +04:30
return reply(
`♻️ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
2017-09-24 23:24:34 +03:30
'<b>for all of their warnings.</b>',
replyOptions
);
2017-09-21 23:47:26 +04:30
};
module.exports = nowarnsHandler;