mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-09-01 14:45:27 +00:00
Allow some custom commands in /warn and /ban
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
// Utils
|
// Utils
|
||||||
const { displayUser, scheduleDeletion } = require('../../utils/tg');
|
const { displayUser, scheduleDeletion } = require('../../utils/tg');
|
||||||
const { html } = require('../../utils/html');
|
const { html } = require('../../utils/html');
|
||||||
const { parse, strip } = require('../../utils/cmd');
|
const { parse, strip, substom } = require('../../utils/cmd');
|
||||||
|
|
||||||
// Bot
|
// 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;
|
module.exports = banHandler;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
const { parse, strip } = require('../../utils/cmd');
|
const { parse, strip, substom } = require('../../utils/cmd');
|
||||||
const { scheduleDeletion } = require('../../utils/tg');
|
const { scheduleDeletion } = require('../../utils/tg');
|
||||||
|
|
||||||
// DB
|
// DB
|
||||||
@@ -53,7 +53,7 @@ const warnHandler = async (ctx) => {
|
|||||||
return ctx.warn({
|
return ctx.warn({
|
||||||
admin: ctx.from,
|
admin: ctx.from,
|
||||||
amend: flags.has('amend'),
|
amend: flags.has('amend'),
|
||||||
reason,
|
reason: await substom(reason),
|
||||||
userToWarn,
|
userToWarn,
|
||||||
mode: 'manual',
|
mode: 'manual',
|
||||||
});
|
});
|
||||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@@ -390,8 +390,7 @@
|
|||||||
"escape-string-regexp": {
|
"escape-string-regexp": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"eslint": {
|
"eslint": {
|
||||||
"version": "6.8.0",
|
"version": "6.8.0",
|
||||||
@@ -1015,6 +1014,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
"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": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
@@ -1266,6 +1270,15 @@
|
|||||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
|
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
|
||||||
"dev": true
|
"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": {
|
"string-width": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
"ramda": "^0.25.0",
|
"ramda": "^0.25.0",
|
||||||
"require-directory": "^2.1.1",
|
"require-directory": "^2.1.1",
|
||||||
"spamwatch": "^0.2.0",
|
"spamwatch": "^0.2.0",
|
||||||
|
"string-replace-async": "^1.2.1",
|
||||||
"telegraf": "^3.38.0",
|
"telegraf": "^3.38.0",
|
||||||
"ts-node": "^8.9.1",
|
"ts-node": "^8.9.1",
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^3.8.3",
|
||||||
|
@@ -3,4 +3,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
...require('../parse'), // eslint-disable-line global-require
|
...require('../parse'), // eslint-disable-line global-require
|
||||||
...require('./stringify'), // 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
14
utils/cmd/substom.ts
Normal 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 + " ";
|
||||||
|
});
|
Reference in New Issue
Block a user