mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Fix nested tag limiter
This commit is contained in:
parent
05df81ddca
commit
204a8619ae
1 changed files with 12 additions and 4 deletions
|
@ -5,16 +5,17 @@ import { renderRecursively, StrictMessageContent } from "../../../utils";
|
||||||
import { TagsPluginType, TTag } from "../types";
|
import { TagsPluginType, TTag } from "../types";
|
||||||
import { findTagByName } from "./findTagByName";
|
import { findTagByName } from "./findTagByName";
|
||||||
|
|
||||||
|
const MAX_TAG_FN_CALLS = 25;
|
||||||
|
|
||||||
export async function renderTagBody(
|
export async function renderTagBody(
|
||||||
pluginData: GuildPluginData<TagsPluginType>,
|
pluginData: GuildPluginData<TagsPluginType>,
|
||||||
body: TTag,
|
body: TTag,
|
||||||
args: TemplateSafeValue[] = [],
|
args: TemplateSafeValue[] = [],
|
||||||
extraData = {},
|
extraData = {},
|
||||||
subTagPermissionMatchParams?: ExtendedMatchParams,
|
subTagPermissionMatchParams?: ExtendedMatchParams,
|
||||||
|
tagFnCallsObj = { calls: 0 },
|
||||||
): Promise<StrictMessageContent> {
|
): Promise<StrictMessageContent> {
|
||||||
const dynamicVars = {};
|
const dynamicVars = {};
|
||||||
const maxTagFnCalls = 25;
|
|
||||||
let tagFnCalls = 0;
|
|
||||||
|
|
||||||
const data = new TemplateSafeValueContainer({
|
const data = new TemplateSafeValueContainer({
|
||||||
args,
|
args,
|
||||||
|
@ -33,7 +34,7 @@ export async function renderTagBody(
|
||||||
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
||||||
},
|
},
|
||||||
tag: async (name, ...subTagArgs) => {
|
tag: async (name, ...subTagArgs) => {
|
||||||
if (tagFnCalls++ > maxTagFnCalls) return "\\_recursion\\_";
|
if (++tagFnCallsObj.calls > MAX_TAG_FN_CALLS) return "";
|
||||||
if (typeof name !== "string") return "";
|
if (typeof name !== "string") return "";
|
||||||
if (name === "") return "";
|
if (name === "") return "";
|
||||||
|
|
||||||
|
@ -47,7 +48,14 @@ export async function renderTagBody(
|
||||||
return "<embed>";
|
return "<embed>";
|
||||||
}
|
}
|
||||||
|
|
||||||
const rendered = await renderTagBody(pluginData, subTagBody, subTagArgs, extraData, subTagPermissionMatchParams);
|
const rendered = await renderTagBody(
|
||||||
|
pluginData,
|
||||||
|
subTagBody,
|
||||||
|
subTagArgs,
|
||||||
|
extraData,
|
||||||
|
subTagPermissionMatchParams,
|
||||||
|
tagFnCallsObj,
|
||||||
|
);
|
||||||
return rendered.content!;
|
return rendered.content!;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue