99from Rcon import Rcon
1010from Translations import Translations
1111from TestEvents import TestEventUtils
12+ import random as Random
13+ import time as Time
14+ import threading as Threading
1215
1316
1417class State ():
1518 def __init__ (self ):
16- self .version = "0.1.0 "
19+ self .version = "0.1.1 "
1720 self .config = Config (self )
1821 self .logging = Logging (self )
1922 self .config .LogMissingSettings ()
@@ -110,6 +113,11 @@ def RecordActivity(self, text):
110113
111114 def OnStreamlabsEventHandler (self , data ):
112115 try :
116+ random = Random .Random ()
117+ random .seed (Threading .get_ident ())
118+ sleepTime = random .random ()
119+ self .logging .DebugLog ("Sleeping event for: " + str (sleepTime ))
120+ Time .sleep (sleepTime )
113121 self .logging .DebugLog (
114122 "Streamlabs raw event data: " + str (data ))
115123 events = StreamlabsEventUtils .GenerateEventPerPayload (self , data )
@@ -135,37 +143,39 @@ def OnStreamlabsEventHandler(self, data):
135143 self .logging .DebugLog (
136144 "Streamlabs processed event: " + str (event ))
137145
138- actionText = self .profiles .currentProfile .GetActionTextForEvent (
146+ actionTexts = self .profiles .currentProfile .GetActionTextsForEvent (
139147 event )
140- if actionText == None :
148+ if len ( actionTexts ) == 0 :
141149 self .RecordActivity (
142150 self .translations .GetTranslation ("StreamlabsEvent NoProfileAction" ) + event .GetEventRawTitlesAsPrettyString ())
143151 self .logging .DebugLog (
144152 "No profile action for: " + event .GetEventRawTitlesAsPrettyString ())
145153 return
146- actionType = ""
147- response = ""
148- if actionText == "" :
149- actionType = "Ignore event"
150- self .logging .DebugLog (
151- "NOTHING action specified for: " + event .GetEventRawTitlesAsPrettyString ())
152- else :
153- actionType = "Rcon command"
154- try :
154+ for actionText in actionTexts :
155+ actionType = ""
156+ response = ""
157+ if actionText == "" :
158+ actionType = "Ignore event"
155159 self .logging .DebugLog (
156- "Doing Rcon command: " + actionText )
157- response = self .rcon .SendCommand (actionText )
158- except Exception as ex :
159- self .logging .RecordException (ex , "Rcon event failed" )
160+ "NOTHING action specified for: " + event .GetEventRawTitlesAsPrettyString ())
161+ else :
162+ actionType = "Rcon command"
163+ try :
164+ self .logging .DebugLog (
165+ "Doing Rcon command: " + actionText )
166+ response = self .rcon .SendCommand (actionText )
167+ except Exception as ex :
168+ self .logging .RecordException (
169+ ex , "Rcon event failed" )
170+ self .RecordActivity (
171+ self .translations .GetTranslation ("Rcon CommandError" ) + actionText )
172+ return
173+ if response != "" :
160174 self .RecordActivity (
161- self .translations .GetTranslation ("Rcon CommandError " ) + actionText )
162- return
175+ self .translations .GetTranslation ("Rcon CommandResponseWarning " ) + response )
176+ self . logging . DebugLog ( "Action done: " + actionText )
163177 self .RecordActivity (
164178 self .translations .GetTranslation ("StreamlabsEvent EventHandled" ) + event .GetEventRawTitlesAsPrettyString () + " : " + event .bestName + " : value " + str (event .value ) + " : " + actionType )
165- if response != "" :
166- self .RecordActivity (
167- self .translations .GetTranslation ("Rcon CommandResponseWarning" ) + response )
168- self .logging .DebugLog ("Action done: " + actionText )
169179 except Exception as ex :
170180 self .logging .RecordException (
171181 ex , "OBS Event Handler Critical Error - This event won't be processed" )
@@ -194,15 +204,17 @@ def OnTestEventButtonHandler(self):
194204 self .RecordActivity (
195205 self .translations .GetTranslation ("TestEvent QuantityCountNotInt" ) + str (testEventQuantity ))
196206 return
197- testEventPayloadCount = self .gui .testEventPayloadCount .get ()
198- try :
199- testEventPayloadCount = int (testEventPayloadCount )
200- if testEventPayloadCount <= 0 :
201- raise ValueError ()
202- except :
203- self .RecordActivity (
204- self .translations .GetTranslation ("TestEvent PayloadCountNotInt" ) + str (testEventPayloadCount ))
205- return
207+ testEventPayloadCount = 1
208+ if TestEventUtils .GetAttribute (testEventPlatform , testEventType , "payloadInput" ):
209+ try :
210+ testEventPayloadCount = self .gui .testEventPayloadCount .get ()
211+ testEventPayloadCount = int (testEventPayloadCount )
212+ if testEventPayloadCount <= 0 :
213+ raise ValueError ()
214+ except :
215+ self .RecordActivity (
216+ self .translations .GetTranslation ("TestEvent PayloadCountNotInt" ) + str (testEventPayloadCount ))
217+ return
206218 testEventArray = self .testEventUtils .GenerateTestEventArray (
207219 testEventPlatform , testEventType , testEventValue , testEventQuantity , testEventPayloadCount )
208220 if len (testEventArray ) > 0 :
@@ -241,7 +253,7 @@ def Run(self):
241253 except :
242254 pass
243255 try :
244- state .logging .RecordException (
256+ self .logging .RecordException (
245257 ex , "Application Critical Error - Application has been stopped" )
246258 except :
247259 pass
0 commit comments