2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 21:55:17 +00:00

getwarns and nowarns now check if there are warnings

This commit is contained in:
Pouria Ezzati
2017-09-24 22:17:27 +03:30
parent 50c6f76968
commit 4455541afe
2 changed files with 12 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ const { link } = require('../../utils/tg');
const { replyOptions } = require('../../bot/options');
// DB
const Warn = require('../../stores/warn');
const { getWarns } = require('../../stores/warn');
const admins = require('../../stores/admin');
const getWarnsHandler = async ({ message, reply }) => {
@@ -19,8 +19,12 @@ const getWarnsHandler = async ({ message, reply }) => {
}
let i = 0;
const theUser = message.reply_to_message.from;
const warns = await getWarns(theUser);
if (warns.length < 1) {
return reply(`✅ <b>no warns for:</b> ${link(theUser)}`, replyOptions);
}
return reply(`⚠️ <b>Warns for</b> ${link(theUser)}:\n\n` +
(await Warn.getWarns(theUser))
warns
.map(warn => ++i + '. ' + warn)
.join('\n\n'), replyOptions);
};

View File

@@ -8,7 +8,7 @@ const { logError } = require('../../utils/log');
const { replyOptions } = require('../../bot/options');
// DB
const { nowarns } = require('../../stores/warn');
const { getWarns, nowarns } = require('../../stores/warn');
const admins = require('../../stores/admin');
const nowarnsHandler = async ({ message, reply }) => {
@@ -21,7 +21,12 @@ const nowarnsHandler = async ({ message, reply }) => {
const messageToUnwarn = message.reply_to_message;
const userToUnwarn = messageToUnwarn.from;
const warns = await getWarns(userToUnwarn);
if (warns.length < 1) {
return reply(` ${link(userToUnwarn)} <b>already has no warnings.</b>`,
replyOptions);
}
try {
await nowarns(userToUnwarn);
} catch (err) {