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

Commit 60b2a8d

Browse files
committed
modValue to calcValue changes and readme additions
1 parent 34c5b67 commit 60b2a8d

File tree

7 files changed

+32
-29
lines changed

7 files changed

+32
-29
lines changed

Profiles/Factorio - Advanced Usage Example.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
{
99
"condition": "[VALUE] >= 10",
1010
"manipulator": "int([VALUE]/10)",
11-
"action": "/a_custom_command [MODVALUE] '[BESTNAME]'"
11+
"action": "/a_custom_command [CALCVALUE] '[BESTNAME]'"
1212
},
1313
{
1414
"condition": "[ALL]",
15-
"manipulator": "myValue = floor([VALUE])\nmodValue = myValue * 2",
16-
"action": "special modValue: \"[MODVALUE]\""
15+
"manipulator": "myValue = floor([VALUE])\ncalcValue = myValue * 2",
16+
"action": "special calcValue: \"[CALCVALUE]\""
1717
}
1818
]
1919
},
@@ -23,7 +23,7 @@
2323
{
2424
"condition": "[ALL]",
2525
"manipulator": "'bob'",
26-
"action": "static manipulator value: \"[MODVALUE]\""
26+
"action": "static manipulator value: \"[CALCVALUE]\""
2727
}
2828
]
2929
},
@@ -33,7 +33,7 @@
3333
{
3434
"condition": "[VALUE] >= 0",
3535
"manipulator": "'bo\\'b'",
36-
"action": "/sc game.print('[MODVALUE]\\'s great' .. ' and ' .. \"[BESTNAME]'s awesome\")"
36+
"action": "/sc game.print('[CALCVALUE]\\'s great' .. ' and ' .. \"[BESTNAME]'s awesome\")"
3737
}
3838
]
3939
}

