44
55
66class StreamlabsEvent ():
7- handledEventTypes = {}
8-
97 def __init__ (self , state , data ):
108 self .state = state
119 self .logging = state .logging
@@ -62,7 +60,7 @@ def __init__(self, state, data):
6260 self .platform = "streamlabs"
6361 elif self .platform == "twitch_account" and self .type == "subscription" and "gifter" in self .rawMessage and self .rawMessage ["gifter" ] != None :
6462 self .type = "subscription_gift"
65- self .handlerName = self .MakeHandlerString (
63+ self .handlerName = StreamlabsEventUtils .MakeHandlerString (
6664 self .platform , self .type )
6765
6866 @property
@@ -96,15 +94,11 @@ def __str__(self):
9694 return '' .join (str_list )
9795
9896 def IsHandledEvent (self ):
99- if self .handlerName in self .handledEventTypes .keys ():
97+ if self .handlerName in StreamlabsEventUtils .handledEventTypes .keys ():
10098 return True
10199 else :
102100 return False
103101
104- @staticmethod
105- def MakeHandlerString (platform , type ):
106- return platform + "-" + type
107-
108102 def ShouldIgnoreEvent (self ):
109103 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" ):
110104 return True
@@ -174,7 +168,7 @@ def GetEventRawTitlesAsPrettyString(self):
174168 return eventDesc
175169
176170 def SubstituteEventDataIntoString (self , string , modValue = "''" ):
177- instances = StreamlabsEvent .FindAttributeTagsInString (string )
171+ instances = StreamlabsEventUtils .FindAttributeTagsInString (string )
178172 for instance in instances :
179173 dataKeyName = instance [1 :- 1 ]
180174 dataKeyValue = "''"
@@ -197,9 +191,24 @@ def SubstituteEventDataIntoString(self, string, modValue="''"):
197191 elif dataKeyName in self .rawMessage :
198192 dataKeyValue = self .rawMessage [dataKeyName ]
199193 string = string .replace (
200- instance , StreamlabsEvent .EspaceStringForRcon (str (dataKeyValue )))
194+ instance , StreamlabsEventUtils .EspaceStringForRcon (str (dataKeyValue )))
201195 return string
202196
197+
198+ class StreamlabsEventUtils ():
199+ handledEventTypes = {}
200+
201+ @staticmethod
202+ def MakeHandlerString (platform , type ):
203+ return platform + "-" + type
204+
205+ @staticmethod
206+ def EspaceStringForRcon (text ):
207+ text = text .replace ("\\ " , "\\ \\ " )
208+ text = text .replace ("'" , "\\ '" )
209+ text = text .replace ('"' , '\\ "' )
210+ return text
211+
203212 @staticmethod
204213 def FindAttributeTagsInString (string ):
205214 return Regex .findall (r"\[[a-z_A-Z0-9]+\]" , string )
@@ -209,28 +218,29 @@ def LoadEventDefinitions():
209218 with open ("eventDefinitions.json" , "r" ) as file :
210219 data = Json .load (file )
211220 file .closed
212- StreamlabsEvent .handledEventTypes = data
221+ StreamlabsEventUtils .handledEventTypes = data
213222
214223 @staticmethod
215224 def IsBadEventAttritubeUsed (eventType , string , modValueAllowed ):
216225 if string in ["" , "[ALL]" , "[NOTHING]" ]:
217226 return ""
218- instances = StreamlabsEvent .FindAttributeTagsInString (string )
227+ instances = StreamlabsEventUtils .FindAttributeTagsInString (string )
219228 for instance in instances :
220229 dataKeyName = instance [1 :- 1 ]
221230 if dataKeyName == "MODVALUE" and not modValueAllowed :
222231 return "[MODVALUE] used when not allowed"
223- if dataKeyName in StreamlabsEvent .handledEventTypes ['[ALL]' ].keys ():
232+ if dataKeyName in StreamlabsEventUtils .handledEventTypes ['[ALL]' ].keys ():
224233 continue
225- if eventType == "" or dataKeyName not in StreamlabsEvent .handledEventTypes [eventType ].keys ():
234+ if eventType == "" or dataKeyName not in StreamlabsEventUtils .handledEventTypes [eventType ].keys ():
226235 return instance + " not a valid attribute for this event"
227236 return ""
228237
229238 @staticmethod
230239 def IsScriptValid (scriptString ):
231240 if scriptString in ["" , "[ALL]" , "[NOTHING]" ]:
232241 return ""
233- instances = StreamlabsEvent .FindAttributeTagsInString (scriptString )
242+ instances = StreamlabsEventUtils .FindAttributeTagsInString (
243+ scriptString )
234244 testScriptString = scriptString
235245 for instance in instances :
236246 testScriptString = testScriptString .replace (instance , str (1 ))
@@ -239,10 +249,3 @@ def IsScriptValid(scriptString):
239249 except Exception :
240250 return "config value: " + scriptString + "\n " + Traceback .format_exc (limit = 0 , chain = False )
241251 return ""
242-
243- @staticmethod
244- def EspaceStringForRcon (text ):
245- text = text .replace ("\\ " , "\\ \\ " )
246- text = text .replace ("'" , "\\ '" )
247- text = text .replace ('"' , '\\ "' )
248- return text
0 commit comments