diff --git a/src/backend/chat/twitch-chat.ts b/src/backend/chat/twitch-chat.ts index 23004ef99..00a63bdee 100644 --- a/src/backend/chat/twitch-chat.ts +++ b/src/backend/chat/twitch-chat.ts @@ -249,6 +249,14 @@ class TwitchChat extends EventEmitter { return; } } + if (slashCommandValidationResult != null && + slashCommandValidationResult.success === false && + slashCommandValidationResult.foundCommand !== false) { + global.renderWindow.webContents.send("chatUpdate", { + fbEvent: "ChatAlert", + message: slashCommandValidationResult.errorMessage + }); + } // split message into fragments that don't exceed the max message length const messageFragments = message diff --git a/src/backend/chat/twitch-commands/chat-handlers.ts b/src/backend/chat/twitch-commands/chat-handlers.ts index b9c07d3fe..ef2997915 100644 --- a/src/backend/chat/twitch-commands/chat-handlers.ts +++ b/src/backend/chat/twitch-commands/chat-handlers.ts @@ -160,8 +160,14 @@ export const shoutoutHandler: TwitchSlashCommandHandler<[string]> = { if (targetUserId == null) { return false; } - - return await twitchApi.chat.sendShoutout(targetUserId); + const result = await twitchApi.chat.sendShoutout(targetUserId); + if (!result.success) { + global.renderWindow.webContents.send("chatUpdate", { + fbEvent: "ChatAlert", + message: result.error + }); + } + return result.success; } }; diff --git a/src/backend/effects/builtin/twitch/shoutout.ts b/src/backend/effects/builtin/twitch/shoutout.ts index 7fa7a0193..df4a91232 100644 --- a/src/backend/effects/builtin/twitch/shoutout.ts +++ b/src/backend/effects/builtin/twitch/shoutout.ts @@ -45,8 +45,14 @@ const model: EffectType<{ logger.error(`Unable to shoutout channel. Twitch user ${effect.username} does not exist.`); return false; } - - return await twitchApi.chat.sendShoutout(targetUserId); + const result = await twitchApi.chat.sendShoutout(targetUserId); + if (!result.success) { + global.renderWindow.webContents.send("chatUpdate", { + fbEvent: "ChatAlert", + message: result.error + }); + } + return result.success; } }; diff --git a/src/backend/twitch-api/resource/chat.ts b/src/backend/twitch-api/resource/chat.ts index 0decf2961..e809bad5f 100644 --- a/src/backend/twitch-api/resource/chat.ts +++ b/src/backend/twitch-api/resource/chat.ts @@ -2,6 +2,12 @@ import logger from '../../logwrapper'; import accountAccess from "../../common/account-access"; import { ApiClient, HelixChatAnnouncementColor, HelixChatChatter, HelixSendChatAnnouncementParams, HelixSentChatMessage, HelixUpdateChatSettingsParams } from "@twurple/api"; +interface ResultWithError { + success: boolean; + result?: TResult; + error?: TError; +} + export class TwitchChatApi { private _streamerClient: ApiClient; private _botClient: ApiClient; @@ -123,18 +129,19 @@ export class TwitchChatApi { * Sends a Twitch shoutout to another channel * * @param targetUserId The Twitch user ID whose channel to shoutout + * @returns true when successful, error message string when unsuccessful */ - async sendShoutout(targetUserId: string): Promise { + async sendShoutout(targetUserId: string): Promise> { const streamerId = accountAccess.getAccounts().streamer.userId; try { await this._streamerClient.chat.shoutoutUser(streamerId, targetUserId); } catch (error) { logger.error("Error sending shoutout", error.message); - return false; + const body = JSON.parse(error._body); + return { success: false, error: body.message }; } - - return true; + return { success: true }; } /**