3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Tags: don't crash when using tags with invalid format, but log it to console instead

This commit is contained in:
Dragory 2019-03-16 17:00:57 +02:00
parent f27da2c56f
commit 8711f86193

View file

@ -1,4 +1,4 @@
import { decorators as d, IPluginOptions } from "knub";
import { decorators as d, IPluginOptions, logger } from "knub";
import { Message, TextChannel } from "eris";
import { errorMessage, successMessage } from "../utils";
import { GuildTags } from "../data/GuildTags";
@ -195,10 +195,19 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig, ITagsPluginPer
const tagArgs = this.commands.parseArguments(variableStr).map(v => v.value);
// Format the string
body = await renderTemplate(body, {
args: tagArgs,
...this.tagFunctions,
});
try {
body = await renderTemplate(body, {
args: tagArgs,
...this.tagFunctions,
});
} catch (e) {
if (e instanceof TemplateParseError) {
logger.warn(`Invalid tag format!\nError: ${e.message}\nFormat: ${tag.body}`);
return;
} else {
throw e;
}
}
const channel = this.guild.channels.get(msg.channel_id) as TextChannel;
const responseMsg = await channel.createMessage(body);