From 2bad5af9c5539eb902c02ddc6373163c3daf43b3 Mon Sep 17 00:00:00 2001 From: Marchandise Rudy Date: Sat, 3 Apr 2021 19:46:19 +0200 Subject: [PATCH] feat(mods): only mods commands (#11) --- README.md | 1 + src/lib/Commands/RandomMessageCommand.ts | 6 ++++++ src/lib/Commands/RoundRobinMessageCommand.ts | 6 ++++++ src/lib/Commands/index.ts | 1 + src/services/TwitchService.ts | 4 +++- src/services/YamlService.ts | 5 +++-- 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb0b06d..0c5bb0a 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/src/lib/Commands/RandomMessageCommand.ts b/src/lib/Commands/RandomMessageCommand.ts index d2fcd86..20019ae 100644 --- a/src/lib/Commands/RandomMessageCommand.ts +++ b/src/lib/Commands/RandomMessageCommand.ts @@ -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; constructor( trigger: string, + onlyMods: boolean, messages: Array) { this._trigger = trigger; + this._onlyMods = onlyMods; this._messages = messages; } diff --git a/src/lib/Commands/RoundRobinMessageCommand.ts b/src/lib/Commands/RoundRobinMessageCommand.ts index d34a4fd..a714d00 100644 --- a/src/lib/Commands/RoundRobinMessageCommand.ts +++ b/src/lib/Commands/RoundRobinMessageCommand.ts @@ -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; private _messageIndex = 0; constructor( trigger: string, + onlyMods: boolean, messages: Array) { this._trigger = trigger; + this._onlyMods = onlyMods; this._messages = messages; } diff --git a/src/lib/Commands/index.ts b/src/lib/Commands/index.ts index 99e06c8..a934391 100644 --- a/src/lib/Commands/index.ts +++ b/src/lib/Commands/index.ts @@ -6,6 +6,7 @@ import { ITwitchService } from '../../services/TwitchService'; */ export interface ICommand { Trigger: string; + OnlyMods: boolean; Action(twitchService: ITwitchService, state: ChatUserstate): void; } diff --git a/src/services/TwitchService.ts b/src/services/TwitchService.ts index 509fa1b..9330754 100644 --- a/src/services/TwitchService.ts +++ b/src/services/TwitchService.ts @@ -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); + } } }); } diff --git a/src/services/YamlService.ts b/src/services/YamlService.ts index 659f2d9..ee99e42 100644 --- a/src/services/YamlService.ts +++ b/src/services/YamlService.ts @@ -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)); } } });