Skip to content

Commit

Permalink
Fix system action event reward toggling and user input event triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
BOLL7708 committed Jun 15, 2024
1 parent 458e4c1 commit 54f76ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/src/Server/Runners/Action/ActionSystemRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class ActionSystemRunner extends AbstractActionRunner {
const interval = clone.trigger.interval
let delay = 0

// region Trigger

// Trigger System Actions
const systemActions = ArrayUtils.getAsType(clone.trigger.systemActionEntries, clone.trigger.systemActionEntries_use, index)
for(const systemAction of systemActions) {
Expand Down Expand Up @@ -109,6 +111,9 @@ export default class ActionSystemRunner extends AbstractActionRunner {
new ActionHandler(userEventEntry.dataSingle.key).call(user).then()
}
}
// endregion

// region Toggle

// Toggle Rewards
const rewardStates = clone.toggle.rewardStates
Expand All @@ -118,7 +123,7 @@ export default class ActionSystemRunner extends AbstractActionRunner {
const eventEntry = DataUtils.ensureItem(eventStates.event)
const event = eventEntry?.dataSingle.filledData
if(event) {
const rewards = DataUtils.ensureDataArray(event.triggers).filter(trigger => trigger.__getClass() == TriggerReward.name) as TriggerReward[]
const rewards = DataUtils.ensureDataArray(event.triggers) as TriggerReward[]
for(const reward of rewards) {
const rewardID = DataUtils.ensureItem(reward.rewardID)
if(rewardID) {
Expand All @@ -134,6 +139,8 @@ export default class ActionSystemRunner extends AbstractActionRunner {

// Toggle the rewards on Twitch
await TwitchHelixHelper.toggleRewards(rewardStates)

// endregion
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/Shared/Objects/Data/DataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AbstractData, {DataEntries, DataRefValues} from './AbstractData.js'
import DataMap from './DataMap.js'
import {IDictionary, INumberDictionary, IStringDictionary} from '../../Interfaces/igeneral.js'
import {IDataBaseItem} from '../../Helpers/DataBaseHelper.js'
import Utils from '../../../Shared/Utils/Utils.js'

export default class DataUtils {
// region Referencing
Expand Down Expand Up @@ -186,7 +187,9 @@ export default class DataUtils {
else return entries
}
static ensureItemDictionary<T>(entries: INumberDictionary|DataEntries<T>): DataEntries<T>|undefined {
if(entries.constructor.name !== DataEntries.name) return undefined
const keys = Object.keys(entries)
const matchKeys = Object.keys(new DataEntries())
if(!Utils.containsAll(keys, matchKeys)) return undefined
else return entries as DataEntries<T>
}
// endregion
Expand Down
10 changes: 10 additions & 0 deletions app/src/Shared/Utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ export default class Utils {
return JSON.parse(JSON.stringify(data)) as Type
}

/**
* Checks if all the needles exist in the haystack.
* @param haystack
* @param needles
*/
static containsAll(needles: any[], haystack: any[]): boolean {
const haystackSet = new Set(haystack)
return needles.every(item => haystackSet.has(item))
}

/**
* Splits a Steam app key into parts and returns the parsed number
* @param appId
Expand Down

0 comments on commit 54f76ed

Please sign in to comment.