Skip to content

Commit

Permalink
feat: Add command to log when permissions are denied
Browse files Browse the repository at this point in the history
  • Loading branch information
schw4rzlicht committed Jun 7, 2020
1 parent fd1a88f commit 40bdf94
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion __tests__/Twitch2Ma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ test("Command permissions denied", async () => {
await sendMessageToBotAndExpectAnswer(twitch2Ma, jest.spyOn(twitch2Ma["chatClient"], "say"), "#doesNotMatter",
"Alice", "!red", aliceRawMessage, "@Alice, please wait \\d{1,2} seconds and try again!");

return expect(permissionDeniedHandler).toBeCalledWith("#doesNotMatter", "Alice", "cooldown");
return expect(permissionDeniedHandler).toBeCalledWith("#doesNotMatter", "Alice", "!red", "cooldown");
});

test("Command permissions denied but godMode enabled", async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Twitch2Ma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class Twitch2Ma extends EventEmitter {
this.permissionController = new PermissionController()
.withPermissionInstance(new SACNPermission(config))
.withPermissionInstance(new CooldownPermission())
.withPermissionInstance(new OwnerPermission())
// .withPermissionInstance(new OwnerPermission())
.withPermissionInstance(new ModeratorPermission());
}

Expand Down Expand Up @@ -154,10 +154,10 @@ export default class Twitch2Ma extends EventEmitter {
})
.then(() => this.emit(this.onCommandExecuted, channel, user, chatCommand, parameterName, instructions.consoleCommand))
.catch((error: PermissionError) => {
let command = _.isString(parameterName) ? `!${chatCommand} ${parameterName}` : `${chatCommand}`;
let command = _.isString(parameterName) ? `!${chatCommand} ${parameterName}` : `!${chatCommand}`;
let reason = error.permissionCollector.permissionDeniedReasons.shift();
this.chatClient.say(channel, reason.viewerMessage.replace("{command}", command));
this.emit(this.onPermissionDenied, channel, user, reason.name);
this.emit(this.onPermissionDenied, channel, user, command, reason.name);
})
.catch(() => this.stopWithError(new TelnetError("Sending telnet command failed!")));
}
Expand Down Expand Up @@ -224,6 +224,6 @@ export default class Twitch2Ma extends EventEmitter {
onError = this.registerEvent<(error: Error) => any>();
onCommandExecuted = this.registerEvent<(channel: string, user: string, chatCommand: string, parameter: string, consoleCommand: string) => any>();
onHelpExecuted = this.registerEvent<(channel: string, user: string, helpCommand?: string) => any>();
onPermissionDenied = this.registerEvent<(channel: string, user: string, reason: string) => any>();
onPermissionDenied = this.registerEvent<(channel: string, user: string, command: string, reason: string) => any>();
onGodMode = this.registerEvent<(channel: string, user: string, reason: string) => any>();
}
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export async function attachEventHandlers(twitch2Ma: Twitch2Ma): Promise<Twitch2
twitch2Ma.onGodMode((channel, user, reason) => channelMessage(channel,
chalk`💪 User {bold ${user}} activated {bold.inverse god mode } because: ${reason}.`));

twitch2Ma.onPermissionDenied((channel, user, reason) => channelMessage(channel,
chalk`✋ User {bold ${user}} tried to run a command but permissions were denied because of ${reason}.`))
twitch2Ma.onPermissionDenied((channel, user, command, reason) => channelMessage(channel,
chalk`✋ User {bold ${user}} tried to run {bold.blue ${command}} but permissions were denied by ${reason}.`))

twitch2Ma.onError(exitWithError);

Expand Down

0 comments on commit 40bdf94

Please sign in to comment.