Profiles/Factorio - Print Most Fancy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"condition": "[VALUE] >= 5",
1111
"manipulator": "[VALUE] * 1.5",
12-
"action": "Thanks for the $[VALUE] donation [name], its worth $[MODVALUE] to me"
12+
"action": "Thanks for the $[VALUE] donation [name], its worth $[CALCVALUE] to me"
1313
},
1414
{
1515
"condition": "[VALUE] < 5",

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,25 @@ When an Streamlabs event is received it is processed to have the standard `[ALL]
3434

3535
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 a scripts conditions to be used to select the approperiate action to do for the event. All of the events data attributes from Streamlabs and this app can be used witihn the filter in the format `[DATA_ITEM_NAME]`. i.e. `[VALUE] >= 5 and [VALUE] < 10`. There is a special `ALL` filter option that it 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 others conditions.
3636

37-
The first complying reaction filter will then run an optional manipulator script if configured. This creates a new data item for the event `[MODVALUE]` with the scripts output value. This is used when you want to pass a modified value in to the game.
37+
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 in to the game.
3838

39-
The action tied to the filter are 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 $[MODVALUE]` 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 its convienent. Should an Rcon command get a response from the server it will be shown in the Activity Log as is liekly an error from the game.
39+
The action tied to the filter are 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 its convienent. Should an Rcon command get a response from the server it will be shown in the Activity Log as is liekly an error from the game.
4040

41-
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.
41+
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.
4242

4343
When the application starts up all profiles in the profile folder are checked for their compliance with the event handler types and their attributes. All conditions and manipulators will be tested with a value of "1" for all attributes to confirm they are valid python scripts. Any issues causes the program to stop loading and the issue is recorded to the log file. This is to avoid failure from mis-configuration at run time.
4444
Additional profiles can be created within the Profiles folder following the sample profile syntax and the eventDefinitions.json events and attributes.
4545

4646
After configuring the application it is advised to run it and use the Streamlabs Test Widget option to send test events and confirm it behaves as you expect.
4747

48+
49+
Creating Profiles Notes
50+
========
51+
4852
Profile configuration files must be created with knowledge of quote escaping. The profile file is in the JSON syntax and so all text strings must be wrapped in double quotes `"` within it. If you want to use a duoble quote within a text string it must be escaped with a back slash `\`. Single quotes can be used fine within a JSON string and are advised for this reason. Data attributes will be made safe by the program; with any single or doube quotes either being removed by Python automatically or escaped with a backslash before being used as part of an rcon command. If you require a single or double quote to be recieved by Rcon escaped then you must escape it with 2 back slashes `\\'`. See the `Factorio - Advanced Usage Example.json` for examples of the some of these combinations.
4953

54+
Manipulator script's are special in that they support raw python code that will be executed within a Python exec() function in addition to a python expression that is executed within a Python eval() function. The event handler will try to eval() the manipulator script first and should it error then try to exec() the manipulator script. As the manipulator script is supplied via the profile JSON file it must be in a single line format with `\n` for the line breaks. The Python maths module is included within the execution environment. The local variable `calcValue` is passed out of the exec environment as the value of `CALCVALUE`. See the `Factorio - Advanced Usage Example.json` for examples of the some of these combinations.
55+
5056

5157
Development Building
5258
=============

Source/StreamlabsEvent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ def GetEventRawTitlesAsPrettyString(self):
171171
eventDesc = "No Title Details"
172172
return eventDesc
173173

174-
def SubstituteEventDataIntoString(self, string, modValue="''"):
174+
def SubstituteEventDataIntoString(self, string, calcValue="''"):
175175
instances = StreamlabsEventUtils.FindAttributeTagsInString(string)
176176
for instance in instances:
177177
dataKeyName = instance[1:-1]
178178
dataKeyValue = "''"
179-
if dataKeyName == "MODVALUE":
180-
dataKeyValue = modValue
179+
if dataKeyName == "CALCVALUE":
180+
dataKeyValue = calcValue
181181
elif dataKeyName == "VALUE":
182182
dataKeyValue = self.GetValueForDisplay()
183183
elif dataKeyName == "PLATFORM":
@@ -225,14 +225,14 @@ def LoadEventDefinitions():
225225
StreamlabsEventUtils.handledEventTypes = data
226226

227227
@staticmethod
228-
def IsBadEventAttritubeUsed(eventType, string, modValueAllowed):
228+
def IsBadEventAttritubeUsed(eventType, string, calcValueAllowed):
229229
if string in ["", "[ALL]", "[NOTHING]"]:
230230
return ""
231231
instances = StreamlabsEventUtils.FindAttributeTagsInString(string)
232232
for instance in instances:
233233
dataKeyName = instance[1:-1]
234-
if dataKeyName == "MODVALUE" and not modValueAllowed:
235-
return "[MODVALUE] used when not allowed"
234+
if dataKeyName == "CALCVALUE" and not calcValueAllowed:
235+
return "[CALCVALUE] used when not allowed"
236236
if dataKeyName in StreamlabsEventUtils.handledEventTypes['[ALL]'].keys():
237237
continue
238238
if eventType == "" or dataKeyName not in StreamlabsEventUtils.handledEventTypes[eventType].keys():
@@ -259,8 +259,8 @@ def IsScriptValid(scriptString):
259259

260260
@staticmethod
261261
def ProcessExecScript(scriptString):
262-
locals = {"modValue": 0}
262+
locals = {"calcValue": 0}
263263
globals = {}
264264
script = "from math import *\n" + scriptString + "\n"
265265
exec(script, globals, locals)
266-
return locals["modValue"]
266+
return locals["calcValue"]

Source/eventDefinitions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"valueType": "number",
2121
"description": "the standardised value of the event. Donations and money amounts are converted to USD with 2 decimal digits for cents if needed. Subscriptions have the USD cost of them. Follows and Hosts have the viewer count."
2222
},
23-
"MODVALUE": {
23+
"CALCVALUE": {
2424
"valueType": "number",
2525
"description": "Action only - an optional calculated value generated by the manipulator script that is only available in the action script."
2626
},

ToDo.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ Make so that profile startup errors are shown in a GUI and disable running until
44
Have seperate Activity and System (status, warning, errors) logs
55
Have a way to pause logs from updating and then resume
66
Add a way to fire test events data at this to allow better testing of responses than the Streamlabs Test Widgets button.
7+
Support multiple calculated values via exec. Array in exec, to numbered strings in action script.
8+
Support multiple rcon commands as an array in JSON.
79

810

911

1012

11-
the integration handles gifted subs for the recipient of the sub, but knowing its been gifted by someone.
12-
that's probably something to add to the integration list to be able to handle gifted subs as single donation from the gifter.
1313

14-
add option for getting gift subscriptions from the gifter view and not from the receiver view
1514

16-
can have multiple payloads per event. need to split these up to separate events internally.
15+
add option for getting gift subscriptions from the gifter view as well as from the receiver view
1716

18-
Support multiple rcon commands as an array in JSON.
17+
can have multiple payloads per event. need to split these up to separate events internally.
1918

20-
Support multiple calculated values via exec. Array in exec, to numbered strings in action script.
2119

22-
change modvalue to calcvalue

my custom profiles/ColonelWill - Chat Hunts Will.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"filteredActions": [
88
{
99
"condition": "[VALUE] >= 1",
10-
"manipulator": "value = floor([VALUE])\nvalue100 = int(value/100)\nmodValue = modValue + (value100 * 1500)\nvalue = value - (value100 * 100)\nvalue50 = int(value/50)\nmodValue = modValue + (value50 * 500)\nvalue = value - (value50 * 50)\nvalue25 = int(value/25)\nmodValue = modValue + (value25 * 175)\nvalue = value - (value25 * 25)\nvalue10 = int(value/10)\nmodValue = modValue + (value10 * 60)\nvalue = value - (value10 * 10)\nvalue5 = int(value/5)\nmodValue = modValue + (value5 * 25)\nvalue = value - (value5 * 5)\nmodValue = modValue + (value * 3)",
11-
"action": "/add-biters [MODVALUE] '[BESTNAME]'"
10+
"manipulator": "value = floor([VALUE])\nvalue100 = int(value/100)\ncalcValue = calcValue + (value100 * 1500)\nvalue = value - (value100 * 100)\nvalue50 = int(value/50)\ncalcValue = calcValue + (value50 * 500)\nvalue = value - (value50 * 50)\nvalue25 = int(value/25)\ncalcValue = calcValue + (value25 * 175)\nvalue = value - (value25 * 25)\nvalue10 = int(value/10)\ncalcValue = calcValue + (value10 * 60)\nvalue = value - (value10 * 10)\nvalue5 = int(value/5)\ncalcValue = calcValue + (value5 * 25)\nvalue = value - (value5 * 5)\ncalcValue = calcValue + (value * 3)",
11+
"action": "/add-biters [CALCVALUE] '[BESTNAME]'"
1212
},
1313
{
1414
"condition": "[ALL]",
@@ -32,8 +32,8 @@
3232
"filteredActions": [
3333
{
3434
"condition": "[VALUE] >= 5",
35-
"manipulator": "value = floor([VALUE])\nvalue100 = int(value/100)\nmodValue = modValue + (value100 * 1500)\nvalue = value - (value100 * 100)\nvalue50 = int(value/50)\nmodValue = modValue + (value50 * 500)\nvalue = value - (value50 * 50)\nvalue25 = int(value/25)\nmodValue = modValue + (value25 * 175)\nvalue = value - (value25 * 25)\nvalue10 = int(value/10)\nmodValue = modValue + (value10 * 60)\nvalue = value - (value10 * 10)\nvalue5 = int(value/5)\nmodValue = modValue + (value5 * 25)\nvalue = value - (value5 * 5)\nmodValue = modValue + (value * 3)",
36-
"action": "/add-biters [MODVALUE] '[BESTNAME]'"
35+
"manipulator": "value = floor([VALUE])\nvalue100 = int(value/100)\ncalcValue = calcValue + (value100 * 1500)\nvalue = value - (value100 * 100)\nvalue50 = int(value/50)\ncalcValue = calcValue + (value50 * 500)\nvalue = value - (value50 * 50)\nvalue25 = int(value/25)\ncalcValue = calcValue + (value25 * 175)\nvalue = value - (value25 * 25)\nvalue10 = int(value/10)\ncalcValue = calcValue + (value10 * 60)\nvalue = value - (value10 * 10)\nvalue5 = int(value/5)\ncalcValue = calcValue + (value5 * 25)\nvalue = value - (value5 * 5)\ncalcValue = calcValue + (value * 3)",
36+
"action": "/add-biters [CALCVALUE] '[BESTNAME]'"
3737
},
3838
{
3939
"condition": "[ALL]",

0 commit comments

Comments
 (0)