2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-31 14:15:25 +00:00

Handle expiry in /unwarn

This commit is contained in:
Wojciech Pawlik
2020-05-08 21:31:02 +02:00
parent 8925648216
commit 9ad99e6c82

View File

@@ -1,3 +1,4 @@
// @ts-check
'use strict';
const { last } = require('ramda');
@@ -5,6 +6,7 @@ const XRegExp = require('xregexp');
// Utils
const { escapeHtml, link, scheduleDeletion } = require('../../utils/tg');
const { isWarnNotExpired } = require('../../utils/config');
const { parse, strip } = require('../../utils/parse');
// Config
@@ -17,8 +19,6 @@ const { replyOptions } = require('../../bot/options');
const { listGroups } = require('../../stores/group');
const { getUser, unwarn } = require('../../stores/user');
const noop = Function.prototype;
const dateRegex = XRegExp.tag('nix')`^
\d{4} # year
-\d{2} # month
@@ -52,7 +52,7 @@ const unwarnHandler = async ({ from, message, reply, telegram }) => {
).then(scheduleDeletion());
}
const allWarns = userToUnwarn.warns;
const allWarns = userToUnwarn.warns.filter(isWarnNotExpired(new Date()));
if (allWarns.length === 0) {
return reply(
@@ -95,7 +95,7 @@ const unwarnHandler = async ({ from, message, reply, telegram }) => {
telegram.sendMessage(
userToUnwarn.id,
'♻️ You were unbanned from all of the /groups!',
).catch(noop);
).catch(() => null);
// it's likely that the banned person haven't PMed the bot,
// which will cause the sendMessage to fail,
// hance .catch(noop)