Skip to content

Commit

Permalink
Ensure consistent string case for channel name checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Aug 2, 2024
1 parent 013e296 commit 6c5177b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default () => {

fetchCurrentChannelInfo(auth)
.then((newChannelInfo) => {
if (typeof newChannelInfo?.broadcaster_name === "string") {
setChannelName(newChannelInfo.broadcaster_name);
if (typeof newChannelInfo?.broadcaster_login === "string") {
setChannelName(newChannelInfo.broadcaster_login.toLowerCase());
}
})
.catch((e) => {
Expand Down
23 changes: 14 additions & 9 deletions src/hooks/useChatCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import { typeSafeObjectEntries } from "../utils/helpers";

import useChannel from "./useChannel";

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(",") ?? [];
const parseCsvEnv = (env: string | undefined): string[] =>
env?.split(",").map((str) => str.toLowerCase()) ?? [];

const testChannelNames = parseCsvEnv(process.env.REACT_APP_TEST_CHANNEL_NAMES);
const defaultChannelNames = parseCsvEnv(
process.env.REACT_APP_DEFAULT_CHANNEL_NAMES,
);
const extraChannelNames = parseCsvEnv(
process.env.REACT_APP_EXTRA_CHANNEL_NAMES,
);
const privilegedUsers = parseCsvEnv(
process.env.REACT_APP_CHAT_COMMANDS_PRIVILEGED_USERS,
);

const getAmbassadorCommandsMap = (): Map<string, AmbassadorKey> => {
const commandMap = new Map<string, AmbassadorKey>();
Expand Down Expand Up @@ -67,7 +72,7 @@ export default function useChatCommand(callback: (command: string) => void) {
if (
!tags.mod &&
!tags.badges?.broadcaster &&
!privilegedUsers.includes(tags.username ?? "")
!privilegedUsers.includes(tags.username?.toLowerCase() ?? "")
)
return;
// Ignore echoed messages (messages sent by the bot) and messages that don't start with '!'
Expand Down

0 comments on commit 6c5177b

Please sign in to comment.