From fd47ba9d6904bc2d05419a13f0c3b986a061e5cc Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 12 Jan 2020 13:44:31 +0200 Subject: [PATCH] Set default success emoji to zep_check; add error_emoji support, mirroring success_emoji but for error messages --- backend/src/index.ts | 10 ++++++---- backend/src/types.ts | 5 ++--- backend/src/utils.ts | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 7e5d645c..46a01d7e 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -4,7 +4,7 @@ import yaml from "js-yaml"; import fs from "fs"; const fsp = fs.promises; -import { Knub, logger, PluginError, Plugin, IGlobalConfig, IGuildConfig, IGuildData } from "knub"; +import { Knub, logger, PluginError, Plugin, IGlobalConfig, IGuildConfig } from "knub"; import { SimpleError } from "./SimpleError"; import DiscordRESTError from "eris/lib/errors/DiscordRESTError"; // tslint:disable-line @@ -162,13 +162,15 @@ connect().then(async conn => { customArgumentTypes, sendSuccessMessageFn(channel, body) { - const guildId = channel instanceof TextChannel ? channel.guild.id : null; - const emoji = (guildId ? bot.getGuildData(guildId).config.success_emoji : null) ?? "default emoji here"; + const guildId = channel instanceof TextChannel ? channel.guild.id : undefined; + const emoji = guildId ? bot.getGuildData(guildId).config.success_emoji : undefined; channel.createMessage(successMessage(body, emoji)); }, sendErrorMessageFn(channel, body) { - channel.createMessage(errorMessage(body)); + const guildId = channel instanceof TextChannel ? channel.guild.id : undefined; + const emoji = guildId ? bot.getGuildData(guildId).config.error_emoji : undefined; + channel.createMessage(errorMessage(body, emoji)); }, }, }); diff --git a/backend/src/types.ts b/backend/src/types.ts index 676279fa..bb80dee7 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -1,9 +1,8 @@ import { IGlobalConfig, IGuildConfig, Knub } from "knub"; -// Remove this tslint exception once there are properties in the interface -// tslint:disable-next-line export interface IZeppelinGuildConfig extends IGuildConfig { - // To fill + success_emoji?: string; + error_emoji?: string; } export interface IZeppelinGlobalConfig extends IGlobalConfig { diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 5821c389..79dd8ec3 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -264,12 +264,12 @@ export function convertMSToDelayString(ms: number): string { return result; } -export function successMessage(str, emoji) { - return `${emoji} ${str}`; +export function successMessage(str, emoji = "<:zep_check:650361014180904971>") { + return emoji ? `${emoji} ${str}` : str; } -export function errorMessage(str) { - return `⚠ ${str}`; +export function errorMessage(str, emoji = "⚠") { + return emoji ? `${emoji} ${str}` : str; } export function get(obj, path, def?): any {