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

Change warn schema to array of objects (#47)

This commit is contained in:
GingerPlusPlus
2018-04-18 21:47:35 +02:00
parent 47d33ad025
commit 53b37e9dfa
3 changed files with 10 additions and 4 deletions

View File

@@ -10,7 +10,10 @@ const ban = require('./ban');
module.exports = async ({ admin, userToWarn, reason }) => {
const { warns } = await warn(userToWarn, reason);
const by_id = admin.id;
const date = new Date();
const { warns } = await warn(userToWarn, { by_id, date, reason });
const isLastWarn = ', <b>last warning!</b>'
.repeat(warns.length === numberOfWarnsToBan - 1);

View File

@@ -1,5 +1,7 @@
'use strict';
const { last } = require('ramda');
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
@@ -63,9 +65,11 @@ const unwarnHandler = async ({ message, reply, state, telegram }) => {
// (it's an expected, non-critical failure)
}
const lastWarn = last(allWarns);
return reply(
`${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
`<b>for:</b>\n\n${allWarns[allWarns.length - 1]}` +
`<b>for:</b>\n\n${lastWarn.reason || lastWarn}` +
` (${allWarns.length - 1}/${numberOfWarnsToBan})`,
replyOptions
);

View File

@@ -34,7 +34,7 @@ const getWarnsHandler = async ({ message, reply, state }) => {
: '';
const userWarns = warns.length
? '\n<b>⚠️ Warns:</b>\n' + warns
.map((warn, i) => `${i + 1}. ${warn}`)
.map((warn, i) => `${i + 1}. ${warn.reason || warn}`)
.join('\n') + '\n'
: '';
@@ -50,4 +50,3 @@ const getWarnsHandler = async ({ message, reply, state }) => {
};
module.exports = getWarnsHandler;