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