2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 11:27:20 +00:00

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
2018-05-04 14:21:51 +02:00
const { scheduleDeletion } = require('../../utils/tg');
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');
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);
}
return ctx.warn({
admin: ctx.from,
reason,
userToWarn,
mode: 'manual',
});
2017-09-21 13:57:49 +04:30
};
module.exports = warnHandler;