Skip to content

Commit

Permalink
Add extra channels to connect to when not in default (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 authored Feb 10, 2024
1 parent 7dd8e3a commit bccaa13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions src/hooks/useChatCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(",") ?? [];

Expand Down Expand Up @@ -50,7 +52,24 @@ const getAmbassadorCommandsMap = (): Map<string, AmbassadorKey> => {
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],
);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bccaa13

Please sign in to comment.