ZeppelinPlugin: add utility function to check if we can use an emoji
This commit is contained in:
parent
da1a0a1da1
commit
77694ca951
1 changed files with 15 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { IPluginOptions, Plugin } from "knub";
|
import { IPluginOptions, Plugin } from "knub";
|
||||||
import { PluginRuntimeError } from "../PluginRuntimeError";
|
import { PluginRuntimeError } from "../PluginRuntimeError";
|
||||||
import Ajv, { ErrorObject } from "ajv";
|
import Ajv, { ErrorObject } from "ajv";
|
||||||
|
import { isSnowflake, isUnicodeEmoji } from "../utils";
|
||||||
|
|
||||||
export class ZeppelinPlugin extends Plugin {
|
export class ZeppelinPlugin extends Plugin {
|
||||||
protected configSchema: any;
|
protected configSchema: any;
|
||||||
|
@ -74,4 +75,18 @@ export class ZeppelinPlugin extends Plugin {
|
||||||
|
|
||||||
return super.runLoad();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue