2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2017-10-31 22:20:49 +01:00
|
|
|
|
const { link, scheduleDeletion } = require('../../utils/tg');
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { logError } = require('../../utils/log');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-09-21 23:47:26 +04:30
|
|
|
|
// Config
|
2017-11-01 21:34:38 +01:00
|
|
|
|
const {
|
2017-11-02 19:17:45 +01:00
|
|
|
|
warnInlineKeyboard,
|
2017-11-24 12:31:47 +01:00
|
|
|
|
} = require('../../config');
|
2017-11-02 19:17:45 +01:00
|
|
|
|
const reply_markup = { inline_keyboard: warnInlineKeyboard };
|
2017-09-21 23:47:26 +04:30
|
|
|
|
|
2017-09-21 13:57:49 +04:30
|
|
|
|
// Bot
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { replyOptions } = require('../../bot/options');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
// DB
|
2018-02-05 19:17:52 +01:00
|
|
|
|
const { isAdmin } = require('../../stores/user');
|
|
|
|
|
const warn = require('../../actions/warn');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2018-02-05 19:17:52 +01:00
|
|
|
|
const warnHandler = async (ctx) => {
|
|
|
|
|
const { message, reply, me } = ctx;
|
2017-09-25 12:40:04 +03:30
|
|
|
|
const userToWarn = message.reply_to_message
|
2017-12-15 03:48:27 +05:00
|
|
|
|
? Object.assign({ username: '' }, message.reply_to_message.from)
|
2017-09-25 12:40:04 +03:30
|
|
|
|
: message.commandMention
|
2017-12-15 03:48:27 +05:00
|
|
|
|
? Object.assign({ username: '' }, message.commandMention)
|
2017-09-25 12:40:04 +03:30
|
|
|
|
: null;
|
|
|
|
|
|
2018-02-05 19:17:52 +01:00
|
|
|
|
if (ctx.from.status !== 'admin') return null;
|
2017-11-02 00:18:59 +03:30
|
|
|
|
|
|
|
|
|
if (message.chat.type === 'private') {
|
|
|
|
|
return reply(
|
|
|
|
|
'ℹ️ <b>This command is only available in groups.</b>',
|
|
|
|
|
replyOptions
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-25 12:40:04 +03:30
|
|
|
|
if (!userToWarn) {
|
2017-10-31 23:08:22 +01:00
|
|
|
|
return reply(
|
2017-11-02 17:34:26 +01:00
|
|
|
|
'ℹ️ <b>Reply to a message or mention a user.</b>',
|
2017-10-31 23:08:22 +01:00
|
|
|
|
replyOptions
|
|
|
|
|
).then(scheduleDeletion);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 03:48:27 +05:00
|
|
|
|
if (userToWarn.username.toLowerCase() === me.toLowerCase()) return null;
|
2017-11-23 18:06:52 +03:30
|
|
|
|
|
2017-09-21 13:57:49 +04:30
|
|
|
|
const reason = message.text.split(' ').slice(1).join(' ').trim();
|
|
|
|
|
|
2017-09-21 16:14:54 +04:30
|
|
|
|
if (await isAdmin(userToWarn)) {
|
2017-09-24 14:28:18 +03:30
|
|
|
|
return reply('ℹ️ <b>Can\'t warn other admins.</b>', replyOptions);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:20:50 +03:30
|
|
|
|
if (reason.length === 0) {
|
2017-10-31 22:20:49 +01:00
|
|
|
|
return reply('ℹ️ <b>Need a reason to warn.</b>', replyOptions)
|
|
|
|
|
.then(scheduleDeletion);
|
2017-10-10 22:20:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 12:40:04 +03:30
|
|
|
|
if (message.reply_to_message) {
|
2018-02-05 19:17:52 +01:00
|
|
|
|
ctx.deleteMessage(message.reply_to_message.message_id);
|
2017-10-31 19:08:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 19:17:52 +01:00
|
|
|
|
const warnMessage = await warn({ admin: ctx.from, reason, userToWarn });
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2018-02-05 19:17:52 +01:00
|
|
|
|
return ctx.replyWithHTML(warnMessage, { reply_markup });
|
2017-09-21 13:57:49 +04:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = warnHandler;
|