2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 13:47:54 +00:00

added /user command and removed /getwarns

This commit is contained in:
Pouria Ezzati 2017-11-02 00:04:22 +03:30
parent eb76e2a651
commit e2e31f04d9
3 changed files with 64 additions and 40 deletions

View File

@ -1,38 +0,0 @@
'use strict';
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { getWarns } = require('../../stores/user');
const getWarnsHandler = async ({ message, reply, state }) => {
const { isAdmin } = state;
if (!isAdmin) return null;
const theUser = message.reply_to_message
? message.reply_to_message.from
: message.commandMention
? message.commandMention
: null;
if (!theUser) {
return reply(
' <b>Reply to a message or mention a user.</b>',
replyOptions
).then(scheduleDeletion);
}
let i = 0;
const warns = await getWarns(theUser);
if (!warns) {
return reply(`✅ <b>no warns for:</b> ${link(theUser)}`, replyOptions);
}
return reply(`⚠️ <b>Warns for</b> ${link(theUser)}:\n\n` +
warns
.map(warn => ++i + '. ' + warn)
.join('\n'), replyOptions);
};
module.exports = getWarnsHandler;

View File

@ -10,7 +10,7 @@ const leaveCommandHandler = require('./leave');
const warnHandler = require('./warn');
const unwarnHandler = require('./unwarn');
const nowarnsHandler = require('./nowarns');
const getWarnsHandler = require('./getwarns');
const userHandler = require('./user');
const banHandler = require('./ban');
const unbanHandler = require('./unban');
const reportHandler = require('./report');
@ -44,7 +44,7 @@ composer.command('leave', deleteMessage, leaveCommandHandler);
composer.command('warn', deleteMessage, warnHandler);
composer.command('unwarn', deleteMessage, unwarnHandler);
composer.command('nowarns', deleteMessage, nowarnsHandler);
composer.command('getwarns', deleteMessage, getWarnsHandler);
composer.command('user', deleteMessage, userHandler);
composer.command('ban', deleteMessage, banHandler);
composer.command('unban', deleteMessage, unbanHandler);
composer.command('report', deleteMessage, reportHandler);

62
handlers/commands/user.js Normal file
View File

@ -0,0 +1,62 @@
'use strict';
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { getUser, getWarns } = require('../../stores/user');
const getWarnsHandler = async ({ message, reply, state }) => {
const { isAdmin } = state;
if (!isAdmin) return null;
const mentionedUser = message.reply_to_message
? message.reply_to_message.from
: message.commandMention
? message.commandMention
: null;
if (!mentionedUser) {
return reply(
' <b>Reply to a message or mention a user.</b>',
replyOptions
).then(scheduleDeletion);
}
const theUser = await getUser({ id: mentionedUser.id });
if (theUser.status === 'admin') {
return reply(
`⭐️ ${link(theUser)} <b>is admin.</b>`,
replyOptions
).then(scheduleDeletion);
}
let i = 0;
const warns = await getWarns(theUser);
const warnsMessage = warns
? '⚠️ <b>Warns:</b>\n' +
warns
.map(warn => ++i + '. ' + warn)
.join('\n')
: '✅ <b>no warns</b>';
if (theUser.status === 'banned') {
return reply(
`🚫 ${link(theUser)} <b>is banned for:</b>\n` +
`${theUser.banReason}\n\n` +
warnsMessage,
replyOptions
);
}
return reply(
` ${link(theUser)} <b>is a member of network.</b>\n\n` +
warnsMessage,
replyOptions
);
};
module.exports = getWarnsHandler;