Skip to content

Commit

Permalink
feat(mods): only mods commands (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealenn authored Apr 3, 2021
1 parent a6012c3 commit 2bad5af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ LARBIN_TWITCH_CHANNEL: example
commands:
- name: '!facebook' # Command to write
random: true # Takes a random message from the list rather than following the order of the list
onlyMods: true # Only moderators can run this command
messages:
- 'My Facebook is https://facebook.com/example'
- name: '!twitter'
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Commands/RandomMessageCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ export class RandomMessageCommand implements ICommand {
public get Trigger(): string {
return this._trigger;
}
private _onlyMods: boolean;
public get OnlyMods(): boolean {
return this._onlyMods;
}
private _messages: Array<string>;

constructor(
trigger: string,
onlyMods: boolean,
messages: Array<string>)
{
this._trigger = trigger;
this._onlyMods = onlyMods;
this._messages = messages;
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/Commands/RoundRobinMessageCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ export class RoundRobinMessageCommand implements ICommand {
public get Trigger(): string {
return this._trigger;
}
private _onlyMods: boolean;
public get OnlyMods(): boolean {
return this._onlyMods;
}
private _messages: Array<string>;
private _messageIndex = 0;

constructor(
trigger: string,
onlyMods: boolean,
messages: Array<string>)
{
this._trigger = trigger;
this._onlyMods = onlyMods;
this._messages = messages;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/Commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ITwitchService } from '../../services/TwitchService';
*/
export interface ICommand {
Trigger: string;
OnlyMods: boolean;
Action(twitchService: ITwitchService, state: ChatUserstate): void;
}

Expand Down
4 changes: 3 additions & 1 deletion src/services/TwitchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class TwitchService implements ITwitchService {
this._client.on('message', (channels, userstate, message) => {
const command = this._commands.find((x) => x.Trigger == message);
if (command != undefined) {
command.Action(this, userstate);
if (!command.OnlyMods || (command.OnlyMods && userstate.mod == true)) {
command.Action(this, userstate);
}
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/services/YamlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ export class YamlService implements IYamlService {

yamlContent.commands.forEach(function (element: any) {
if (element.name && element.message) {
const onlyMods = element.onlyMods as boolean || false;
if (element.random) {
commands.push(new RandomMessageCommand(element.name, element.message));
commands.push(new RandomMessageCommand(element.name, onlyMods, element.message));
} else {
commands.push(new RoundRobinMessageCommand(element.name, element.message));
commands.push(new RoundRobinMessageCommand(element.name, onlyMods, element.message));
}
}
});
Expand Down

0 comments on commit 2bad5af

Please sign in to comment.