This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
87 lines (84 loc) · 3.16 KB
/
setup.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
import os
import json
import configparser
import asyncio
import websockets
import func
from func import *
import webbrowser
async def setup(websocket):
if os.path.exists('token.json'):
print('Loading authtoken From File...')
with open('token.json', "r") as json_file:
data = json.load(json_file)
authtoken = (data['authenticationkey'])
confirm = await authen(websocket,authtoken)
if authtoken == "" or confirm["data"]["authenticated"] == False:
print('Error Token Invalid')
print('Fetching New Tokens...')
authtoken = await token(websocket)
print(authtoken)
print('Saving authtoken for Future Use...')
data["authenticationkey"] = authtoken
json_file.close()
json_file = open('token.json', "w")
json_file.write(json.dumps(data))
json_file.close()
print("Saving finished")
else:
json_file.close()
else:
print('Fetching New Tokens...')
authtoken = await token(websocket)
print(authtoken)
print('Saving authtoken for Future Use...')
with open('token.json', "w") as json_file:
jsonfilecon = {
"chatspeed": 0.1,
"authenticationkey": authtoken,
"authenticationkeytwitch": ""
}
json_file.write(json.dumps(jsonfilecon))
json_file.close()
await authen(websocket,authtoken)
if os.path.exists('commands.ini'):
config = configparser.ConfigParser()
commandlist = config.read('commands.ini')
else:
config = configparser.ConfigParser()
with open('commands.ini', "w") as configfile:
config['COMMANDS'] = {
"!spin": "spin(websocket,x,y,s)",
"!reset": "mdmv(websocket,0.2,False,0,0,0,-76)",
"!rainbow": "rainbow(websocket)"
}
config.write(configfile)
with open('token.json') as json_file:
data = json.load(json_file)
json_file.close()
###############################
# command auto generation #
###############################
mdls = await listvtsmodel(websocket)
runs = mdls["data"]["numberOfModels"]
i=0
for key in config['COMMANDS']:
i+=1
nmumm = runs - i
if i < nmumm:
with open('commands.ini', "w") as configfile:
for i in range(runs):
ff = mdls["data"]["availableModels"][i]["modelName"]
gg = mdls["data"]["availableModels"][i]["modelID"]
name = "!"+ff
mdss = mdch.__name__+"("+"websocket"+",'"+str(gg)+"')"
config['COMMANDS'][name] = mdss
config.write(configfile)
###############################
# command auto generation end #
###############################
print("Successfully Loaded")
print("Detected Commands")
for key in config['COMMANDS']:
print(key)
return config