2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 02:47:48 +00:00

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-09-21 23:47:26 +04:30
'use strict';
// Utils
const { link } = 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/warn');
const admins = require('../../stores/admin');
2017-09-21 23:47:26 +04:30
const nowarnsHandler = async ({ message, reply }) => {
if (!await admins.isAdmin(message.from)) {
return null;
}
if (!message.reply_to_message) {
2017-09-24 14:28:18 +03:30
return reply(' <b>Reply to a message.</b>', replyOptions);
2017-09-21 23:47:26 +04:30
}
const messageToUnwarn = message.reply_to_message;
const userToUnwarn = messageToUnwarn.from;
const warns = await getWarns(userToUnwarn);
2017-09-21 23:47:26 +04:30
if (warns.length < 1) {
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(process.env.DEBUG)(err);
}
2017-09-21 23:47:26 +04:30
return reply(
2017-09-24 23:24:34 +03:30
`♻️ ${link(message.from)} <b>pardoned</b> ${link(userToUnwarn)} ` +
'<b>for all of their warnings.</b>',
2017-09-21 23:47:26 +04:30
replyOptions);
};
module.exports = nowarnsHandler;