-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAHKParameters_StreamlabsSystem.py
187 lines (128 loc) · 5.04 KB
/
AHKParameters_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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#---------------------------
# Import Libraries
#---------------------------
import sys
import json
import codecs
import os
import clr
clr.AddReference("IronPython.SQLite.dll")
clr.AddReference("IronPython.Modules.dll")
#---------------------------
# [Required] Script Information
#---------------------------
ScriptName = "AHKParameters"
Website = "https://github.com/CrashKoeck/AHKParameters"
Description = "Run AutoHotkey scripts with or without parameters"
Creator = "CrashKoeck"
Version = "1.0.2"
#---------------------------
# Define Global Variables
#---------------------------
script_path = os.path.join(os.path.dirname(__file__), "AHKPScripts")
ReadMeFile = os.path.join(os.path.dirname(__file__), "ReadMe.txt")
SettingsFile = os.path.join(os.path.dirname(__file__), "settings.json")
#---------------------------
# [Required] Initialize Data (Only called on load)
#---------------------------
def Init():
global ScriptSettings
ScriptSettings = Settings(SettingsFile)
return
#---------------------------
# [Required] Execute Data / Process messages
#---------------------------
def Execute(data):
return
#---------------------------
# [Required] Tick method (Gets called during every iteration even when there is no incoming data)
#---------------------------
def Tick():
return
#---------------------------
# [Optional] Parse method (Allows you to create your own custom $parameters)
#---------------------------
def Parse(parseString, userid, username, targetid, targetname, message):
if "$AHKP" in parseString:
start = '$AHKP('
end = ')'
guts = (parseString.split(start))[1].split(end)[0]
if "," in guts:
script = guts.split(",", 1)
args = guts.split(",")
args.pop(0)
RunAHKP(script[0],args)
else:
RunAHKP(guts,"")
ahkp = "$AHKP({})".format(guts)
return parseString.replace(ahkp,"")
return parseString
#---------------------------
# [Optional] Reload Settings (Called when a user clicks the Save Settings button in the Chatbot UI)
#---------------------------
def ReloadSettings(jsondata):
# Reload newly saved settings and verify
ScriptSettings.Reload(jsondata)
# End of ReloadSettings
return
#---------------------------
# [Optional] Unload (Called when a user reloads their scripts or closes the bot / cleanup stuff)
#---------------------------
def Unload():
return
#---------------------------
# Script Classes
#---------------------------
class Settings(object):
""" Load in saved settings file if available else set default values. """
def __init__(self, settingsfile=None):
try:
with codecs.open(settingsfile, encoding="utf-8-sig", mode="r") as f:
self.__dict__ = json.load(f, encoding="utf-8")
except:
self.AHKPPath = "C:\Program Files\AutoHotkey"
def Reload(self, jsondata):
""" Reload settings from Streamlabs user interface by given json data. """
self.__dict__ = json.loads(jsondata, encoding="utf-8")
def Save(self, settingsfile):
""" Save settings contained within to .json and .js settings files. """
try:
with codecs.open(settingsfile, encoding="utf-8-sig", mode="w+") as f:
json.dump(self.__dict__, f, encoding="utf-8", ensure_ascii=False)
with codecs.open(settingsfile.replace("json", "js"), encoding="utf-8-sig", mode="w+") as f:
f.write("var settings = {0};".format(json.dumps(self.__dict__, encoding='utf-8', ensure_ascii=False)))
except:
Parent.Log(ScriptName, "Failed to save settings to file.")
#---------------------------
# Custom Functions
#---------------------------
def RunAHKP(script,params):
AHKPScript = os.path.join(script_path, "{}.ahk").format(script)
if not params:
os.startfile(AHKPScript)
else:
AHKPexe = os.path.join(ScriptSettings.AHKPPath, "{}.exe").format("AutoHotkey")
params.insert(0,AHKPScript)
params.insert(0,script)
os.spawnv(os.P_NOWAIT, AHKPexe, params)
return
#---------------------------
# Script UI Button Functions
#---------------------------
def OpenReadMe():
""" Open the script readme file on GitHub in the user's default browser. """
os.system("start \"\" https://github.com/CrashKoeck/AHKParameters/blob/master/README.md")
return
def OpenAHKPScripts():
"""Open AHKPScripts folder"""
os.startfile(os.path.join(os.path.dirname(__file__), "AHKPScripts"))
def VisitWebiste():
""" Open Crash's website in user's default browser. """
os.system("start \"\" https://www.CrashKoeck.com")
return
def JoinDiscord():
""" Open Discord invite link in user's default browser. """
os.system("start \"\" https://discord.gg/zyS2jbJ")
return