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

Commit 6a2b5ac

Browse files
committed
Readme and testing facility update
Test events supports "Prime" sub_plan for twitch subscription. Some auto formatting changes.
1 parent affd4af commit 6a2b5ac

File tree

6 files changed

+231
-29
lines changed

6 files changed

+231
-29
lines changed

Source/Streamlabs Rcon Integration.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,26 @@ def OnTestEventButtonHandler(self):
186186
testEventType = self.gui.selectedTestEventType.get()
187187
testEventValue = ""
188188
if TestEventUtils.GetAttribute(testEventPlatform, testEventType, "valueInput"):
189-
try:
190-
testEventValue = self.gui.testEventValue.get()
191-
testEventValue = float(testEventValue)
192-
except:
193-
self.RecordActivity(
194-
self.translations.GetTranslation("TestEvent ValueNotFloat") + str(testEventValue))
195-
return
189+
testEventValue = self.gui.testEventValue.get()
190+
# Twitch Subscribe events allow special values.
191+
if testEventPlatform == "Twitch" and testEventType == "Subscribe":
192+
# If the value is "Prime" then just accept it.
193+
if testEventValue != "Prime":
194+
# Value isn't "Prime" so make sure its a number.
195+
try:
196+
testEventValue = float(testEventValue)
197+
except:
198+
self.RecordActivity(
199+
self.translations.GetTranslation("TestEvent ValueNotFloatOrPrime") + str(testEventValue))
200+
return
201+
else:
202+
# As a standard event type the value must be a number
203+
try:
204+
testEventValue = float(testEventValue)
205+
except:
206+
self.RecordActivity(
207+
self.translations.GetTranslation("TestEvent ValueNotFloat") + str(testEventValue))
208+
return
196209
testEventQuantity = ""
197210
if TestEventUtils.GetAttribute(testEventPlatform, testEventType, "quantityInput"):
198211
try:
@@ -212,9 +225,11 @@ def OnTestEventButtonHandler(self):
212225
if testEventPayloadCount <= 0:
213226
raise ValueError()
214227
except:
215-
self.RecordActivity(self.translations.GetTranslation("TestEvent PayloadCountNotInt") + str(testEventPayloadCount))
228+
self.RecordActivity(self.translations.GetTranslation(
229+
"TestEvent PayloadCountNotInt") + str(testEventPayloadCount))
216230
return
217-
testEventArray = self.testEventUtils.GenerateTestEventArray(testEventPlatform, testEventType, testEventValue, testEventQuantity, testEventPayloadCount)
231+
testEventArray = self.testEventUtils.GenerateTestEventArray(
232+
testEventPlatform, testEventType, testEventValue, testEventQuantity, testEventPayloadCount)
218233
if len(testEventArray) > 0:
219234
for testEvent in testEventArray:
220235
self.OnStreamlabsEventHandler(testEvent)

