mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-30 05:37:59 +00:00
Add warn expiry; closes #27.
This commit is contained in:
parent
eeb571226d
commit
919c422c18
@ -1,29 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const dedent = require('dedent-js');
|
||||
const ms = require('millisecond');
|
||||
|
||||
const { context } = require('../bot');
|
||||
const { link } = require('../utils/tg');
|
||||
const { numberOfWarnsToBan } = require('../config');
|
||||
const {
|
||||
expireWarnsAfter = Infinity,
|
||||
numberOfWarnsToBan,
|
||||
} = require('../config');
|
||||
const { warn } = require('../stores/user');
|
||||
const ban = require('./ban');
|
||||
|
||||
const isNewerThan = date => warning => warning.date >= date;
|
||||
|
||||
module.exports = async ({ admin, reason, userToWarn }) => {
|
||||
const by_id = admin.id;
|
||||
const date = new Date();
|
||||
|
||||
const { warns } = await warn(userToWarn, { by_id, date, reason });
|
||||
const recentWarns = warns.filter(isNewerThan(date - ms(expireWarnsAfter)));
|
||||
|
||||
const isLastWarn = ', <b>last warning!</b>'
|
||||
.repeat(warns.length === numberOfWarnsToBan - 1);
|
||||
.repeat(recentWarns.length === numberOfWarnsToBan - 1);
|
||||
|
||||
const warnMessage = dedent(`
|
||||
⚠️ ${link(admin)} <b>warned</b> ${link(userToWarn)} <b>for</b>:
|
||||
|
||||
${reason} (${warns.length}/${numberOfWarnsToBan}${isLastWarn})`);
|
||||
${reason} (${recentWarns.length}/${numberOfWarnsToBan}${isLastWarn})`);
|
||||
|
||||
if (warns.length >= numberOfWarnsToBan) {
|
||||
if (recentWarns.length >= numberOfWarnsToBan) {
|
||||
await ban({
|
||||
admin: context.botInfo,
|
||||
reason: 'Reached max number of warnings',
|
||||
|
@ -14,8 +14,7 @@
|
||||
* Millisecond
|
||||
* String to be parsed by https://npmjs.com/millisecond,
|
||||
* or number of milliseconds. Pass 0 to remove immediately.
|
||||
* Pass false to disable option.
|
||||
* @typedef {( number | string | false )} ms
|
||||
* @typedef {( number | string )} ms
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
@ -46,6 +45,7 @@ module.exports = {
|
||||
* @type {ms} Millisecond
|
||||
* Timeout before removing join and leave messages.
|
||||
* [Look at typedef above for details.]
|
||||
* Pass false to disable this feature.
|
||||
*/
|
||||
deleteJoinsAfter: '2 minutes',
|
||||
|
||||
@ -55,6 +55,7 @@ module.exports = {
|
||||
* [Look at typedef above for details.]
|
||||
* Pass an object with { auto, manual } for more granular control
|
||||
* over which messages get deleted
|
||||
* Pass false to disable this feature.
|
||||
*/
|
||||
deleteWarnsAfter: false,
|
||||
|
||||
@ -62,6 +63,7 @@ module.exports = {
|
||||
* @type {ms}
|
||||
* Timeout before removing ban messages.
|
||||
* [Look at typedef above for details.]
|
||||
* Pass false to disable this feature.
|
||||
*/
|
||||
deleteBansAfter: false,
|
||||
|
||||
@ -82,6 +84,13 @@ module.exports = {
|
||||
*/
|
||||
excludeLinks: [],
|
||||
|
||||
/**
|
||||
* @type {ms}
|
||||
* Don't count warns older than this value towards automatic ban.
|
||||
* [Look at typedef above for details.]
|
||||
*/
|
||||
expireWarnsAfter: Infinity,
|
||||
|
||||
/**
|
||||
* @type {InlineKeyboardMarkup}
|
||||
* Inline keyboard to be added to reply to /groups.
|
||||
|
Loading…
x
Reference in New Issue
Block a user