2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-29 05:07:49 +00:00

40 lines
1.0 KiB
JavaScript
Raw Normal View History

'use strict';
const dedent = require('dedent-js');
const { context } = require('../bot');
const { link } = require('../utils/tg');
const { numberOfWarnsToBan } = require('../config');
const { warn } = require('../stores/user');
const ban = require('./ban');
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 isLastWarn = ', <b>last warning!</b>'
.repeat(warns.length === numberOfWarnsToBan - 1);
const warnMessage = dedent(`
${link(admin)} <b>warned</b> ${link(userToWarn)} <b>for</b>:
${reason} (${warns.length}/${numberOfWarnsToBan}${isLastWarn})`);
if (warns.length >= numberOfWarnsToBan) {
await ban({
admin: context.botInfo,
reason: 'Reached max number of warnings',
userToBan: userToWarn,
});
return warnMessage +
'\n\n' +
'🚫 The user was <b>banned</b> ' +
`for receiving ${numberOfWarnsToBan} warnings!`;
}
return warnMessage;
};