Skip to content

Commit

Permalink
Delist runners again, switch runners to extend AbstractActionRunner, …
Browse files Browse the repository at this point in the history
…add build back into data classes with a dynamic import.
  • Loading branch information
BOLL7708 committed Apr 21, 2024
1 parent 7ca8b3e commit b484501
Show file tree
Hide file tree
Showing 43 changed files with 245 additions and 146 deletions.
5 changes: 5 additions & 0 deletions app/src/Server/Objects/Data/AbstractActionRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import AbstractAction, {IActionCallback} from '../../../Shared/Objects/Data/Action/AbstractAction.js'

export default abstract class AbstractActionRunner {
abstract getCallback<T>(key: string, instance: T&AbstractAction): IActionCallback
}
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionAudioRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionAudio>(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
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionChatRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionChat>(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) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionCustomRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionCustom>(this)
const clone = Utils.clone(instance as ActionCustom)
const modules = ModulesSingleton.getInstance()
eval(clone.code)
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionDiscordRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionDiscord>(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)
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionInputRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionInput>(this)
const clone = Utils.clone(instance as ActionInput)
clone.commands = ArrayUtils.getAsType(clone.commands, clone.commands_use, index)
ExecUtils.runCommandsFromAction(clone)
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionLabelRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionLabel>(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))
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionMoveVRSpaceRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionMoveVRSpace>(this)
const clone = Utils.clone(instance as ActionMoveVRSpace)
const modules = ModulesSingleton.getInstance()
modules.openvr2ws.moveSpace(clone)
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionOBSRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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
Expand Down
11 changes: 6 additions & 5 deletions app/src/Server/Objects/Data/ActionPhilipsHueBulbRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionPhilipsHueBulb>(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)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionPhilipsHuePlugRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionPhilipsHuePlug>(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)
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionPipeRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionPipe>(this)
const clone = Utils.clone(instance as ActionPipe)
const modules = ModulesSingleton.getInstance()
const customPreset = DataUtils.ensureData(clone.customPreset)
const basicPreset = DataUtils.ensureData(clone.basicPreset)
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionRemoteCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionRemoteCommand>(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) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionScreenshotRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionScreenshot>(this)
const clone = Utils.clone(instance as ActionScreenshot)
const states = StatesSingleton.getInstance()
const modules = ModulesSingleton.getInstance()
const userInput = user.input
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionSettingTTSRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionSettingTTS>(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)
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionSettingVRRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionSettingVR>(this)
const clone = Utils.clone(instance as ActionSettingVR)
const modules = ModulesSingleton.getInstance()
modules.openvr2ws.setSetting(clone)
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/Server/Objects/Data/ActionSignRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<ActionSign>(this)
const clone = Utils.clone(instance as ActionSign)
const modules = ModulesSingleton.getInstance()
TwitchHelixHelper.getUserById(user.id).then(async userData => {
const modules = ModulesSingleton.getInstance()
Expand Down
Loading

0 comments on commit b484501

Please sign in to comment.