2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-27 04:17:21 +00:00
2018-05-04 14:21:51 +02:00

58 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
// Utils
const { scheduleDeletion } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { isAdmin } = require('../../stores/user');
const warnHandler = async (ctx) => {
const { message, reply, me } = ctx;
const userToWarn = message.reply_to_message
? Object.assign({ username: '' }, message.reply_to_message.from)
: message.commandMention
? Object.assign({ username: '' }, message.commandMention)
: 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
);
}
if (!userToWarn) {
return reply(
' <b>Reply to a message or mention a user.</b>',
replyOptions
).then(scheduleDeletion);
}
if (userToWarn.username.toLowerCase() === me.toLowerCase()) return null;
const reason = message.text.split(' ').slice(1).join(' ').trim();
if (await isAdmin(userToWarn)) {
return reply(' <b>Can\'t warn other admins.</b>', replyOptions);
}
if (reason.length === 0) {
return reply(' <b>Need a reason to warn.</b>', replyOptions)
.then(scheduleDeletion);
}
if (message.reply_to_message) {
ctx.deleteMessage(message.reply_to_message.message_id);
}
return ctx.warn({ admin: ctx.from, reason, userToWarn });
};
module.exports = warnHandler;