Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra channels to connect to when not in default #155

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading