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

Commit 57d4d1b

Browse files
committed
add basic support of subMysteryGift
1 parent 3df480b commit 57d4d1b

File tree

11 files changed

+88
-34
lines changed

11 files changed

+88
-34
lines changed

Profiles/Factorio - Print Most Fancy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"platform": "twitch_account",
39-
"type": "subscription_gift",
39+
"type": "subscriptionGift",
4040
"filteredActions": [
4141
{
4242
"condition": "[VALUE] >= 5",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Profile configuration files must be created with knowledge of quote escaping. Th
5353

5454
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.
5555

56-
The config has a `Test Mode` option. When enabled it prints the RCON commands to the activity window rather than sending them. It also skips the RCON connection test which the Start button is clicked within the app. In effect not doing any RCON commands.
56+
The config has a `Rcon No Commands` option. When enabled it prints the RCON commands to the activity window rather than sending them. It also skips the RCON connection test which the Start button is clicked within the app. In effect not doing any RCON commands.
5757

5858

5959
Development Building

Source/Config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _PopulateMissingConfigDefaults(self):
2727
"Rcon Server Port": 25575,
2828
"Rcon Server Password": "",
2929
"Rcon Test Command": "/version",
30-
"Test Mode": False
30+
"Rcon No Commands": False
3131
}
3232
for name, value in defaults.items():
3333
if not name in self._settings:

Source/Profiles.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ def __init__(self, reactionData, profile):
6767
self.handlerName = StreamlabsEventUtils.MakeHandlerString(
6868
self.platform, self.type)
6969
if self.handlerName not in StreamlabsEventUtils.handledEventTypes.keys():
70-
self.logging.LogQuit(
71-
"invalid event handler type: " + self.handlerName)
70+
self.logging.LogQuit(self.profile.name +
71+
" : has invalid event handler type: " + self.handlerName)
7272
else:
7373
self.valueType = reactionData["valueType"]
7474
if self.valueType not in ["money", "follow", "viewer"]:
75-
self.logging.LogQuit("invalid valueType: " + self.valueType)
75+
self.logging.LogQuit(
76+
self.profile.name + " : has invalid valueType: " + self.valueType)
7677
self.filterActionPriorities = {1: [], 2: []}
7778
for filteredActionData in reactionData["filteredActions"]:
7879
filteredAction = FilteredAction(filteredActionData, self)
@@ -101,30 +102,31 @@ class FilteredAction:
101102
def __init__(self, filteredActionData, reaction):
102103
self.reaction = reaction
103104
self.logging = self.reaction.profile.profiles.state.logging
105+
errorLoggingParentsString = reaction.profile.name + " : " + reaction.handlerName
104106

105107
self.condition = filteredActionData["condition"]
106108
if self.condition == "":
107-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
109+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
108110
"' condition can not be blank")
109111
eventAttributeCheckResult = StreamlabsEventUtils.IsBadEventAttritubeUsed(
110112
self.reaction.handlerName, self.condition, False)
111113
if eventAttributeCheckResult != "":
112-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
114+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
113115
"' condition error: " + eventAttributeCheckResult)
114116
scriptParseCheck = StreamlabsEventUtils.IsScriptValid(self.condition)
115117
if scriptParseCheck != "":
116-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
118+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
117119
"' has an invalid condition script:\n" + scriptParseCheck)
118120

119121
self.manipulator = filteredActionData["manipulator"]
120122
eventAttributeCheckResult = StreamlabsEventUtils.IsBadEventAttritubeUsed(
121123
self.reaction.handlerName, self.manipulator, False)
122124
if eventAttributeCheckResult != "":
123-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
125+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
124126
"' manipulator error: " + eventAttributeCheckResult)
125127
scriptParseCheck = StreamlabsEventUtils.IsScriptValid(self.manipulator)
126128
if scriptParseCheck != "":
127-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
129+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
128130
"' has an invalid manipulator script:\n" + scriptParseCheck)
129131

130132
self.actionText = ""
@@ -137,20 +139,20 @@ def __init__(self, filteredActionData, reaction):
137139
eventAttributeCheckResult = StreamlabsEventUtils.IsBadEventAttritubeUsed(
138140
self.reaction.handlerName, self.action.effect, True)
139141
if eventAttributeCheckResult != "":
140-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() + "' referenced action " +
142+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() + "' referenced action " +
141143
actionName + " which has action text error: " + eventAttributeCheckResult)
142144
else:
143-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
145+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
144146
"' referenced non-existent action : " + actionName)
145147
else:
146148
self.actionText = action
147149
if self.actionText == "":
148-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
150+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
149151
"' action can not be blank")
150152
eventAttributeCheckResult = StreamlabsEventUtils.IsBadEventAttritubeUsed(
151153
self.reaction.handlerName, self.actionText, True)
152154
if eventAttributeCheckResult != "":
153-
self.logging.LogQuit("'" + self.reaction.GetPrintHandlerType() +
155+
self.logging.LogQuit(errorLoggingParentsString + " : '" + self.reaction.GetPrintHandlerType() +
154156
"' action text error: " + eventAttributeCheckResult)
155157

156158
def DoesEventTriggerAction(self, event):

Source/Rcon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, state):
1212
self.testCommand = self.state.config.GetSetting("Rcon Test Command")
1313

1414
def TestConnection(self):
15-
if self.state.config.GetSetting("Test Mode"):
15+
if self.state.config.GetSetting("Rcon No Commands"):
1616
return True
1717
try:
1818
self.SendCommand(self.testCommand)
@@ -24,9 +24,9 @@ def TestConnection(self):
2424
return False
2525

2626
def SendCommand(self, commandString):
27-
if self.state.config.GetSetting("Test Mode"):
27+
if self.state.config.GetSetting("Rcon No Commands"):
2828
self.state.RecordActivity(
29-
self.state.translations.GetTranslation("Rcon TestMode") + commandString)
29+
self.state.translations.GetTranslation("Rcon NoCommand") + commandString)
3030
return ""
3131
with MCRcon(self.serverAddress, self.serverPassword, self.serverPort) as mcr:
3232
return mcr.command(commandString)

Source/StreamlabsEvent.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, state, data):
5959
if self.type == "donation" and self.platform == "":
6060
self.platform = "streamlabs"
6161
elif self.platform == "twitch_account" and self.type == "subscription" and "gifter" in self.rawMessage and self.rawMessage["gifter"] != None:
62-
self.type = "subscription_gift"
62+
self.type = "subscriptionGift"
6363
self.handlerName = StreamlabsEventUtils.MakeHandlerString(
6464
self.platform, self.type)
6565

