From 56521d5b58e054ce8099b3fbb2972d0f9bb5ad4a Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Mon, 5 Feb 2024 04:31:45 +0000 Subject: [PATCH] Add extra channels to connect to when not in default --- .env.sample | 1 + src/hooks/useChatCommand.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index 9ac90b08..a952dcef 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,3 @@ REACT_APP_CHAT_COMMANDS_PRIVILEGED_USERS=abdullahmorrison,mattipv4,pjeweb,alveusgg,spacevoyage REACT_APP_DEFAULT_CHANNEL_NAMES=maya,alveussanctuary +REACT_APP_EXTRA_CHANNEL_NAMES=alveusgg diff --git a/src/hooks/useChatCommand.ts b/src/hooks/useChatCommand.ts index 7c8ce9a1..95388fdd 100644 --- a/src/hooks/useChatCommand.ts +++ b/src/hooks/useChatCommand.ts @@ -10,6 +10,8 @@ const testChannelNames = process.env.REACT_APP_TEST_CHANNEL_NAMES?.split(",") ?? []; const defaultChannelNames = process.env.REACT_APP_DEFAULT_CHANNEL_NAMES?.split(",") ?? []; +const extraChannelNames = + process.env.REACT_APP_EXTRA_CHANNEL_NAMES?.split(",") ?? []; const privilegedUsers = process.env.REACT_APP_CHAT_COMMANDS_PRIVILEGED_USERS?.split(",") ?? []; @@ -50,7 +52,24 @@ const getAmbassadorCommandsMap = (): Map => { export default function useChatCommand(callback: (command: string) => void) { const channel = useChannel(); const channelNames = useMemo( - () => [...testChannelNames, ...(channel ? [channel] : defaultChannelNames)], + () => + Array.from( + new Set( + [ + // Always connect to any test channels, for development. + ...testChannelNames, + // If we know what channel we're in, connect to it. + // Otherwise, connect to the default channels. + ...(channel ? [channel] : defaultChannelNames), + // If we're not in a default channel, connect to the extra channels. + // Extra channels are used for mod control during collaborations, + // so we don't need to connect to them if we're in a default channel. + ...(channel && !defaultChannelNames.includes(channel) + ? extraChannelNames + : []), + ].map((name) => name.toLowerCase()), + ), + ), [channel], ); @@ -121,7 +140,10 @@ export default function useChatCommand(callback: (command: string) => void) { return; } - console.log("*Twitch extension is connected to chat*", id); + console.log( + `*Twitch extension is connected to chat: ${channelNames.join(", ")}*`, + id, + ); }); // Connect to chat