Tags: don't crash when using tags with invalid format, but log it to console instead
This commit is contained in:
parent
f27da2c56f
commit
8711f86193
1 changed files with 14 additions and 5 deletions
|
@ -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 { Message, TextChannel } from "eris";
|
||||||
import { errorMessage, successMessage } from "../utils";
|
import { errorMessage, successMessage } from "../utils";
|
||||||
import { GuildTags } from "../data/GuildTags";
|
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);
|
const tagArgs = this.commands.parseArguments(variableStr).map(v => v.value);
|
||||||
|
|
||||||
// Format the string
|
// Format the string
|
||||||
body = await renderTemplate(body, {
|
try {
|
||||||
args: tagArgs,
|
body = await renderTemplate(body, {
|
||||||
...this.tagFunctions,
|
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 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