-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMWO_SyncDrop_StreamlabsSystem.py
executable file
·220 lines (181 loc) · 6.23 KB
/
MWO_SyncDrop_StreamlabsSystem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#---------------------------------------
# Import Libraries
#---------------------------------------
import sys
import os
import codecs
import clr
import time
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
#---------------------------------------
# Script Information
#---------------------------------------
ScriptName = "Sync-Drop Countdown Script"
Website = "https://www.dimensionv.de"
Description = "Initiates a countdown on chat for sync-dropping, using the !syncdrop command"
Creator = "Karubian"
Version = "1.3.1"
#---------------------------------------
# Set Variables
#---------------------------------------
command = "!syncdrop"
HELP = "help?"
commandPermission = "caster"
commandInfo = "Initiates a sync-drop countdown for MWO"
launchText = "CLICK!"
countDownTime = 5
useNA = True
useEU = True
useOC = True
useSubMode = True
effectiveLaunchText = launchText
effectiveTime = countDownTime
effectiveUseNA = useNA
effectiveUseEU = useEU
effectiveUseOC = useOC
coolDownTime = countDownTime * 10
useBoth = True
isFromTwitch = True
isFromDiscord = True
showHelpAndQuit = False
#---------------------------------------
# Intialize Data (Only called on Load)
#---------------------------------------
def Init():
loadSettingsFile(__file__, filename='settings.json')
return
#---------------------------------------
# Execute Data / Process Messages
#---------------------------------------
def Execute(data):
global isFromTwitch
global isFromDiscord
if (data.IsChatMessage()):
if (checkPermissionToRun(data)):
if(not useBoth):
isFromTwitch = data.IsFromTwitch()
isFromDiscord = data.IsFromDiscord()
else:
isFromTwitch = useBoth
isFromDiscord = useBoth
parseParameters(data)
if(showHelpAndQuit):
showHelp()
else:
runCountDown(effectiveTime, effectiveUseEU, effectiveUseNA, effectiveUseOC)
return
#---------------------------------------
# [Required] Tick Function
#---------------------------------------
def Tick():
return
#---------------------------------------
# Load the settings from JSON
#---------------------------------------
def ReloadSettings(jsonData):
global launchText
global useSubMode
global useBoth
global countDownTime
global useNA
global useEU
global useOC
global coolDownTime
Parent.Log(ScriptName, "Reloading settings")
parsedData = json.loads(jsonData)
if("launchText" in parsedData):
launchText = parsedData["launchText"]
if("useSubMode" in parsedData):
useSubMode = parsedData["useSubMode"]
if("useBoth" in parsedData):
useBoth = parsedData["useBoth"]
if("countDownTime" in parsedData):
countDownTime = int(parsedData["countDownTime"])
if("useNA" in parsedData):
useNA = parsedData["useNA"]
if("useEU" in parsedData):
useEU = parsedData["useEU"]
if("useOC" in parsedData):
useOC = parsedData["useOC"]
coolDownTime = countDownTime * 10
Parent.Log(ScriptName, "Reloading finished")
return
def parseParameters(data):
global effectiveTime
global effectiveUseNA
global effectiveUseEU
global effectiveUseOC
global showHelpAndQuit
paramCount = data.GetParamCount()
if(paramCount < 2):
effectiveTime = countDownTime
effectiveUseNA = useNA
effectiveUseEU = useEU
effectiveUseOC = useOC
elif(paramCount == 2):
if(data.GetParam(1) in HELP):
showHelpAndQuit = True
return
effectiveTime = int(data.GetParam(1))
effectiveUseNA = useNA
effectiveUseEU = useEU
effectiveUseOC = useOC
elif(paramCount == 3):
effectiveTime = int(data.GetParam(1))
useRegions = data.GetParam(2)
effectiveUseNA = "NA" in useRegions
effectiveUseEU = "EU" in useRegions
effectiveUseOC = "OC" in useRegions
return
def checkPermissionToRun(data):
result = data.GetParam(0).lower() == command
result = result and not Parent.IsOnCooldown(ScriptName, command)
result = result and Parent.HasPermission(data.User, commandPermission, commandInfo)
return result
def runCountDown(count, includeEU, includeNA, includeOC):
if(useSubMode and isFromTwitch):
Parent.SendTwitchMessage("/subscribers")
sendMessage("Initiating sync-drop with the following regions included:")
includedRegions = ""
if(includeNA):
includedRegions = addRegion("North America", includedRegions)
if(includeEU):
includedRegions = addRegion("Europe", includedRegions)
if(includeOC):
includedRegions = addRegion("Oceanic", includedRegions)
sendMessage(includedRegions)
sendMessage("Sync drop starts in:")
for step in range(count, 0, -1):
sendMessage(" %d" % (step))
time.sleep(1.0)
sendMessage(launchText)
if(useSubMode and isFromTwitch):
Parent.SendTwitchMessage("/subscribersoff")
return
def addRegion(region, regions):
if(regions != "" ):
regions += ", "
regions += region
return regions
def showHelp():
sendMessage("!syncdrop [<countDownTime>|<countDownTime> <regions>]")
sendMessage("countDownTime: time for the countdown in seconds")
sendMessage("regions: selected regions. Can be any combination of EU, NA or OC")
sendMessage(" Use the following syntax: EU, EU|NA or EU|NA|OC in any combination/order.")
return
def sendMessage(message):
if(isFromTwitch):
Parent.SendTwitchMessage(message)
if(isFromDiscord):
Parent.SendDiscordMessage(message)
Parent.Log(ScriptName, message)
return
def loadSettingsFile(base, filename):
try:
with codecs.open(os.path.join(os.path.dirname(base), filename), encoding='utf-8-sig') as jsonData:
ReloadSettings(jsonData.read())
return
except Exception as e:
Parent.Log(ScriptName, "Error loading %s: %s" % (filename, str(e)))
return