From 53b37e9dfa5c7164e21e280f3b56435b8c825e4f Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Wed, 18 Apr 2018 21:47:35 +0200 Subject: [PATCH] Change warn schema to array of objects (#47) --- actions/warn.js | 5 ++++- handlers/commands/unwarn.js | 6 +++++- handlers/commands/user.js | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/actions/warn.js b/actions/warn.js index 4fcf37c..1f3dc4d 100644 --- a/actions/warn.js +++ b/actions/warn.js @@ -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 = ', last warning!' .repeat(warns.length === numberOfWarnsToBan - 1); diff --git a/handlers/commands/unwarn.js b/handlers/commands/unwarn.js index ae9ff92..36939db 100644 --- a/handlers/commands/unwarn.js +++ b/handlers/commands/unwarn.js @@ -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)} pardoned ${link(userToUnwarn)} ` + - `for:\n\n${allWarns[allWarns.length - 1]}` + + `for:\n\n${lastWarn.reason || lastWarn}` + ` (${allWarns.length - 1}/${numberOfWarnsToBan})`, replyOptions ); diff --git a/handlers/commands/user.js b/handlers/commands/user.js index 5f14d67..42c1e9c 100644 --- a/handlers/commands/user.js +++ b/handlers/commands/user.js @@ -34,7 +34,7 @@ const getWarnsHandler = async ({ message, reply, state }) => { : ''; const userWarns = warns.length ? '\n⚠️ Warns:\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; -