2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 03:17:09 +00:00

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
const { logError } = require('../../utils/log');
2017-09-21 13:57:49 +04:30
2017-09-21 23:47:26 +04:30
// Config
const {
warnInlineKeyboard,
} = require('../../config');
const reply_markup = { inline_keyboard: warnInlineKeyboard };
2017-09-21 23:47:26 +04:30
2017-09-21 13:57:49 +04:30
// Bot
const { replyOptions } = require('../../bot/options');
2017-09-21 13:57:49 +04:30
// DB
const { isAdmin } = require('../../stores/user');
const warn = require('../../actions/warn');
2017-09-21 13:57:49 +04:30
const warnHandler = async (ctx) => {
const { message, reply, me } = ctx;
2017-09-25 12:40:04 +03:30
const userToWarn = message.reply_to_message
? Object.assign({ username: '' }, message.reply_to_message.from)
2017-09-25 12:40:04 +03:30
: message.commandMention
? Object.assign({ username: '' }, message.commandMention)
2017-09-25 12:40:04 +03:30
: null;
if (ctx.from.status !== 'admin') return null;
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) {
return reply(
2017-11-02 17:34:26 +01:00
' <b>Reply to a message or mention a user.</b>',
replyOptions
).then(scheduleDeletion);
2017-09-21 13:57:49 +04:30
}
if (userToWarn.username.toLowerCase() === me.toLowerCase()) return null;
2017-09-21 13:57:49 +04:30
const reason = message.text.split(' ').slice(1).join(' ').trim();
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
}
if (reason.length === 0) {
return reply(' <b>Need a reason to warn.</b>', replyOptions)
.then(scheduleDeletion);
}
2017-09-25 12:40:04 +03:30
if (message.reply_to_message) {
ctx.deleteMessage(message.reply_to_message.message_id);
}
const warnMessage = await warn({ admin: ctx.from, reason, userToWarn });
2017-09-21 13:57:49 +04:30
return ctx.replyWithHTML(warnMessage, { reply_markup });
2017-09-21 13:57:49 +04:30
};
module.exports = warnHandler;