From 8711f861934b3675ba06a2832b2c906aab2adaae Mon Sep 17 00:00:00 2001 From: Dragory Date: Sat, 16 Mar 2019 17:00:57 +0200 Subject: [PATCH] Tags: don't crash when using tags with invalid format, but log it to console instead --- src/plugins/Tags.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/plugins/Tags.ts b/src/plugins/Tags.ts index 71dc9511..b141ef15 100644 --- a/src/plugins/Tags.ts +++ b/src/plugins/Tags.ts @@ -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 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);