From b4845013969be6164875aa04167f1377274c1b63 Mon Sep 17 00:00:00 2001 From: Andreas Aronsson Date: Sun, 21 Apr 2024 18:25:23 +0200 Subject: [PATCH] Delist runners again, switch runners to extend AbstractActionRunner, add build back into data classes with a dynamic import. --- .../Objects/Data/AbstractActionRunner.ts | 5 +++ .../Server/Objects/Data/ActionAudioRunner.ts | 7 +-- .../Server/Objects/Data/ActionChatRunner.ts | 7 +-- .../Server/Objects/Data/ActionCustomRunner.ts | 7 +-- .../Objects/Data/ActionDiscordRunner.ts | 7 +-- .../Server/Objects/Data/ActionInputRunner.ts | 7 +-- .../Server/Objects/Data/ActionLabelRunner.ts | 7 +-- .../Objects/Data/ActionMoveVRSpaceRunner.ts | 7 +-- .../Server/Objects/Data/ActionOBSRunner.ts | 7 +-- .../Data/ActionPhilipsHueBulbRunner.ts | 11 ++--- .../Data/ActionPhilipsHuePlugRunner.ts | 7 +-- .../Server/Objects/Data/ActionPipeRunner.ts | 7 +-- .../Objects/Data/ActionRemoteCommandRunner.ts | 7 +-- .../Objects/Data/ActionScreenshotRunner.ts | 7 +-- .../Objects/Data/ActionSettingTTSRunner.ts | 7 +-- .../Objects/Data/ActionSettingVRRunner.ts | 7 +-- .../Server/Objects/Data/ActionSignRunner.ts | 7 +-- .../Server/Objects/Data/ActionSpeechRunner.ts | 29 +++++++------ .../Server/Objects/Data/ActionSystemRunner.ts | 13 +++--- .../Server/Objects/Data/ActionURIRunner.ts | 7 +-- app/src/Shared/Bot/Actions.ts | 22 +++++----- .../Objects/Data/Action/AbstractAction.ts | 2 +- .../Shared/Objects/Data/Action/ActionAudio.ts | 8 +++- .../Shared/Objects/Data/Action/ActionChat.ts | 9 +++- .../Objects/Data/Action/ActionCustom.ts | 8 +++- .../Objects/Data/Action/ActionDiscord.ts | 8 +++- .../Shared/Objects/Data/Action/ActionInput.ts | 8 +++- .../Shared/Objects/Data/Action/ActionLabel.ts | 8 +++- .../Objects/Data/Action/ActionMoveVRSpace.ts | 8 +++- .../Shared/Objects/Data/Action/ActionOBS.ts | 8 +++- .../Data/Action/ActionPhilipsHueBulb.ts | 8 +++- .../Data/Action/ActionPhilipsHuePlug.ts | 8 +++- .../Shared/Objects/Data/Action/ActionPipe.ts | 8 +++- .../Data/Action/ActionRemoteCommand.ts | 8 +++- .../Objects/Data/Action/ActionScreenshot.ts | 8 +++- .../Objects/Data/Action/ActionSettingTTS.ts | 8 +++- .../Objects/Data/Action/ActionSettingVR.ts | 8 +++- .../Shared/Objects/Data/Action/ActionSign.ts | 8 +++- .../Objects/Data/Action/ActionSpeech.ts | 8 +++- .../Objects/Data/Action/ActionSystem.ts | 8 +++- .../Shared/Objects/Data/Action/ActionURI.ts | 8 +++- app/src/Shared/Objects/Data/EnlistData.ts | 43 ------------------- .../Objects/Data/Trigger/TriggerReward.ts | 1 + 43 files changed, 245 insertions(+), 146 deletions(-) create mode 100644 app/src/Server/Objects/Data/AbstractActionRunner.ts diff --git a/app/src/Server/Objects/Data/AbstractActionRunner.ts b/app/src/Server/Objects/Data/AbstractActionRunner.ts new file mode 100644 index 0000000..4f4c508 --- /dev/null +++ b/app/src/Server/Objects/Data/AbstractActionRunner.ts @@ -0,0 +1,5 @@ +import AbstractAction, {IActionCallback} from '../../../Shared/Objects/Data/Action/AbstractAction.js' + +export default abstract class AbstractActionRunner { + abstract getCallback(key: string, instance: T&AbstractAction): IActionCallback +} \ No newline at end of file diff --git a/app/src/Server/Objects/Data/ActionAudioRunner.ts b/app/src/Server/Objects/Data/ActionAudioRunner.ts index 4ca9e8a..a590b09 100644 --- a/app/src/Server/Objects/Data/ActionAudioRunner.ts +++ b/app/src/Server/Objects/Data/ActionAudioRunner.ts @@ -4,15 +4,16 @@ import AssetsHelper from '../../../Shared/Helpers/AssetsHelper.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' +import AbstractActionRunner from './AbstractActionRunner.js' import ActionAudio from '../../../Shared/Objects/Data/Action/ActionAudio.js' -export default class ActionAudioRunner extends ActionAudio { - build(key: string): IActionCallback { +export default class ActionAudioRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a sound and/or speech action', awaitCall: true, call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionAudio) clone.srcEntries = await AssetsHelper.preparePathsForUse(clone.srcEntries) clone.srcEntries = await TextHelper.replaceTagsInTextArray( // To support audio URLs in input ArrayUtils.getAsType(Utils.ensureArray(clone.srcEntries), clone.srcEntries_use, index), // Need to read entries from config here as cloning drops __type diff --git a/app/src/Server/Objects/Data/ActionChatRunner.ts b/app/src/Server/Objects/Data/ActionChatRunner.ts index 43d097d..2a44351 100644 --- a/app/src/Server/Objects/Data/ActionChatRunner.ts +++ b/app/src/Server/Objects/Data/ActionChatRunner.ts @@ -7,13 +7,14 @@ import DataBaseHelper from '../../../Shared/Helpers/DataBaseHelper.js' import {SettingTwitchTokens} from '../../../Shared/Objects/Data/Setting/SettingTwitch.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' import ActionChat from '../../../Shared/Objects/Data/Action/ActionChat.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionChatRunner extends ActionChat { - build(key: string): IActionCallback { +export default class ActionChatRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Twitch chat message action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionChat) const modules = ModulesSingleton.getInstance() const entries = ArrayUtils.getAsType(Utils.ensureArray(clone.entries), clone.entries_use, index) for(const entry of entries) { diff --git a/app/src/Server/Objects/Data/ActionCustomRunner.ts b/app/src/Server/Objects/Data/ActionCustomRunner.ts index bf2081b..c8275ac 100644 --- a/app/src/Server/Objects/Data/ActionCustomRunner.ts +++ b/app/src/Server/Objects/Data/ActionCustomRunner.ts @@ -2,14 +2,15 @@ import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/ import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' import ActionCustom from '../../../Shared/Objects/Data/Action/ActionCustom.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionCustomRunner extends ActionCustom { - build(key: string): IActionCallback { +export default class ActionCustomRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers arbitrary code', call: async (user: IActionUser, nonce: string, index?: number) => { try { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionCustom) const modules = ModulesSingleton.getInstance() eval(clone.code) } catch (error) { diff --git a/app/src/Server/Objects/Data/ActionDiscordRunner.ts b/app/src/Server/Objects/Data/ActionDiscordRunner.ts index 13a9599..1da7ba6 100644 --- a/app/src/Server/Objects/Data/ActionDiscordRunner.ts +++ b/app/src/Server/Objects/Data/ActionDiscordRunner.ts @@ -7,13 +7,14 @@ import DiscordUtils from '../../../Shared/Utils/DiscordUtils.js' import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' import ActionDiscord from '../../../Shared/Objects/Data/Action/ActionDiscord.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionDiscordRunner extends ActionDiscord { - build(key: string): IActionCallback { +export default class ActionDiscordRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a DiscordUtils message action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionDiscord) const modules = ModulesSingleton.getInstance() const userData = await TwitchHelixHelper.getUserById(user.id) const entries = ArrayUtils.getAsType(clone.entries, clone.entries_use, index) diff --git a/app/src/Server/Objects/Data/ActionInputRunner.ts b/app/src/Server/Objects/Data/ActionInputRunner.ts index 63ff881..9ecc2ef 100644 --- a/app/src/Server/Objects/Data/ActionInputRunner.ts +++ b/app/src/Server/Objects/Data/ActionInputRunner.ts @@ -3,13 +3,14 @@ import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/ import Utils from '../../../Shared/Utils/Utils.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import ExecUtils from '../../../Shared/Utils/ExecUtils.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionInputRunner extends ActionInput { - build(key: string): IActionCallback { +export default class ActionInputRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers an input action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionInput) clone.commands = ArrayUtils.getAsType(clone.commands, clone.commands_use, index) ExecUtils.runCommandsFromAction(clone) } diff --git a/app/src/Server/Objects/Data/ActionLabelRunner.ts b/app/src/Server/Objects/Data/ActionLabelRunner.ts index 1f8ee43..7e91591 100644 --- a/app/src/Server/Objects/Data/ActionLabelRunner.ts +++ b/app/src/Server/Objects/Data/ActionLabelRunner.ts @@ -4,13 +4,14 @@ import Utils from '../../../Shared/Utils/Utils.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import DataFileUtils from '../../../Shared/Utils/DataFileUtils.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionLabelRunner extends ActionLabel { - build(key: string): IActionCallback { +export default class ActionLabelRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Label action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionLabel) for(const text of ArrayUtils.getAsType(clone.textEntries, clone.textEntries_use)) { if(clone.append) { await DataFileUtils.appendText(clone.fileName, await TextHelper.replaceTagsInText(text, user)) diff --git a/app/src/Server/Objects/Data/ActionMoveVRSpaceRunner.ts b/app/src/Server/Objects/Data/ActionMoveVRSpaceRunner.ts index 1830bc7..c27d84e 100644 --- a/app/src/Server/Objects/Data/ActionMoveVRSpaceRunner.ts +++ b/app/src/Server/Objects/Data/ActionMoveVRSpaceRunner.ts @@ -2,13 +2,14 @@ import ActionMoveVRSpace from '../../../Shared/Objects/Data/Action/ActionMoveVRS import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/AbstractAction.js' import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionMoveVRSpaceRunner extends ActionMoveVRSpace { - build(key: string): IActionCallback { +export default class ActionMoveVRSpaceRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers an OpenVR2WSMoveSpace action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionMoveVRSpace) const modules = ModulesSingleton.getInstance() modules.openvr2ws.moveSpace(clone) } diff --git a/app/src/Server/Objects/Data/ActionOBSRunner.ts b/app/src/Server/Objects/Data/ActionOBSRunner.ts index 0049ec9..98ca99a 100644 --- a/app/src/Server/Objects/Data/ActionOBSRunner.ts +++ b/app/src/Server/Objects/Data/ActionOBSRunner.ts @@ -2,13 +2,14 @@ import ActionOBS from '../../../Shared/Objects/Data/Action/ActionOBS.js' import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/AbstractAction.js' import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionOBSRunner extends ActionOBS { - build(key: string): IActionCallback { +export default class ActionOBSRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers an OBS action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) as ActionOBS + const clone = Utils.clone(instance as ActionOBS) const modules = ModulesSingleton.getInstance() // clone.key = key TODO: Is this needed for the group toggling? const state = clone.state diff --git a/app/src/Server/Objects/Data/ActionPhilipsHueBulbRunner.ts b/app/src/Server/Objects/Data/ActionPhilipsHueBulbRunner.ts index e6b7e47..da42fb8 100644 --- a/app/src/Server/Objects/Data/ActionPhilipsHueBulbRunner.ts +++ b/app/src/Server/Objects/Data/ActionPhilipsHueBulbRunner.ts @@ -4,23 +4,24 @@ import Utils from '../../../Shared/Utils/Utils.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import PhilipsHueHelper from '../../../Shared/Helpers/PhilipsHueHelper.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionPhilipsHueBulbRunner extends ActionPhilipsHueBulb { - build(key: string): IActionCallback { +export default class ActionPhilipsHueBulbRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Philips Hue bulb action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionPhilipsHueBulb) const ids = ArrayUtils.getAsType(DataUtils.ensureKeyArray(clone.entries) ?? [], clone.entries_use, index) let colors = ArrayUtils.getAsType(DataUtils.ensureDataArray(clone.colorEntries) ?? [], clone.colorEntries_use, index) if(colors.length > 0 && ids.length > 0) { - if(this.colorEntries_delay <= 0) colors = [colors[0]] // No reason to set more than one color if there is no delay as that would be at the same time. + if(clone.colorEntries_delay <= 0) colors = [colors[0]] // No reason to set more than one color if there is no delay as that would be at the same time. let delay = 0 for(const color of colors) { setTimeout(() => { PhilipsHueHelper.runBulbs(ids, color.brightness, color.hue, color.saturation) }, delay) - delay += (this.colorEntries_delay*1000) + delay += (clone.colorEntries_delay*1000) } } } diff --git a/app/src/Server/Objects/Data/ActionPhilipsHuePlugRunner.ts b/app/src/Server/Objects/Data/ActionPhilipsHuePlugRunner.ts index 45840a2..90c6d0a 100644 --- a/app/src/Server/Objects/Data/ActionPhilipsHuePlugRunner.ts +++ b/app/src/Server/Objects/Data/ActionPhilipsHuePlugRunner.ts @@ -4,13 +4,14 @@ import Utils from '../../../Shared/Utils/Utils.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import PhilipsHueHelper from '../../../Shared/Helpers/PhilipsHueHelper.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionPhilipsHuePlugRunner extends ActionPhilipsHuePlug { - build(key: string): IActionCallback { +export default class ActionPhilipsHuePlugRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Philips Hue plug action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionPhilipsHuePlug) const ids = ArrayUtils.getAsType(DataUtils.ensureKeyArray(clone.entries) ?? [], clone.entries_use, index) PhilipsHueHelper.runPlugs(ids, clone.triggerState, clone.originalState, clone.duration) } diff --git a/app/src/Server/Objects/Data/ActionPipeRunner.ts b/app/src/Server/Objects/Data/ActionPipeRunner.ts index d2f18d0..f4ac77f 100644 --- a/app/src/Server/Objects/Data/ActionPipeRunner.ts +++ b/app/src/Server/Objects/Data/ActionPipeRunner.ts @@ -6,13 +6,14 @@ import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import AssetsHelper from '../../../Shared/Helpers/AssetsHelper.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionPipeRunner extends ActionPipe { - build(key: string): IActionCallback { +export default class ActionPipeRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers an OpenVRNotificationPipe action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionPipe) const modules = ModulesSingleton.getInstance() const customPreset = DataUtils.ensureData(clone.customPreset) const basicPreset = DataUtils.ensureData(clone.basicPreset) diff --git a/app/src/Server/Objects/Data/ActionRemoteCommandRunner.ts b/app/src/Server/Objects/Data/ActionRemoteCommandRunner.ts index b711781..261db31 100644 --- a/app/src/Server/Objects/Data/ActionRemoteCommandRunner.ts +++ b/app/src/Server/Objects/Data/ActionRemoteCommandRunner.ts @@ -3,13 +3,14 @@ import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/ import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionRemoteCommandRunner extends ActionRemoteCommand { - build(key: string): IActionCallback { +export default class ActionRemoteCommandRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Remote Command action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionRemoteCommand) const modules = ModulesSingleton.getInstance() const entries = ArrayUtils.getAsType(clone.entries, clone.entries_use, index) for(const entry of entries) { diff --git a/app/src/Server/Objects/Data/ActionScreenshotRunner.ts b/app/src/Server/Objects/Data/ActionScreenshotRunner.ts index a453722..339302d 100644 --- a/app/src/Server/Objects/Data/ActionScreenshotRunner.ts +++ b/app/src/Server/Objects/Data/ActionScreenshotRunner.ts @@ -7,13 +7,14 @@ import DataBaseHelper from '../../../Shared/Helpers/DataBaseHelper.js' import ConfigScreenshots from '../../../Shared/Objects/Data/Config/ConfigScreenshots.js' import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import {OptionScreenshotType} from '../../../Shared/Objects/Options/OptionScreenshotType.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionScreenshotRunner extends ActionScreenshot { - build(key: string): IActionCallback { +export default class ActionScreenshotRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Screenshot action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionScreenshot) const states = StatesSingleton.getInstance() const modules = ModulesSingleton.getInstance() const userInput = user.input diff --git a/app/src/Server/Objects/Data/ActionSettingTTSRunner.ts b/app/src/Server/Objects/Data/ActionSettingTTSRunner.ts index 49236c8..cf23309 100644 --- a/app/src/Server/Objects/Data/ActionSettingTTSRunner.ts +++ b/app/src/Server/Objects/Data/ActionSettingTTSRunner.ts @@ -12,14 +12,15 @@ import Color from '../../../Shared/Constants/ColorConstants.js' import SettingDictionaryEntry from '../../../Shared/Objects/Data/Setting/SettingDictionary.js' import DataUtils from '../../../Shared/Objects/Data/DataUtils.js' import SettingUser, {SettingUserMute, SettingUserName} from '../../../Shared/Objects/Data/Setting/SettingUser.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionSettingTTSRunner extends ActionSettingTTS { - build(key: string): IActionCallback { +export default class ActionSettingTTSRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { awaitCall: true, description: 'Callback that executes a TTS function', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionSettingTTS) const modules = ModulesSingleton.getInstance() const states = StatesSingleton.getInstance() const input = await TextHelper.replaceTagsInText(clone.inputOverride ?? user.input, user) diff --git a/app/src/Server/Objects/Data/ActionSettingVRRunner.ts b/app/src/Server/Objects/Data/ActionSettingVRRunner.ts index bb43909..6feb8e0 100644 --- a/app/src/Server/Objects/Data/ActionSettingVRRunner.ts +++ b/app/src/Server/Objects/Data/ActionSettingVRRunner.ts @@ -2,13 +2,14 @@ import ActionSettingVR from '../../../Shared/Objects/Data/Action/ActionSettingVR import {IActionCallback, IActionUser} from '../../../Shared/Objects/Data/Action/AbstractAction.js' import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionSettingVRRunner extends ActionSettingVR { - build(key: string): IActionCallback { +export default class ActionSettingVRRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers an OpenVR2WSSetting action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionSettingVR) const modules = ModulesSingleton.getInstance() modules.openvr2ws.setSetting(clone) } diff --git a/app/src/Server/Objects/Data/ActionSignRunner.ts b/app/src/Server/Objects/Data/ActionSignRunner.ts index e83b6e0..86f62a9 100644 --- a/app/src/Server/Objects/Data/ActionSignRunner.ts +++ b/app/src/Server/Objects/Data/ActionSignRunner.ts @@ -4,13 +4,14 @@ import Utils from '../../../Shared/Utils/Utils.js' import ModulesSingleton from '../../../Shared/Singletons/ModulesSingleton.js' import TwitchHelixHelper from '../../../Shared/Helpers/TwitchHelixHelper.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionSignRunner extends ActionSign { - build(key: string): IActionCallback { +export default class ActionSignRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a Sign action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionSign) const modules = ModulesSingleton.getInstance() TwitchHelixHelper.getUserById(user.id).then(async userData => { const modules = ModulesSingleton.getInstance() diff --git a/app/src/Server/Objects/Data/ActionSpeechRunner.ts b/app/src/Server/Objects/Data/ActionSpeechRunner.ts index afe7df7..32d4062 100644 --- a/app/src/Server/Objects/Data/ActionSpeechRunner.ts +++ b/app/src/Server/Objects/Data/ActionSpeechRunner.ts @@ -7,44 +7,47 @@ import {SettingTwitchTokens} from '../../../Shared/Objects/Data/Setting/SettingT import TextHelper from '../../../Shared/Helpers/TextHelper.js' import TwitchHelixHelper from '../../../Shared/Helpers/TwitchHelixHelper.js' import ActionSpeech from '../../../Shared/Objects/Data/Action/ActionSpeech.js' +import AbstractActionRunner from './AbstractActionRunner.js' +import Utils from '../../../Shared/Utils/Utils.js' -export default class ActionSpeechRunner extends ActionSpeech { - build(key: string): IActionCallback { +export default class ActionSpeechRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers something spoken with TTS.', call: async (user: IActionUser, nonce: string, index?: number) => { - console.log('tts debug, entry preset', this.entryPreset) + const clone = Utils.clone(instance as ActionSpeech) + console.log('tts debug, entry preset', clone.entryPreset) const modules = ModulesSingleton.getInstance() let entries: string[] = [] - if(this.entryPreset) { - const entryPreset = DataUtils.ensureData(this.entryPreset) + if(clone.entryPreset) { + const entryPreset = DataUtils.ensureData(clone.entryPreset) entries = entryPreset && entryPreset.collection.length > 0 - ? ArrayUtils.getAsType(entryPreset.collection, this.entryPreset_use, index) - : ArrayUtils.getAsType(this.entries, this.entries_use, index) // Should be redundant, only used if someone forgot to remove an empty preset + ? ArrayUtils.getAsType(entryPreset.collection, clone.entryPreset_use, index) + : ArrayUtils.getAsType(clone.entries, clone.entries_use, index) // Should be redundant, only used if someone forgot to remove an empty preset } else { - entries = ArrayUtils.getAsType(this.entries, this.entries_use, index) + entries = ArrayUtils.getAsType(clone.entries, clone.entries_use, index) } const chatbotTokens = await DataBaseHelper.load(new SettingTwitchTokens(), 'Chatbot') - const userName = await TextHelper.replaceTagsInText(this.voiceOfUser_orUsername, user) - const voiceOfUserTwitchId = parseInt(DataUtils.ensureKey(this.voiceOfUser)) + const userName = await TextHelper.replaceTagsInText(clone.voiceOfUser_orUsername, user) + const voiceOfUserTwitchId = parseInt(DataUtils.ensureKey(clone.voiceOfUser)) const voiceOfNameTwitchId = parseInt((await TwitchHelixHelper.getUserByLogin(userName))?.id ?? '') const voiceUserId = !isNaN(voiceOfUserTwitchId) ? voiceOfUserTwitchId : !isNaN(voiceOfNameTwitchId) ? voiceOfNameTwitchId : chatbotTokens?.userId ?? 0 - console.log('Voice of user', [this.voiceOfUser, DataUtils.ensureKey(this.voiceOfUser), this.voiceOfUser_orUsername, userName, voiceUserId]) + console.log('Voice of user', [clone.voiceOfUser, DataUtils.ensureKey(clone.voiceOfUser), clone.voiceOfUser_orUsername, userName, voiceUserId]) for(const ttsStr of entries) { await modules.tts.enqueueSpeakSentence( await TextHelper.replaceTagsInText(ttsStr, user), voiceUserId, - this.type, + clone.type, nonce, // Used for screenshots but could be used for other things too. undefined, undefined, - this.skipDictionary + clone.skipDictionary ) } } diff --git a/app/src/Server/Objects/Data/ActionSystemRunner.ts b/app/src/Server/Objects/Data/ActionSystemRunner.ts index 4dc6a6b..0998e30 100644 --- a/app/src/Server/Objects/Data/ActionSystemRunner.ts +++ b/app/src/Server/Objects/Data/ActionSystemRunner.ts @@ -12,13 +12,14 @@ import EventDefault from '../../../Shared/Objects/Data/Event/EventDefault.js' import TriggerReward from '../../../Shared/Objects/Data/Trigger/TriggerReward.js' import TwitchHelixHelper from '../../../Shared/Helpers/TwitchHelixHelper.js' import ActionSystem, {ActionSystemRewardState} from '../../../Shared/Objects/Data/Action/ActionSystem.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionSystemRunner extends ActionSystem { - build(key: string): IActionCallback { +export default class ActionSystemRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers or toggles events', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionSystem) const modules = ModulesSingleton.getInstance() const interval = clone.trigger.interval let delay = 0 @@ -62,10 +63,10 @@ export default class ActionSystemRunner extends ActionSystem { } // Trigger Events on User Input - const matchEntries = DataUtils.ensureItemDictionary(this.trigger.matchedEventEntries)?.dataDictionary ?? {} + const matchEntries = DataUtils.ensureItemDictionary(clone.trigger.matchedEventEntries)?.dataDictionary ?? {} const matchTheseKeys = Object.keys(matchEntries) - const matchCaseSensitive = this.trigger.matchedEventEntries_caseSensitive - const matchRegex = this.trigger.matchedEventEntries_isRegex + const matchCaseSensitive = clone.trigger.matchedEventEntries_caseSensitive + const matchRegex = clone.trigger.matchedEventEntries_isRegex const matchThisInput = (matchCaseSensitive ? user.input : user.input.toLowerCase()).trim() const matchDefaultEventKey = matchEntries['*']?.key diff --git a/app/src/Server/Objects/Data/ActionURIRunner.ts b/app/src/Server/Objects/Data/ActionURIRunner.ts index 21071bd..c55db88 100644 --- a/app/src/Server/Objects/Data/ActionURIRunner.ts +++ b/app/src/Server/Objects/Data/ActionURIRunner.ts @@ -4,13 +4,14 @@ import Utils from '../../../Shared/Utils/Utils.js' import ArrayUtils from '../../../Shared/Utils/ArrayUtils.js' import TextHelper from '../../../Shared/Helpers/TextHelper.js' import ExecUtils from '../../../Shared/Utils/ExecUtils.js' +import AbstractActionRunner from './AbstractActionRunner.js' -export default class ActionURIRunner extends ActionURI { - build(key: string): IActionCallback { +export default class ActionURIRunner extends AbstractActionRunner { + getCallback(key: string, instance: T): IActionCallback { return { description: 'Callback that triggers a URI action', call: async (user: IActionUser, nonce: string, index?: number) => { - const clone = Utils.clone(this) + const clone = Utils.clone(instance as ActionURI) const uris = ArrayUtils.getAsType(clone.entries, clone.entries_use, index) let totalDelay = 0 for(const uri of uris) { diff --git a/app/src/Shared/Bot/Actions.ts b/app/src/Shared/Bot/Actions.ts index c980f67..ff53199 100644 --- a/app/src/Shared/Bot/Actions.ts +++ b/app/src/Shared/Bot/Actions.ts @@ -71,7 +71,7 @@ export class ActionHandler { */ switch(event.behavior) { case OptionEventBehavior.Random: { - actionsMainCallback = Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneRandom, eventOptions.specificIndex)) + actionsMainCallback = await Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneRandom, eventOptions.specificIndex)) break } /** @@ -115,7 +115,7 @@ export class ActionHandler { index = options.loop ? (counter.count - 1) % (options.maxValue > 0 ? options.maxValue : eventActionContainers.length) // Loop : Math.min(counter.count - 1, eventActionContainers.length-1) // Clamp to max - actionsMainCallback = Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index)) + actionsMainCallback = await Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index)) break } /** @@ -184,7 +184,7 @@ export class ActionHandler { index = Math.max(0, eventActionContainers.length - 2) // Second to last, fallback to first } } - actionsMainCallback = Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index)) + actionsMainCallback = await Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index)) break } /** @@ -214,11 +214,11 @@ export class ActionHandler { // Run reset actions if enabled. if(event.multiTierOptions.resetOnTimeout) { // Will use this specific index to run the hard reset actions. - index = 1 - Actions.buildActionsMainCallback( + index = 1; + (await Actions.buildActionsMainCallback( this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index) - ) (user, index) + )) (user, index) } // Reset counter @@ -295,11 +295,11 @@ export class ActionHandler { actions.push(...ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, 0)) } actions.push(...ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.OneSpecific, index)) - actionsMainCallback = Actions.buildActionsMainCallback(this.key, actions) + actionsMainCallback = await Actions.buildActionsMainCallback(this.key, actions) break } default: {// Basically "All", no special behavior, only generate the callback if it is missing, but uses the entries by type. - actionsMainCallback = Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.All, eventOptions.specificIndex)) + actionsMainCallback = await Actions.buildActionsMainCallback(this.key, ArrayUtils.getAsType(eventActionContainers, OptionEntryUsage.All, eventOptions.specificIndex)) break } } @@ -431,13 +431,13 @@ export class Actions { * @param use OptionEntryUsage * @param index */ - public static buildActionsMainCallback(key: string, actionContainerList: (EventActionContainer|undefined)[], use: number=OptionEntryUsage.All, index: number=0): IActionsMainCallback { + public static async buildActionsMainCallback(key: string, actionContainerList: (EventActionContainer|undefined)[], use: number=OptionEntryUsage.All, index: number=0): Promise { /** * Handle all the different types of action constructs here. * 1. Single setup * 2. Multiple setup * - * The multiple setups can be set to be all, random, incremental, accumulating or multitier. + * The multiple setups can be set to be all, random, incremental, accumulating or multi-tier. * In the future, possible other alternatives, like leveling up/community challenge. * * There will be a settings for the first one in an array to be the default. @@ -453,7 +453,7 @@ export class Actions { const actions = DataUtils.ensureDataArray(actionContainer.entries) for(const action of actions) { // Build callbacks - const callback: IActionCallback = (action as AbstractAction).build(key) + const callback: IActionCallback = await (action as AbstractAction).build(key) actionCallbacks.push(callback) } // Logging diff --git a/app/src/Shared/Objects/Data/Action/AbstractAction.ts b/app/src/Shared/Objects/Data/Action/AbstractAction.ts index 6a2a1e1..47b8413 100644 --- a/app/src/Shared/Objects/Data/Action/AbstractAction.ts +++ b/app/src/Shared/Objects/Data/Action/AbstractAction.ts @@ -8,7 +8,7 @@ export default abstract class AbstractAction extends AbstractData { * This builds a callback that takes in user data to execute the action. * @param key */ - build(key: string): IActionCallback { + async build(key: string): Promise { console.warn(`Build not implemented for Action: ${key}`) return { description: 'Abstract action callback', diff --git a/app/src/Shared/Objects/Data/Action/ActionAudio.ts b/app/src/Shared/Objects/Data/Action/ActionAudio.ts index f6df505..2e42f81 100644 --- a/app/src/Shared/Objects/Data/Action/ActionAudio.ts +++ b/app/src/Shared/Objects/Data/Action/ActionAudio.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' import DataUtils from '../DataUtils.js' @@ -31,5 +31,11 @@ export default class ActionAudio extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionAudioRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/Action/ActionChat.ts b/app/src/Shared/Objects/Data/Action/ActionChat.ts index 8c40874..d603dec 100644 --- a/app/src/Shared/Objects/Data/Action/ActionChat.ts +++ b/app/src/Shared/Objects/Data/Action/ActionChat.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -7,6 +7,7 @@ export default class ActionChat extends AbstractAction { entries_use = OptionEntryUsage.First onlySendNonRepeats = false onlySendAfterUserMessage = false + enlist() { DataMap.addRootInstance({ instance: new ActionChat(), @@ -23,4 +24,10 @@ export default class ActionChat extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionChatRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionCustom.ts b/app/src/Shared/Objects/Data/Action/ActionCustom.ts index a44e535..3ad8bb5 100644 --- a/app/src/Shared/Objects/Data/Action/ActionCustom.ts +++ b/app/src/Shared/Objects/Data/Action/ActionCustom.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import DataMap from '../DataMap.js' export default class ActionCustom extends AbstractAction { @@ -17,4 +17,10 @@ export default class ActionCustom extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionCustomRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionDiscord.ts b/app/src/Shared/Objects/Data/Action/ActionDiscord.ts index a47ddfa..bc6fdd8 100644 --- a/app/src/Shared/Objects/Data/Action/ActionDiscord.ts +++ b/app/src/Shared/Objects/Data/Action/ActionDiscord.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {DataEntries} from '../AbstractData.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -21,4 +21,10 @@ export default class ActionDiscord extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionDiscordRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/Action/ActionInput.ts b/app/src/Shared/Objects/Data/Action/ActionInput.ts index b91a65c..fdb42ce 100644 --- a/app/src/Shared/Objects/Data/Action/ActionInput.ts +++ b/app/src/Shared/Objects/Data/Action/ActionInput.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionCommandType} from '../../Options/OptionCommandType.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -31,6 +31,12 @@ export default class ActionInput extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionInputRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } export class ActionInputCommand extends AbstractData { diff --git a/app/src/Shared/Objects/Data/Action/ActionLabel.ts b/app/src/Shared/Objects/Data/Action/ActionLabel.ts index ebcfb5f..df32d92 100644 --- a/app/src/Shared/Objects/Data/Action/ActionLabel.ts +++ b/app/src/Shared/Objects/Data/Action/ActionLabel.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -24,5 +24,11 @@ export default class ActionLabel extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionLabelRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/Action/ActionMoveVRSpace.ts b/app/src/Shared/Objects/Data/Action/ActionMoveVRSpace.ts index 41531ed..acadf57 100644 --- a/app/src/Shared/Objects/Data/Action/ActionMoveVRSpace.ts +++ b/app/src/Shared/Objects/Data/Action/ActionMoveVRSpace.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import DataMap from '../DataMap.js' export default class ActionMoveVRSpace extends AbstractAction { @@ -22,4 +22,10 @@ export default class ActionMoveVRSpace extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionMoveVRSpaceRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/Action/ActionOBS.ts b/app/src/Shared/Objects/Data/Action/ActionOBS.ts index a7f6bca..8b3b38a 100644 --- a/app/src/Shared/Objects/Data/Action/ActionOBS.ts +++ b/app/src/Shared/Objects/Data/Action/ActionOBS.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import AbstractData, {DataEntries} from '../AbstractData.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -36,6 +36,12 @@ export default class ActionOBS extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionOBSRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } export class ActionOBSSource extends AbstractData { scenePreset: number|DataEntries = 0 diff --git a/app/src/Shared/Objects/Data/Action/ActionPhilipsHueBulb.ts b/app/src/Shared/Objects/Data/Action/ActionPhilipsHueBulb.ts index 88cf2ed..ce1d2fb 100644 --- a/app/src/Shared/Objects/Data/Action/ActionPhilipsHueBulb.ts +++ b/app/src/Shared/Objects/Data/Action/ActionPhilipsHueBulb.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {DataEntries} from '../AbstractData.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -28,5 +28,11 @@ export default class ActionPhilipsHueBulb extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionPhilipsHueBulbRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/Action/ActionPhilipsHuePlug.ts b/app/src/Shared/Objects/Data/Action/ActionPhilipsHuePlug.ts index 66c332a..9d3b798 100644 --- a/app/src/Shared/Objects/Data/Action/ActionPhilipsHuePlug.ts +++ b/app/src/Shared/Objects/Data/Action/ActionPhilipsHuePlug.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {DataEntries} from '../AbstractData.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -28,4 +28,10 @@ export default class ActionPhilipsHuePlug extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionPhilipsHuePlugRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionPipe.ts b/app/src/Shared/Objects/Data/Action/ActionPipe.ts index ea3300e..143b696 100644 --- a/app/src/Shared/Objects/Data/Action/ActionPipe.ts +++ b/app/src/Shared/Objects/Data/Action/ActionPipe.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import {DataEntries} from '../AbstractData.js' import DataMap from '../DataMap.js' @@ -40,4 +40,10 @@ export default class ActionPipe extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionPipeRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionRemoteCommand.ts b/app/src/Shared/Objects/Data/Action/ActionRemoteCommand.ts index b94446d..650d9af 100644 --- a/app/src/Shared/Objects/Data/Action/ActionRemoteCommand.ts +++ b/app/src/Shared/Objects/Data/Action/ActionRemoteCommand.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -17,4 +17,10 @@ export default class ActionRemoteCommand extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionRemoteCommandRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionScreenshot.ts b/app/src/Shared/Objects/Data/Action/ActionScreenshot.ts index 1c9d413..cc716db 100644 --- a/app/src/Shared/Objects/Data/Action/ActionScreenshot.ts +++ b/app/src/Shared/Objects/Data/Action/ActionScreenshot.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionScreenshotType} from '../../Options/OptionScreenshotType.js' import {DataEntries} from '../AbstractData.js' import DataMap from '../DataMap.js' @@ -25,6 +25,12 @@ export default class ActionScreenshot extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionScreenshotRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } /** diff --git a/app/src/Shared/Objects/Data/Action/ActionSettingTTS.ts b/app/src/Shared/Objects/Data/Action/ActionSettingTTS.ts index 7bb3b26..558a65c 100644 --- a/app/src/Shared/Objects/Data/Action/ActionSettingTTS.ts +++ b/app/src/Shared/Objects/Data/Action/ActionSettingTTS.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionTTSFunctionType} from '../../Options/OptionTTS.js' import DataMap from '../DataMap.js' @@ -20,4 +20,10 @@ export default class ActionSettingTTS extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionSettingTTSRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionSettingVR.ts b/app/src/Shared/Objects/Data/Action/ActionSettingVR.ts index a4fbfee..02eefc2 100644 --- a/app/src/Shared/Objects/Data/Action/ActionSettingVR.ts +++ b/app/src/Shared/Objects/Data/Action/ActionSettingVR.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionSteamVRSettingType} from '../../Options/OptionSteamVRSetting.js' import DataMap from '../DataMap.js' @@ -28,4 +28,10 @@ export default class ActionSettingVR extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionSettingVRRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionSign.ts b/app/src/Shared/Objects/Data/Action/ActionSign.ts index 65b4123..33e3676 100644 --- a/app/src/Shared/Objects/Data/Action/ActionSign.ts +++ b/app/src/Shared/Objects/Data/Action/ActionSign.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import DataMap from '../DataMap.js' import DataUtils from '../DataUtils.js' @@ -24,4 +24,10 @@ export default class ActionSign extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionSignRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionSpeech.ts b/app/src/Shared/Objects/Data/Action/ActionSpeech.ts index a42c702..9e5cfa4 100644 --- a/app/src/Shared/Objects/Data/Action/ActionSpeech.ts +++ b/app/src/Shared/Objects/Data/Action/ActionSpeech.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import {DataEntries} from '../AbstractData.js' import {OptionTTSType} from '../../Options/OptionTTS.js' @@ -37,4 +37,10 @@ export default class ActionSpeech extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionSpeechRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } \ No newline at end of file diff --git a/app/src/Shared/Objects/Data/Action/ActionSystem.ts b/app/src/Shared/Objects/Data/Action/ActionSystem.ts index f390715..473ec98 100644 --- a/app/src/Shared/Objects/Data/Action/ActionSystem.ts +++ b/app/src/Shared/Objects/Data/Action/ActionSystem.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import DataMap from '../DataMap.js' import AbstractData, {DataEntries} from '../AbstractData.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' @@ -24,6 +24,12 @@ export default class ActionSystem extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionSystemRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } export class ActionSystemTrigger extends AbstractData { interval: number = 0 diff --git a/app/src/Shared/Objects/Data/Action/ActionURI.ts b/app/src/Shared/Objects/Data/Action/ActionURI.ts index fbfc503..537f6d3 100644 --- a/app/src/Shared/Objects/Data/Action/ActionURI.ts +++ b/app/src/Shared/Objects/Data/Action/ActionURI.ts @@ -1,4 +1,4 @@ -import AbstractAction from './AbstractAction.js' +import AbstractAction, {IActionCallback} from './AbstractAction.js' import {OptionEntryUsage} from '../../Options/OptionEntryType.js' import DataMap from '../DataMap.js' @@ -22,5 +22,11 @@ export default class ActionURI extends AbstractAction { } }) } + + async build(key: string): Promise { + const runner = await import('../../../../Server/Objects/Data/ActionURIRunner.js') + const instance = new runner.default() + return instance.getCallback(key, this) + } } diff --git a/app/src/Shared/Objects/Data/EnlistData.ts b/app/src/Shared/Objects/Data/EnlistData.ts index 414e6a9..603097c 100644 --- a/app/src/Shared/Objects/Data/EnlistData.ts +++ b/app/src/Shared/Objects/Data/EnlistData.ts @@ -61,25 +61,6 @@ import PresetDiscordWebhook from './Preset/PresetDiscordWebhook.js' import PresetOBSScene, {PresetOBSFilter, PresetOBSSource} from './Preset/PresetOBS.js' import PresetPermissions from './Preset/PresetPermissions.js' import PresetPhilipsHueBulbState, {PresetPhilipsHueBulb, PresetPhilipsHuePlug} from './Preset/PresetPhilipsHue.js' -import ActionInputRunner from '../../../Server/Objects/Data/ActionInputRunner.js' -import ActionLabelRunner from '../../../Server/Objects/Data/ActionLabelRunner.js' -import ActionURIRunner from '../../../Server/Objects/Data/ActionURIRunner.js' -import ActionMoveVRSpaceRunner from '../../../Server/Objects/Data/ActionMoveVRSpaceRunner.js' -import ActionOBSRunner from '../../../Server/Objects/Data/ActionOBSRunner.js' -import ActionPhilipsHueBulbRunner from '../../../Server/Objects/Data/ActionPhilipsHueBulbRunner.js' -import ActionPipeRunner from '../../../Server/Objects/Data/ActionPipeRunner.js' -import ActionRemoteCommandRunner from '../../../Server/Objects/Data/ActionRemoteCommandRunner.js' -import ActionScreenshotRunner from '../../../Server/Objects/Data/ActionScreenshotRunner.js' -import ActionSettingTTSRunner from '../../../Server/Objects/Data/ActionSettingTTSRunner.js' -import ActionSettingVRRunner from '../../../Server/Objects/Data/ActionSettingVRRunner.js' -import ActionSignRunner from '../../../Server/Objects/Data/ActionSignRunner.js' -import ActionSpeechRunner from '../../../Server/Objects/Data/ActionSpeechRunner.js' -import ActionSystemRunner from '../../../Server/Objects/Data/ActionSystemRunner.js' -import ActionAudioRunner from '../../../Server/Objects/Data/ActionAudioRunner.js' -import ActionChatRunner from '../../../Server/Objects/Data/ActionChatRunner.js' -import ActionCustomRunner from '../../../Server/Objects/Data/ActionCustomRunner.js' -import ActionDiscordRunner from '../../../Server/Objects/Data/ActionDiscordRunner.js' -import ActionPhilipsHuePlugRunner from '../../../Server/Objects/Data/ActionPhilipsHuePlugRunner.js' /** * TODO: Try to do this dynamically in EJS when we are in Node, scan the Objects source folder and auto-generate this file. @@ -90,7 +71,6 @@ import ActionPhilipsHuePlugRunner from '../../../Server/Objects/Data/ActionPhili export default class EnlistData { static run() { const objects: AbstractData[] = [ - // region Actions new ActionAudio(), new ActionChat(), new ActionCustom(), @@ -119,29 +99,6 @@ export default class EnlistData { new ActionSystemRewardStateForEvent(), new ActionSystemUserEvent(), - // region Runners - new ActionAudioRunner(), - new ActionChatRunner(), - new ActionCustomRunner(), - new ActionDiscordRunner(), - new ActionInputRunner(), - new ActionLabelRunner(), - new ActionURIRunner(), - new ActionMoveVRSpaceRunner(), - new ActionOBSRunner(), - new ActionPhilipsHueBulbRunner(), - new ActionPhilipsHuePlugRunner(), - new ActionPipeRunner(), - new ActionRemoteCommandRunner(), - new ActionScreenshotRunner(), - new ActionSettingTTSRunner(), - new ActionSettingVRRunner(), - new ActionSignRunner(), - new ActionSpeechRunner(), - new ActionSystemRunner(), - // endregion - // endregion - new ConfigAnnounceCheer(), new ConfigAnnounceRaid(), new ConfigAnnounceSub(), diff --git a/app/src/Shared/Objects/Data/Trigger/TriggerReward.ts b/app/src/Shared/Objects/Data/Trigger/TriggerReward.ts index c233df7..05b4511 100644 --- a/app/src/Shared/Objects/Data/Trigger/TriggerReward.ts +++ b/app/src/Shared/Objects/Data/Trigger/TriggerReward.ts @@ -10,6 +10,7 @@ import {ActionHandler} from '../../../Bot/Actions.js' import DataUtils from '../DataUtils.js' import {ITwitchReward} from '../../../Classes/TwitchEventSub.js' import Utils from '../../../Utils/Utils.js' +import PresetReward from '../Preset/PresetReward.js' export default class TriggerReward extends AbstractTrigger { permissions: number|DataEntries = 0