From 77694ca9513ade3ef27f15dac2283a61901caff0 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sat, 9 Feb 2019 14:34:42 +0200 Subject: [PATCH] ZeppelinPlugin: add utility function to check if we can use an emoji --- src/plugins/ZeppelinPlugin.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plugins/ZeppelinPlugin.ts b/src/plugins/ZeppelinPlugin.ts index 9fb5a4a7..cd6a5649 100644 --- a/src/plugins/ZeppelinPlugin.ts +++ b/src/plugins/ZeppelinPlugin.ts @@ -1,6 +1,7 @@ import { IPluginOptions, Plugin } from "knub"; import { PluginRuntimeError } from "../PluginRuntimeError"; import Ajv, { ErrorObject } from "ajv"; +import { isSnowflake, isUnicodeEmoji } from "../utils"; export class ZeppelinPlugin extends Plugin { protected configSchema: any; @@ -74,4 +75,18 @@ export class ZeppelinPlugin extends Plugin { return super.runLoad(); } + + public canUseEmoji(snowflake): boolean { + if (isUnicodeEmoji(snowflake)) { + return true; + } else if (isSnowflake(snowflake)) { + for (const guild of this.bot.guilds.values()) { + if (guild.emojis.some(e => (e as any).id === snowflake)) { + return true; + } + } + } else { + throw new PluginRuntimeError(`Invalid emoji: ${snowflake}`, this.runtimePluginName, this.guildId); + } + } }