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

Allow some custom commands in /warn and /ban

This commit is contained in:
Wojciech Pawlik
2020-05-23 21:56:04 +02:00
parent 9db362f6ad
commit 1a9e3cecd0
6 changed files with 39 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
// Utils
const { displayUser, scheduleDeletion } = require('../../utils/tg');
const { html } = require('../../utils/html');
const { parse, strip } = require('../../utils/cmd');
const { parse, strip, substom } = require('../../utils/cmd');
// Bot
@@ -63,7 +63,11 @@ const banHandler = async (ctx) => {
);
}
return ctx.ban({ admin: ctx.from, reason, userToBan });
return ctx.ban({
admin: ctx.from,
reason: await substom(reason),
userToBan,
});
};
module.exports = banHandler;

View File

@@ -1,7 +1,7 @@
'use strict';
// Utils
const { parse, strip } = require('../../utils/cmd');
const { parse, strip, substom } = require('../../utils/cmd');
const { scheduleDeletion } = require('../../utils/tg');
// DB
@@ -53,7 +53,7 @@ const warnHandler = async (ctx) => {
return ctx.warn({
admin: ctx.from,
amend: flags.has('amend'),
reason,
reason: await substom(reason),
userToWarn,
mode: 'manual',
});

17
package-lock.json generated
View File

@@ -390,8 +390,7 @@
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"eslint": {
"version": "6.8.0",
@@ -1015,6 +1014,11 @@
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -1266,6 +1270,15 @@
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"string-replace-async": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/string-replace-async/-/string-replace-async-1.2.1.tgz",
"integrity": "sha1-1SzcfjOBQbvq6jRx3jEhUCjJo6o=",
"requires": {
"escape-string-regexp": "^1.0.4",
"object-assign": "^4.0.1"
}
},
"string-width": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",

View File

@@ -38,6 +38,7 @@
"ramda": "^0.25.0",
"require-directory": "^2.1.1",
"spamwatch": "^0.2.0",
"string-replace-async": "^1.2.1",
"telegraf": "^3.38.0",
"ts-node": "^8.9.1",
"typescript": "^3.8.3",

View File

@@ -3,4 +3,5 @@
module.exports = {
...require('../parse'), // eslint-disable-line global-require
...require('./stringify'), // eslint-disable-line global-require
...require('./substom'), // eslint-disable-line global-require
};

14
utils/cmd/substom.ts Normal file
View File

@@ -0,0 +1,14 @@
import replace = require("string-replace-async");
import { getCommand } from "../../stores/command";
export const substom = (reason: string): Promise<string> =>
replace(reason, /!\s?(\w+)\s*|.+/g, async (match, name) => {
if (!name) return match;
const command = await getCommand({
name: name.toLowerCase(),
role: "admins",
type: "copy",
});
if (!command) return match;
return command.content.text + " ";
});