@@ -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") or (self.type == "eventListSettingsUpdate"):
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 == "eventListSettingsUpdate"):
104104
return True
105105
if (self.platform == "widget"):
106106
return True
@@ -127,15 +127,23 @@ def PopulateNormalisedData(self):
127127
elif (self.handlerName == "twitch_account-bits"):
128128
self.valueType = "money"
129129
self.value = round(float(self.rawMessage["amount"]) / 100, 2)
130-
elif (self.handlerName == "twitch_account-subscription") or (self.handlerName == "twitch_account-subscription_gift"):
130+
elif (self.handlerName == "twitch_account-subscription") or (self.handlerName == "twitch_account-subscriptionGift"):
131131
self.valueType = "money"
132132
subPlan = self.rawMessage["sub_plan"]
133-
if subPlan == "Prime" or subPlan == "1000":
134-
self.value = 5
135-
elif subPlan == "2000":
136-
self.value = 10
137-
elif subPlan == "3000":
138-
self.value = 25
133+
subValue = StreamlabsEventUtils.GetTwitchSubscriptionValue(subPlan)
134+
if subValue != None:
135+
self.value = subValue
136+
else:
137+
self.state.RecordActivity(
138+
self.state.translations.GetTranslation("StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
139+
return False
140+
elif (self.handlerName == "twitch_account-subMysteryGift"):
141+
self.bestName = self.rawMessage["gifter_display_name"]
142+
self.valueType = "money"
143+
subPlan = self.rawMessage["sub_plan"]
144+
subValue = StreamlabsEventUtils.GetTwitchSubscriptionValue(subPlan)
145+
if subValue != None:
146+
self.value = subValue * self.rawMessage["amount"]
139147
else:
140148
self.state.RecordActivity(
141149
self.state.translations.GetTranslation("StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
@@ -264,3 +272,14 @@ def ProcessExecScript(scriptString):
264272
script = "from math import *\n" + scriptString + "\n"
265273
exec(script, globals, locals)
266274
return locals["calcValue"]
275+
276+
@staticmethod
277+
def GetTwitchSubscriptionValue(subPlan):
278+
if subPlan == "Prime" or subPlan == "1000":
279+
return 5
280+
elif subPlan == "2000":
281+
return 10
282+
elif subPlan == "3000":
283+
return 25
284+
else:
285+
return None

Source/Translations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def LoadLocalisedTexts(self, language):
3030
"Rcon CommandError": "ERROR: Rcon command failed, run manually: ",
3131
"Rcon CommandResponseWarning": "WARNING: Rcon got response from server: ",
3232
"Rcon TestErrorMessage": "Rcon connection test message: ",
33-
"Rcon TestMode": "Rcon Test Mode: "
33+
"Rcon NoCommand": "Rcon Test Mode: "
3434
}
3535

3636
def GetTranslation(self, key):

Source/config.sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"Rcon Server Port": 25575,
1010
"Rcon Server Password": "",
1111
"Rcon Test Command": "/version",
12-
"Test Mode": false
12+
"Rcon No Commands": false
1313
}

Source/eventDefinitions.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
}
7575
},
7676
"twitch_account-subscription": {
77+
"_comment": "When a user gets themselves a subscription",
7778
"name": {
7879
"valueType": "text string",
7980
"description": "the username of the person who did the event"
@@ -95,7 +96,8 @@
9596
"description": "the number twitch uses to identify each sub tier: Prime, 1000, 2000, 3000"
9697
}
9798
},
98-
"twitch_account-subscription_gift": {
99+
"twitch_account-subscriptionGift": {
100+
"_comment": "When a user is gifted a subscription",
99101
"name": {
100102
"valueType": "text string",
101103
"description": "the username of the person who received the subscription"
@@ -125,6 +127,29 @@
125127
"description": "the display name of the person who gifted the subscription"
126128
}
127129
},
130+
"twitch_account-subMysteryGift": {
131+
"_comment": "When a user gifts a number of subscriptions to the community",
132+
"name": {
133+
"valueType": "text string",
134+
"description": "the username of the person who did the event"
135+
},
136+
"gifter": {
137+
"valueType": "text string",
138+
"description": "the username of the person who gifted the subscription"
139+
},
140+
"gifter_display_name": {
141+
"valueType": "text string",
142+
"description": "the display name of the person who gifted the subscription"
143+
},
144+
"amount": {
145+
"valueType": "number",
146+
"description": "the number of subscriptions gifted to the community"
147+
},
148+
"sub_plan": {
149+
"valueType": "number",
150+
"description": "the number twitch uses to identify each sub tier: Prime, 1000, 2000, 3000"
151+
}
152+
},
128153
"twitch_account-bits": {
129154
"name": {
130155
"valueType": "text string",

ToDo.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Handle paused Factorio server accepting but not reply to RCON command. It will h
1010

1111

1212

13+
At present a mysterySubGift will trigger plus each recipient will trigger the receiving subscription event. As mysterySubGift event comes first this needs to be monitored and receieved sub gift events ignored appropariately.
1314

1415

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

0 commit comments

Comments
 (0)