diff --git a/handlers/commands/getwarns.js b/handlers/commands/getwarns.js deleted file mode 100644 index f53375f..0000000 --- a/handlers/commands/getwarns.js +++ /dev/null @@ -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( - 'ℹ️ Reply to a message or mention a user.', - replyOptions - ).then(scheduleDeletion); - } - let i = 0; - const warns = await getWarns(theUser); - if (!warns) { - return reply(`✅ no warns for: ${link(theUser)}`, replyOptions); - } - return reply(`⚠️ Warns for ${link(theUser)}:\n\n` + - warns - .map(warn => ++i + '. ' + warn) - .join('\n'), replyOptions); -}; - -module.exports = getWarnsHandler; diff --git a/handlers/commands/index.js b/handlers/commands/index.js index 4b97716..01bc7cf 100644 --- a/handlers/commands/index.js +++ b/handlers/commands/index.js @@ -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); diff --git a/handlers/commands/user.js b/handlers/commands/user.js new file mode 100644 index 0000000..c326924 --- /dev/null +++ b/handlers/commands/user.js @@ -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( + 'ℹ️ Reply to a message or mention a user.', + replyOptions + ).then(scheduleDeletion); + } + + const theUser = await getUser({ id: mentionedUser.id }); + + if (theUser.status === 'admin') { + return reply( + `⭐️ ${link(theUser)} is admin.`, + replyOptions + ).then(scheduleDeletion); + } + + let i = 0; + const warns = await getWarns(theUser); + const warnsMessage = warns + ? '⚠️ Warns:\n' + + warns + .map(warn => ++i + '. ' + warn) + .join('\n') + : '✅ no warns'; + + if (theUser.status === 'banned') { + return reply( + `🚫 ${link(theUser)} is banned for:\n` + + `${theUser.banReason}\n\n` + + warnsMessage, + replyOptions + ); + } + + return reply( + `ℹ️ ${link(theUser)} is a member of network.\n\n` + + warnsMessage, + replyOptions + ); +}; + +module.exports = getWarnsHandler;