3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Run user-supplied regexes in worker threads with a timeout

This commit is contained in:
Dragory 2020-08-05 01:15:36 +03:00
parent 19b97bc32b
commit a7fa258f2a
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
15 changed files with 237 additions and 43 deletions

View file

@ -4,6 +4,7 @@ import { LogType } from "src/data/LogType";
import { TextChannel } from "eris";
import { createChunkedMessage, noop } from "src/utils";
import { getLogMessage } from "./getLogMessage";
import { allowTimeout } from "../../../RegExpRunner";
const excludedUserProps = ["user", "member", "mod"];
@ -45,7 +46,8 @@ export async function log(pluginData: PluginData<LogsPluginType>, type: LogType,
// If this entry contains a message with an excluded regex, skip it
if (type === LogType.MESSAGE_DELETE && opts.excluded_message_regexes && data.message.data.content) {
for (const regex of opts.excluded_message_regexes) {
if (regex.test(data.message.data.content)) {
const matches = await pluginData.state.regexRunner.exec(regex, data.message.data.content).catch(allowTimeout);
if (matches) {
continue logChannelLoop;
}
}
@ -53,7 +55,8 @@ export async function log(pluginData: PluginData<LogsPluginType>, type: LogType,
if (type === LogType.MESSAGE_EDIT && opts.excluded_message_regexes && data.before.data.content) {
for (const regex of opts.excluded_message_regexes) {
if (regex.test(data.before.data.content)) {
const matches = await pluginData.state.regexRunner.exec(regex, data.message.data.content).catch(allowTimeout);
if (matches) {
continue logChannelLoop;
}
}