From 365f3bfda387cb19dfb420cd53b72770031659cd Mon Sep 17 00:00:00 2001 From: CKY- Date: Wed, 24 Apr 2024 14:47:01 -0600 Subject: [PATCH 1/2] Feat: add chatFeed for slash commands --- src/backend/chat/twitch-chat.ts | 8 ++++++++ src/backend/twitch-api/resource/chat.ts | 5 +++++ 2 files changed, 13 insertions(+) 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/twitch-api/resource/chat.ts b/src/backend/twitch-api/resource/chat.ts index 0decf2961..1616b097c 100644 --- a/src/backend/twitch-api/resource/chat.ts +++ b/src/backend/twitch-api/resource/chat.ts @@ -131,6 +131,11 @@ export class TwitchChatApi { await this._streamerClient.chat.shoutoutUser(streamerId, targetUserId); } catch (error) { logger.error("Error sending shoutout", error.message); + const body = JSON.parse(error._body); + global.renderWindow.webContents.send("chatUpdate", { + fbEvent: "ChatAlert", + message: body.message + }); return false; } From 9afc268c16bca623c9a41fa3f74dd38fe8963c0a Mon Sep 17 00:00:00 2001 From: CKY- Date: Thu, 6 Jun 2024 14:38:44 -0600 Subject: [PATCH 2/2] Feat:Move chat feed out of api --- .../chat/twitch-commands/chat-handlers.ts | 10 ++++++++-- src/backend/effects/builtin/twitch/shoutout.ts | 10 ++++++++-- src/backend/twitch-api/resource/chat.ts | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 12 deletions(-) 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 1616b097c..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,8 +129,9 @@ 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 { @@ -132,14 +139,9 @@ export class TwitchChatApi { } catch (error) { logger.error("Error sending shoutout", error.message); const body = JSON.parse(error._body); - global.renderWindow.webContents.send("chatUpdate", { - fbEvent: "ChatAlert", - message: body.message - }); - return false; + return { success: false, error: body.message }; } - - return true; + return { success: true }; } /**