Skip to content

Commit

Permalink
fix: Extension now respects access settings set by broadcaster
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed Sep 18, 2023
1 parent 7e56780 commit 0628028
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 62 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@
"default": "Viewers",
"description": "Users who are allowed to use the extension via Twitch chat."
},
"twitchThemer.installState": {
"title": "Install Access",
"type": "string",
"enum": [
"Viewers",
"Followers",
"Subscribers",
"VIPs",
"Moderators",
"Broadcaster"
],
"default": "Followers",
"description": "Users who are allowed to use the install command."
},
"twitchThemer.autoInstall": {
"title": "Auto-install Theme Install Requests",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default abstract class API {
});
if (res.status === 200) {
const { data } = res;
return data && data.length > 0 ? true : false;
return data && data.data && data.data.length > 0 ? true : false;
}
} catch (err: any) {
Logger.log(
Expand Down
18 changes: 11 additions & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { Theme } from "./types/theme";
*/
export enum AccessState {
/** All viewers */
viewer = 0,
Viewers,

/** Followers only */
follower = 1,
Followers,

/** Subscribers only */
subscriber = 2,
Subscribers,

/** VIPs only */
vip = 3,
VIPs,

/** Moderators only */
moderator = 4,
Moderators,

/** Broadcaster only */
broadcaster = 5,
Broadcaster,
}

/**
Expand Down Expand Up @@ -106,6 +106,7 @@ export const twitchScopes = [
`TWITCH_CLIENT_ID:${twitchAPIClientId}`,
"chat:read",
"chat:edit",
"moderator:read:followers"
];

export const messageHelp =
Expand Down Expand Up @@ -139,7 +140,7 @@ export const messageOnPaused = (
minute${minutes === 1 ? "" : "s"}.`;

export const messageInstalled = (user: string, labels: string[]) =>
`@${user}, the theme(s) '${labels.join(", ")}' were installed successfully.`;
`@${user}, the theme${labels.length > 1 ? "s" : ""} '${labels.join(", ")}' ${labels.length > 1 ? "were" : "was"} installed successfully.`;

export const messageThemeExists = (
user: string,
Expand All @@ -149,3 +150,6 @@ export const messageThemeExists = (
`@${user}, '${theme}' is already installed. To switch to it, send: !theme ${labels.join(
" -or- !theme ",
)}`;

export const messageInstallNotAuthorized = (user: string, installState: string) =>
`Sorry @${user}. Only ${installState} are allowed to install new themes.`;
23 changes: 11 additions & 12 deletions src/test/suite/themer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ suite("Themer Tests", function () {
fakeChatClient = new ChatClient();
fakeThemer = new Themer(fakeState);
fakeThemer.initializeConfiguration();
fakeThemer.handleAccessStateChanged(AccessState.viewer);
getConfigurationStub.resetHistory();
isTwitchUserFollowingStub.resetHistory();
isTwitchUserFollowingReturn = false;
Expand Down Expand Up @@ -524,7 +523,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = false;

fakeThemer.handleAccessStateChanged(AccessState.follower);
fakeThemer.handleAccessStateChanged(AccessState.Followers);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -546,7 +545,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.follower);
fakeThemer.handleAccessStateChanged(AccessState.Followers);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -568,7 +567,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = false;

fakeThemer.handleAccessStateChanged(AccessState.subscriber);
fakeThemer.handleAccessStateChanged(AccessState.Subscribers);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -589,7 +588,7 @@ suite("Themer Tests", function () {
extra: standardExtra,
};
isTwitchUserFollowingReturn = true;
fakeThemer.handleAccessStateChanged(AccessState.subscriber);
fakeThemer.handleAccessStateChanged(AccessState.Subscribers);

fakeThemer.handleCommands(chatMessage).then(() => {
try {
Expand All @@ -611,7 +610,7 @@ suite("Themer Tests", function () {
extra: standardExtra,
};

fakeThemer.handleAccessStateChanged(AccessState.subscriber);
fakeThemer.handleAccessStateChanged(AccessState.Subscribers);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -632,7 +631,7 @@ suite("Themer Tests", function () {
extra: standardExtra,
};

fakeThemer.handleAccessStateChanged(AccessState.vip);
fakeThemer.handleAccessStateChanged(AccessState.VIPs);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -654,7 +653,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.vip);
fakeThemer.handleAccessStateChanged(AccessState.VIPs);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -676,7 +675,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.moderator);
fakeThemer.handleAccessStateChanged(AccessState.Moderators);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -698,7 +697,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.moderator);
fakeThemer.handleAccessStateChanged(AccessState.Moderators);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -720,7 +719,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.broadcaster);
fakeThemer.handleAccessStateChanged(AccessState.Broadcaster);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand All @@ -742,7 +741,7 @@ suite("Themer Tests", function () {
};
isTwitchUserFollowingReturn = true;

fakeThemer.handleAccessStateChanged(AccessState.broadcaster);
fakeThemer.handleAccessStateChanged(AccessState.Broadcaster);
fakeThemer.handleCommands(chatMessage).then(() => {
try {
fakeWorkspaceConfiguration
Expand Down
Loading

0 comments on commit 0628028

Please sign in to comment.