mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Tags: add tag() function to call other tags (with infinite loop protection 👀)
This commit is contained in:
parent
45b06ece20
commit
e61fe722c5
1 changed files with 16 additions and 2 deletions
|
@ -197,7 +197,10 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig, ITagsPluginPer
|
||||||
// Format the string
|
// Format the string
|
||||||
try {
|
try {
|
||||||
const dynamicVars = {};
|
const dynamicVars = {};
|
||||||
body = await renderTemplate(body, {
|
const maxTagFnCalls = 25;
|
||||||
|
let tagFnCalls = 0;
|
||||||
|
|
||||||
|
const data = {
|
||||||
args: tagArgs,
|
args: tagArgs,
|
||||||
...this.tagFunctions,
|
...this.tagFunctions,
|
||||||
set(name, val) {
|
set(name, val) {
|
||||||
|
@ -207,7 +210,17 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig, ITagsPluginPer
|
||||||
get(name) {
|
get(name) {
|
||||||
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
||||||
},
|
},
|
||||||
});
|
tag: async (name, ...args) => {
|
||||||
|
if (tagFnCalls++ > maxTagFnCalls) return "\\_recursion\\_";
|
||||||
|
if (typeof name !== "string") return "";
|
||||||
|
if (name === "") return "";
|
||||||
|
const subTag = await this.tags.find(name);
|
||||||
|
if (!subTag) return "";
|
||||||
|
return renderTemplate(subTag.body, { ...data, args });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
body = await renderTemplate(body, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
if (e instanceof TemplateParseError) {
|
||||||
logger.warn(`Invalid tag format!\nError: ${e.message}\nFormat: ${tag.body}`);
|
logger.warn(`Invalid tag format!\nError: ${e.message}\nFormat: ${tag.body}`);
|
||||||
|
@ -218,6 +231,7 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig, ITagsPluginPer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.trim() === "") return;
|
if (body.trim() === "") return;
|
||||||
|
if (body.length > 2048) return;
|
||||||
|
|
||||||
const channel = this.guild.channels.get(msg.channel_id) as TextChannel;
|
const channel = this.guild.channels.get(msg.channel_id) as TextChannel;
|
||||||
const responseMsg = await channel.createMessage(body);
|
const responseMsg = await channel.createMessage(body);
|
||||||
|
|
Loading…
Add table
Reference in a new issue