2017-09-21 23:47:26 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2017-09-23 21:40:58 +03:30
|
|
|
|
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
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { replyOptions } = require('../../bot/options');
|
2017-09-21 23:47:26 +04:30
|
|
|
|
|
|
|
|
|
// DB
|
2017-09-24 22:17:27 +03:30
|
|
|
|
const { getWarns, nowarns } = require('../../stores/warn');
|
2017-09-23 21:40:58 +03:30
|
|
|
|
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;
|
2017-09-24 22:17:27 +03:30
|
|
|
|
const warns = await getWarns(userToUnwarn);
|
2017-09-21 23:47:26 +04:30
|
|
|
|
|
2017-09-24 22:17:27 +03: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-22 15:52:27 +03:30
|
|
|
|
|
2017-09-21 23:47:26 +04:30
|
|
|
|
return reply(
|
2017-09-24 14:28:18 +03:30
|
|
|
|
`♻️ ${link(userToUnwarn)} <b>was pardoned for ` +
|
|
|
|
|
'all of their warnings.</b>',
|
2017-09-21 23:47:26 +04:30
|
|
|
|
replyOptions);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = nowarnsHandler;
|