Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 402ff1a

Browse files
committed
all (multiple) filteredActions will run for an event where conditions are met
1 parent 70568a2 commit 402ff1a

File tree

6 files changed

+48
-39
lines changed

6 files changed

+48
-39
lines changed

Profiles/Factorio - Advanced Usage Example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
"manipulator": "int([VALUE]/10)",
4444
"action": "/a_custom_command [CALCVALUE] '[BESTNAME]'"
4545
},
46+
{
47+
"condition": "[VALUE] >= 0",
48+
"manipulator": "int([VALUE]/10)",
49+
"action": "I run with any value, including when the >10 action runs"
50+
},
4651
{
4752
"condition": "[ALL]",
4853
"manipulator": "myValue = floor([VALUE])\ncalcValue = myValue * 2",

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ The complete list of Streamlabs events and their contained data attributes can b
3333

3434
The app runs a single grouping of reactions at a time, being loaded and saved as a profile. During the process if no suitable option is found it will be shown within the app and that events processing stops. It's assumed you want to handle any event you get. Special options at each level exist for more simple uses cases.
3535

36-
When a Streamlabs event is received it is processed to have the standard `[ALL]` additional data attributes calculated for them. The reactions are reviewed to find the most appropriate one. First, the reactions are checked for the first matching platform and type to the event. If no match is found the ValueType of the event is checked for in the reactions for a match.
36+
When a Streamlabs event is received it is processed to have the standard `[ALL]` additional data attributes calculated for them. The reactions are reviewed to find the most appropriate one. Firstly, the reactions are checked for the first matching platform and type to the event, i.e. `twitch_account-subscription`. If no match is found the ValueType of the event is checked for in the reactions for a match, i.e. `money`.
3737

38-
Assuming a reaction for the event is found the reaction's filter script is checked for the first that is met (resolves to True). Filters allow the conditions of a script to be used to select the appropriate action to do for the event. All of the events data attributes from Streamlabs and this app can be used within the filter in the format `[DATA_ITEM_NAME]`. i.e. `[VALUE] >= 5 and [VALUE] < 10`. There is a special `ALL` filter option that if configured will be triggered after all other filters have been checked. The filters within a reaction are not order specific and so should not overlap each other's conditions.
38+
Assuming a reaction for the event is found, the reaction's `filteredActions` are checked. The `condition` script in each filteredAction is evaluated and those that are met (resolves to True)are executed for this event. All of the events data attributes from Streamlabs and this app can be used within the `condition` script in the format `[DATA_ITEM_NAME]`. i.e. `[VALUE] >= 5 and [VALUE] < 10`. There is a special `[ALL]` conditon script value that if configured will be triggered after all other suitable conditions have been triggered. The conditions within a reaction are order specific and so can overlap each other's conditions if desired.
3939

40-
The first complying reaction filter will then run an optional manipulator script if configured. This creates a new data item for the event `[CALCVALUE]` with the scripts output value. This is used when you want to pass a modified value into the game. Note that the values are treated as doubles and so rounding of the output to the desired accuracy is advised.
40+
Each suitable reaction filteredActions will then run an optional manipulator script if configured. This creates a new data item for the event `[CALCVALUE]` with the scripts output value. This is used when you want to pass a modified value into the game. Note that the values are treated as doubles and so rounding of the output to the desired accuracy is advised.
4141

42-
The action tied to the filter is the Rcon commands that are run in the game. It can utilise any of the events data attributes in the standard format `[DATA_ITEM_NAME]`. i.e. `[name] supported with $[VALUE] worth $[CALCVALUE]` or `/promote [name]`. There is a special `NOTHING` action that is intended for intentionally ignoring the event. This avoids any warnings about unhandled events. Actions can be either a specific Lua command string or the name of a shared Lua command string within the profile. This is to allow re-use of Lua command strings when it's convenient. Should a Rcon command get a response from the server it will be shown in the Activity Log as is likely an error from the game.
42+
The action tied to the filteredAction is the Rcon command string that is run in the game. It can utilise any of the events data attributes in the standard format `[DATA_ITEM_NAME]`. i.e. `[name] supported with $[VALUE] worth $[CALCVALUE]` or `/promote [name]`. There is a special `NOTHING` action that is intended for intentionally ignoring the event. This avoids any warnings about unhandled events. Actions can be either a specific Lua command string or the name of a shared Lua command string within the profile. This is to allow re-use of Lua command strings when it's convenient. Should an Rcon command get a response from the server it will be shown in the Activity Log as is likely an error from the game.
4343

4444
All data attributes used in scripts are replaced with their event data values at execution time. The replaced text may require wrapping in quotes if it needs to be treated as a string. A script is a single python expression that can be processed via the Python eval() function. It is executed within an environment that includes the Python maths module.
4545

Source/Profiles.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,15 @@ def __init__(self, profileData, profiles):
4343
else:
4444
self.options = Options(self, {})
4545

46-
def GetActionTextForEvent(self, event):
46+
def GetActionTextsForEvent(self, event):
47+
results = []
4748
for reaction in self.reactionPriorities[1]:
4849
if reaction.handlerName == event.handlerName:
49-
result = reaction.GetActionTextForEvent(event)
50-
if result != None:
51-
return result
50+
results += reaction.GetActionTextsForEvent(event)
5251
for reaction in self.reactionPriorities[2]:
5352
if reaction.valueType == event.valueType:
54-
result = reaction.GetActionTextForEvent(event)
55-
if result != None:
56-
return result
57-
return None
53+
results += reaction.GetActionTextsForEvent(event)
54+
return results
5855

5956

6057
class Reaction:
@@ -86,14 +83,15 @@ def __init__(self, reactionData, profile):
8683
else:
8784
self.filterActionPriorities[1].append(filteredAction)
8885

89-
def GetActionTextForEvent(self, event):
86+
def GetActionTextsForEvent(self, event):
87+
results = []
9088
for filterAction in self.filterActionPriorities[1]:
9189
if filterAction.DoesEventTriggerAction(event):
92-
return filterAction.GetActionText(event)
90+
results.append(filterAction.GetActionText(event))
9391
for filterAction in self.filterActionPriorities[2]:
9492
if filterAction.DoesEventTriggerAction(event):
95-
return filterAction.GetActionText(event)
96-
return None
93+
results.append(filterAction.GetActionText(event))
94+
return results
9795

9896
def GetPrintHandlerType(self):
9997
if self.handlerName != "":

Source/Streamlabs Rcon Integration.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,39 @@ def OnStreamlabsEventHandler(self, data):
143143
self.logging.DebugLog(
144144
"Streamlabs processed event: " + str(event))
145145

146-
actionText = self.profiles.currentProfile.GetActionTextForEvent(
146+
actionTexts = self.profiles.currentProfile.GetActionTextsForEvent(
147147
event)
148-
if actionText == None:
148+
if len(actionTexts) == 0:
149149
self.RecordActivity(
150150
self.translations.GetTranslation("StreamlabsEvent NoProfileAction") + event.GetEventRawTitlesAsPrettyString())
151151
self.logging.DebugLog(
152152
"No profile action for: " + event.GetEventRawTitlesAsPrettyString())
153153
return
154-
actionType = ""
155-
response = ""
156-
if actionText == "":
157-
actionType = "Ignore event"
158-
self.logging.DebugLog(
159-
"NOTHING action specified for: " + event.GetEventRawTitlesAsPrettyString())
160-
else:
161-
actionType = "Rcon command"
162-
try:
154+
for actionText in actionTexts:
155+
actionType = ""
156+
response = ""
157+
if actionText == "":
158+
actionType = "Ignore event"
163159
self.logging.DebugLog(
164-
"Doing Rcon command: " + actionText)
165-
response = self.rcon.SendCommand(actionText)
166-
except Exception as ex:
167-
self.logging.RecordException(ex, "Rcon event failed")
160+
"NOTHING action specified for: " + event.GetEventRawTitlesAsPrettyString())
161+
else:
162+
actionType = "Rcon command"
163+
try:
164+
self.logging.DebugLog(
165+
"Doing Rcon command: " + actionText)
166+
response = self.rcon.SendCommand(actionText)
167+
except Exception as ex:
168+
self.logging.RecordException(
169+
ex, "Rcon event failed")
170+
self.RecordActivity(
171+
self.translations.GetTranslation("Rcon CommandError") + actionText)
172+
return
173+
if response != "":
168174
self.RecordActivity(
169-
self.translations.GetTranslation("Rcon CommandError") + actionText)
170-
return
175+
self.translations.GetTranslation("Rcon CommandResponseWarning") + response)
176+
self.logging.DebugLog("Action done: " + actionText)
171177
self.RecordActivity(
172178
self.translations.GetTranslation("StreamlabsEvent EventHandled") + event.GetEventRawTitlesAsPrettyString() + " : " + event.bestName + " : value " + str(event.value) + " : " + actionType)
173-
if response != "":
174-
self.RecordActivity(
175-
self.translations.GetTranslation("Rcon CommandResponseWarning") + response)
176-
self.logging.DebugLog("Action done: " + actionText)
177179
except Exception as ex:
178180
self.logging.RecordException(
179181
ex, "OBS Event Handler Critical Error - This event won't be processed")

ToDo.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Bugs / Outstanding
22
===================
33

4-
Support multiple rcon commands as an array in JSON.
54

65

76

my custom profiles/JD_Plays - Followers Hunt JD.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
{
1919
"condition": "[ALL]",
2020
"manipulator": "",
21-
"action": "/biters_hunt_group_add_biters 1 1 /biters_hunt_group_reset_group_timer 1" NEEDS MULTI ACTION SUPPORT!
21+
"action": "/biters_hunt_group_add_biters 1 1"
22+
},
23+
{
24+
"condition": "[ALL]",
25+
"manipulator": "",
26+
"action": "/biters_hunt_group_reset_group_timer 1"
2227
}
2328
]
2429
},

0 commit comments

Comments
 (0)