Source/StreamlabsEvent.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,24 @@ def PopulateNormalisedData(self):
109109
currency = self.rawMessage["currency"]
110110
else:
111111
currency = "USD"
112-
self.value = self.state.currency.GetNormalisedValue(currency, float(self.rawMessage["amount"]))
112+
self.value = self.state.currency.GetNormalisedValue(
113+
currency, float(self.rawMessage["amount"]))
113114
elif (self.handlerName == "patreon-pledge"):
114115
self.valueType = "money"
115116
if "currency" in self.rawMessage.keys():
116117
currency = self.rawMessage["currency"]
117118
else:
118119
currency = "USD"
119-
self.value = self.state.currency.GetNormalisedValue(currency, float(self.rawMessage["amount"]))
120+
self.value = self.state.currency.GetNormalisedValue(
121+
currency, float(self.rawMessage["amount"]))
120122
elif (self.handlerName == "youtube_account-superchat"):
121123
self.valueType = "money"
122124
if "currency" in self.rawMessage.keys():
123125
currency = self.rawMessage["currency"]
124126
else:
125127
currency = "USD"
126-
self.value = self.state.currency.GetNormalisedValue(currency, float(self.rawMessage["amount"])/1000000)
128+
self.value = self.state.currency.GetNormalisedValue(
129+
currency, float(self.rawMessage["amount"])/1000000)
127130
elif (self.handlerName == "twitch_account-bits"):
128131
self.valueType = "money"
129132
self.value = round(float(self.rawMessage["amount"]) / 100, 2)
@@ -134,7 +137,8 @@ def PopulateNormalisedData(self):
134137
if subValue != None:
135138
self.value = subValue
136139
else:
137-
self.state.RecordActivity(self.state.translations.GetTranslation("StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
140+
self.state.RecordActivity(self.state.translations.GetTranslation(
141+
"StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
138142
return False
139143
elif (self.handlerName == "twitch_account-subMysteryGift"):
140144
self.bestName = self.rawMessage["gifter_display_name"]
@@ -145,7 +149,8 @@ def PopulateNormalisedData(self):
145149
if subValue != None:
146150
self.value = subValue * amount
147151
else:
148-
self.state.RecordActivity(self.state.translations.GetTranslation("StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
152+
self.state.RecordActivity(self.state.translations.GetTranslation(
153+
"StreamlabsEvent UnrecognisedTwitchSubscriptionType") + subPlan)
149154
return False
150155
self.state.mysterySubGifts[self.bestName] = amount
151156
elif (self.handlerName == "youtube_account-subscription"):
@@ -184,6 +189,7 @@ def SubstituteEventDataIntoString(self, string, calcValue="''"):
184189
for instance in instances:
185190
dataKeyName = instance[1:-1]
186191
dataKeyValue = "''"
192+
187193
if dataKeyName == "CALCVALUE":
188194
dataKeyValue = calcValue
189195
elif dataKeyName == "VALUE":
@@ -202,6 +208,7 @@ def SubstituteEventDataIntoString(self, string, calcValue="''"):
202208
dataKeyValue = self.bestComment
203209
elif dataKeyName in self.rawMessage:
204210
dataKeyValue = self.rawMessage[dataKeyName]
211+
205212
string = string.replace(
206213
instance, StreamlabsEventUtils.EspaceStringForRcon(str(dataKeyValue)))
207214
return string
@@ -251,7 +258,8 @@ def IsBadEventAttritubeUsed(eventType, string, calcValueAllowed):
251258
def IsScriptValid(scriptString):
252259
if scriptString in ["", "[ALL]", "[NOTHING]"]:
253260
return ""
254-
instances = StreamlabsEventUtils.FindAttributeTagsInString(scriptString)
261+
instances = StreamlabsEventUtils.FindAttributeTagsInString(
262+
scriptString)
255263
testScriptString = scriptString
256264
for instance in instances:
257265
testScriptString = testScriptString.replace(instance, str(1))
@@ -286,7 +294,8 @@ def GetTwitchSubscriptionValue(subPlan):
286294
@staticmethod
287295
def GenerateEventPerPayload(state, data):
288296
if "message" not in data:
289-
state.RecordActivity(state.translations.GetTranslation("StreamlabsEvent MissingEventPayloadCount"))
297+
state.RecordActivity(state.translations.GetTranslation(
298+
"StreamlabsEvent MissingEventPayloadCount"))
290299
return None
291300
events = []
292301
if "for" in data:
@@ -299,8 +308,10 @@ def GenerateEventPerPayload(state, data):
299308
typeString = ""
300309
# twitch alerts only have a dictionary as message and not an array of dictionaries like all other scenarios
301310
if isinstance(data["message"], dict):
302-
events.append(StreamlabsEvent(state, platformString, typeString, data["message"]))
311+
events.append(StreamlabsEvent(
312+
state, platformString, typeString, data["message"]))
303313
else:
304314
for payload in data["message"]:
305-
events.append(StreamlabsEvent(state, platformString, typeString, payload))
315+
events.append(StreamlabsEvent(
316+
state, platformString, typeString, payload))
306317
return events

Source/TestEvents.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import random as Random
77
import json as Json
88

9+
910
class TestEventUtils:
1011
_types = {
1112
"Streamlabs": {
@@ -74,7 +75,8 @@ class TestEventUtils:
7475

7576
@staticmethod
7677
def GenerateTestEventArray(eventPlatform, eventType, value, special, payloadCount):
77-
primaryEvent = TestEventUtils._GenerateTestEvent(eventPlatform, eventType, value, special, payloadCount)
78+
primaryEvent = TestEventUtils._GenerateTestEvent(
79+
eventPlatform, eventType, value, special, payloadCount)
7880
testEventArray = [primaryEvent]
7981
if eventPlatform == "Twitch" and eventType == "Give Random Gift Subscriptions":
8082
for i in range(special):
@@ -176,7 +178,7 @@ def EventMessageConstructor(value, special, iterator):
176178
'display_name': usernameCamalCase,
177179
'from_display_name': usernameCamalCase,
178180
'message': 'a test subscription',
179-
'sub_plan': str(int(value)),
181+
'sub_plan': TestEventUtils.TwitchSubscriptionSubPlanValueToString(value),
180182
'months': '2',
181183
'streak_months': '2',
182184
'gifter': None
@@ -201,7 +203,7 @@ def EventMessageConstructor(value, special, iterator):
201203
'display_name': recieverUsernameCamalCase,
202204
'from_display_name': recieverUsernameCamalCase,
203205
'message': 'a test subscription',
204-
'sub_plan': str(int(value)),
206+
'sub_plan': TestEventUtils.TwitchSubscriptionSubPlanValueToString(value),
205207
'months': '2',
206208
'streak_months': '2',
207209
'gifter': gifterUsernameLowerCase
@@ -217,7 +219,7 @@ def EventMessageConstructor(value, special, iterator):
217219
usernameLowerCase = 'user' + str(iterator)
218220
messageEventId = TestEventUtils.GenerateUuidNoHyphens()
219221
return {
220-
'sub_plan': str(int(value)),
222+
'sub_plan': str(value),
221223
'sub_type': 'submysterygift',
222224
'gifter': usernameLowerCase,
223225
'gifter_display_name': usernameCamalCase,
@@ -295,10 +297,12 @@ def _ConstructTestEventDict(forString, typeString, messageConstructor, value, sp
295297
eventDict["message"] = []
296298
for i in range(payloadCount):
297299
messageEntry = messageConstructor(value, special, i)
298-
eventDict["message"].append(TestEventUtils._MakeTestEventMessageEntry(messageEntry, forString, typeString, eventOptions))
300+
eventDict["message"].append(TestEventUtils._MakeTestEventMessageEntry(
301+
messageEntry, forString, typeString, eventOptions))
299302
else:
300303
messageEntry = messageConstructor(value, special, 1)
301-
eventDict["message"] = TestEventUtils._MakeTestEventMessageEntry(messageEntry, forString, typeString, eventOptions)
304+
eventDict["message"] = TestEventUtils._MakeTestEventMessageEntry(
305+
messageEntry, forString, typeString, eventOptions)
302306
return eventDict
303307

304308
@staticmethod
@@ -307,7 +311,8 @@ def _MakeTestEventMessageEntry(messageEntry, forString, typeString, eventOptions
307311
return messageEntry
308312

309313
nowDateTime = DateTime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
310-
pastDateTime = (DateTime.datetime.now() - DateTime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
314+
pastDateTime = (DateTime.datetime.now() -
315+
DateTime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
311316

312317
messageEntry["type"] = typeString
313318
messageEntry["platform"] = forString
@@ -327,7 +332,7 @@ def _MakeTestEventMessageEntry(messageEntry, forString, typeString, eventOptions
327332
messageEntry["uuid"] = TestEventUtils.GenerateUuid()
328333
messageEntry["read"] = False
329334
messageEntry["createdAt"] = str(nowDateTime)
330-
messageEntry["repeat"]= True
335+
messageEntry["repeat"] = True
331336
messageEntry["_id"] = TestEventUtils.GenerateRandomAlphaDigits(13)
332337
messageEntry["priority"] = 10
333338

@@ -337,6 +342,7 @@ def _MakeTestEventMessageEntry(messageEntry, forString, typeString, eventOptions
337342
def GetAttribute(platformString, typeString, attributeName):
338343
return TestEventUtils._types[platformString][typeString][attributeName]
339344

345+
@staticmethod
340346
def DoesAttributeExist(platformString, typeString, attributeName):
341347
if attributeName in TestEventUtils._types[platformString][typeString].keys():
342348
return True
@@ -374,7 +380,16 @@ def GenerateRandomDigits(count):
374380
def GenerateRandomAlphaDigits(count):
375381
return ''.join(Random.choices(String.ascii_uppercase + String.digits, k=count))
376382

383+
# Have to use as the values all come as string in JSON from streamlabs, but we auto convert anything number to a number. So the test event data needs to match this int/string data type.
384+
@staticmethod
385+
def TwitchSubscriptionSubPlanValueToString(value):
386+
if value == "Prime":
387+
return value
388+
else:
389+
return str(int(value))
390+
391+
377392
class TestEventOptions:
378393
def __init__(self):
379394
self.globalEventId = True
380-
self.eventDefaultAttributes = True
395+
self.eventDefaultAttributes = True

Source/Translations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def LoadLocalisedTexts(self, language):
3939
"TestEvent ValueNotFloat": "Test Event Value isn't a number: ",
4040
"TestEvent PayloadCountNotInt": "Test Event Payload Count not a positive whole number: ",
4141
"TestEvent QuantityCountNotInt": "Test Event Quantity Count not a positive whole number: ",
42+
"TestEvent ValueNotFloatOrPrime": "Test Event Value isn't a number or \"Prime\": "
4243
}
4344

4445
def GetTranslation(self, key):

Source/eventDefinitions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
"description": "the text message with the subscription"
9090
},
9191
"sub_plan": {
92-
"valueType": "number",
93-
"description": "the number twitch uses to identify each sub tier: Prime, 1000, 2000, 3000"
92+
"valueType": "number or text string",
93+
"description": "the number twitch uses to identify each sub tier. If a Prime subscription then a text string of 'Prime'. If a paid for subscription then for level 1, 2 or 3 its the corrisponding numbers: 1000, 2000 or 3000. This sub_plan is an oddity as the other Twitch Subscription types don;t support a sub_plan of 'Prime'."
9494
}
9595
},
9696
"twitch_account-subscriptionGift": {

0 commit comments

Comments
 (0)