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

Commit abdb084

Browse files
committed
Add support for exec python scripts as well as the eval short functions
1 parent 6e840b8 commit abdb084

File tree

5 files changed

+75
-11
lines changed

5 files changed

+75
-11
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "ColonelWill - Chat Hunts Will",
3+
"description": "Chat hunts will buying biters 2019-06-11",
4+
"reactions": [
5+
{
6+
"valueType": "money",
7+
"filteredActions": [
8+
{
9+
"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]'"
12+
},
13+
{
14+
"condition": "[ALL]",
15+
"manipulator": "",
16+
"action": "[NOTHING]"
17+
}
18+
]
19+
},
20+
{
21+
"valueType": "follow",
22+
"filteredActions": [
23+
{
24+
"condition": "[ALL]",
25+
"manipulator": "",
26+
"action": "/add-biters 10 '[BESTNAME]'"
27+
}
28+
]
29+
},
30+
{
31+
"valueType": "viewer",
32+
"filteredActions": [
33+
{
34+
"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]'"
37+
},
38+
{
39+
"condition": "[ALL]",
40+
"manipulator": "",
41+
"action": "[NOTHING]"
42+
}
43+
]
44+
}
45+
]
46+
}

Profiles/Factorio - Advanced Usage Example.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"valueType": "money",
77
"filteredActions": [
88
{
9-
"condition": "[VALUE] >= 5",
10-
"manipulator": "int([VALUE]/5)",
9+
"condition": "[VALUE] >= 10",
10+
"manipulator": "int([VALUE]/10)",
1111
"action": "/a_custom_command [MODVALUE] '[BESTNAME]'"
1212
},
1313
{
1414
"condition": "[ALL]",
15-
"manipulator": "'bob'",
16-
"action": "static manipulator value: \"[MODVALUE]\""
15+
"manipulator": "myValue = floor([VALUE])\nmodValue = myValue * 2",
16+
"action": "special modValue: \"[MODVALUE]\""
1717
}
1818
]
1919
},
@@ -22,8 +22,8 @@
2222
"filteredActions": [
2323
{
2424
"condition": "[ALL]",
25-
"manipulator": "",
26-
"action": "/sc game.print('[BESTNAME]')"
25+
"manipulator": "'bob'",
26+
"action": "static manipulator value: \"[MODVALUE]\""
2727
}
2828
]
2929
},

Source/Profiles.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ def GetActionText(self, event):
172172
if self.manipulator != None and self.manipulator != "":
173173
manipulatorValueString = event.SubstituteEventDataIntoString(
174174
self.manipulator)
175-
manipulatorValue = eval(manipulatorValueString)
175+
manipulatorValue = 0
176+
try:
177+
manipulatorValue = eval(manipulatorValueString)
178+
except:
179+
manipulatorValue = StreamlabsEventUtils.ProcessExecScript(
180+
manipulatorValueString)
176181
return event.SubstituteEventDataIntoString(
177182
actionText, manipulatorValue)
178183
return event.SubstituteEventDataIntoString(

Source/StreamlabsEvent.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def IsHandledEvent(self):
100100
return False
101101

102102
def ShouldIgnoreEvent(self):
103-
if (self.type == "streamlabels") or (self.type == "streamlabels.underlying") or (self.type == "alertPlaying") or (self.type == "subscription-playing") or (self.type == "rollEndCredits") or (self.type == "subMysteryGift"):
103+
if (self.type == "streamlabels") or (self.type == "streamlabels.underlying") or (self.type == "alertPlaying") or (self.type == "subscription-playing") or (self.type == "rollEndCredits") or (self.type == "subMysteryGift") or (self.type == "eventListSettingsUpdate"):
104104
return True
105105
if (self.platform == "widget"):
106106
return True
@@ -246,6 +246,17 @@ def IsScriptValid(scriptString):
246246
testScriptString = testScriptString.replace(instance, str(1))
247247
try:
248248
eval(testScriptString)
249-
except Exception:
250-
return "config value: " + scriptString + "\n" + Traceback.format_exc(limit=0, chain=False)
249+
except:
250+
try:
251+
StreamlabsEventUtils.ProcessExecScript(testScriptString)
252+
except Exception:
253+
return "config value: " + scriptString + "\n" + Traceback.format_exc(limit=0, chain=False)
251254
return ""
255+
256+
@staticmethod
257+
def ProcessExecScript(scriptString):
258+
locals = {"modValue": 0}
259+
globals = {}
260+
script = "from math import *\n" + scriptString + "\n"
261+
exec(script, globals, locals)
262+
return locals["modValue"]

event samples.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ TWITCH REAL WORLD
2626

2727
00:37:01 : Streamlabs supported raw event received: {'type': 'host', 'message': [{'name': 'UsEr', 'viewers': 157, 'type': 'manual', '_id': '47740b852ebfe74364d1d2123e2cec35', 'event_id': '47740b852ebfe74364d1d2123e2cec35'}], 'for': 'twitch_account'}
2828

29-
22:43:07 : Streamlabs supported raw event received: {'type': 'raid', 'message': [{'id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275', 'name': 'user', 'display_name': 'UsEr', 'raiders': '28', '_id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275', 'event_id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275'}], 'for': 'twitch_account'}
29+
22:43:07 : Streamlabs supported raw event received: {'type': 'raid', 'message': [{'id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275', 'name': 'user', 'display_name': 'UsEr', 'raiders': '28', '_id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275', 'event_id': 'a7ca29ca-03c8-4857-b9d4-915fa03fc275'}], 'for': 'twitch_account'}
30+
31+
19:37:29 : Streamlabs raw event data: {'type': 'pledge', 'message': [{'name': 'UsEr', 'isTest': True, 'formatted_amount': '£56.00', 'amount': 56, 'currency': 'GBP', 'to': {'name': 'StReAmErNaMe'}, 'from': 'Real Name', '_id': '938e6fdb71d5b11a19d170c3dbca555c'}], 'for': 'patreon', 'event_id': 'evt_a5f4b15b617c16d498f8fdf6d0865aaa'}

0 commit comments

Comments
 (0)