11import os
22import json
3+ import configparser
34
45import asyncio
56import websockets
@@ -34,69 +35,60 @@ async def setup(websocket):
3435 json_file .write (json .dumps (data ))
3536 json_file .close ()
3637 print ("Saving finished" )
37- elif (data ['authenticationkeytwitch' ] == "" ):
38- print ('Error With Twitch Token' )
39- print ('Fetching New Tokens...' )
40- print ("click authorize, copy the token from access_token=, till the & seperator" )
41- webbrowser .open (link )
42- twauthtoken = input ()
43- data ["authenticationkeytwitch" ] = twauthtoken
44- json_file .close ()
45- json_file = open ('token.json' , "w" )
46- json_file .write (json .dumps (data ))
47- json_file .close ()
4838 else :
4939 json_file .close ()
5040 else :
5141 print ('Fetching New Tokens...' )
5242 authtoken = await token (websocket )
5343 print (authtoken )
5444 print ('Saving authtoken for Future Use...' )
55- print ("click authorize, copy the token from access_token=, till the & seperator" )
56- webbrowser .open (link )
57- twauthtoken = input ()
5845 with open ('token.json' , "w" ) as json_file :
5946 jsonfilecon = {
6047 "chatspeed" : 0.1 ,
6148 "authenticationkey" : authtoken ,
62- "authenticationkeytwitch" : twauthtoken ,
63- "data" :{
64- "!spin" : "spin(vtubestudio,x,y,s)" ,
65- "!reset" : "mdmv(vtubestudio,0.2,False,0,0,0,-76)" ,
66- "!rainbow" : "rainbow(vtubestudio)" }
49+ "authenticationkeytwitch" : ""
6750 }
6851 json_file .write (json .dumps (jsonfilecon ))
6952 json_file .close ()
7053 await authen (websocket ,authtoken )
71-
54+ if os .path .exists ('commands.ini' ):
55+ config = configparser .ConfigParser ()
56+ cmm = config .read ('commands.ini' )
57+ else :
58+ config = configparser .ConfigParser ()
59+ with open ('commands.ini' , "w" ) as configfile :
60+ config ['COMMANDS' ] = {
61+ "!spin" : "spin(websocket,x,y,s)" ,
62+ "!reset" : "mdmv(websocket,0.2,False,0,0,0,-76)" ,
63+ "!rainbow" : "rainbow(websocket)"
64+ }
65+ config .write (configfile )
7266 data = json .load (open ('token.json' ))
73-
67+ json_file . close ()
7468 ###############################
7569 # command auto generation #
7670 ###############################
7771 mdls = await listvtsmodel (websocket )
7872 runs = mdls ["data" ]["numberOfModels" ]
7973 i = 0
80- for key in data [ "data" ]:
74+ for key in config [ 'COMMANDS' ]:
8175 i += 1
8276 nmumm = runs - i
8377 if i < nmumm :
84- for i in range (runs ):
85- ff = mdls ["data" ]["availableModels" ][i ]["modelName" ]
86- gg = mdls ["data" ]["availableModels" ][i ]["modelID" ]
87- name = "!" + ff
88- mdss = mdch .__name__ + "(" + "vtubestudio" + ",'" + str (gg )+ "')"
89- data ["data" ][name ] = mdss
90- json_file .close ()
91- json_file = open ('token.json' , "w" )
92- json_file .write (json .dumps (data ))
93- json_file .close ()
78+ with open ('commands.ini' , "w" ) as configfile :
79+ for i in range (runs ):
80+ ff = mdls ["data" ]["availableModels" ][i ]["modelName" ]
81+ gg = mdls ["data" ]["availableModels" ][i ]["modelID" ]
82+ name = "!" + ff
83+ mdss = mdch .__name__ + "(" + "websocket" + ",'" + str (gg )+ "')"
84+ config ['COMMANDS' ][name ] = mdss
85+ config .write (configfile )
9486 ###############################
9587 # command auto generation end #
9688 ###############################
9789 print ("Successfully Loaded" )
9890 print ("Detected Commands" )
99- for key in data [ "data" ]:
91+ for key in config [ 'COMMANDS' ]:
10092 print (key )
10193 print ("type your streamid and press enter" )
10294 op = input ("do you want to use [1]Youtube chat, [2]Twitch chat " )
@@ -105,6 +97,16 @@ async def setup(websocket):
10597 op = input ("input streamid " )
10698 chat = LiveChat (video_id = op )
10799 elif (op == "2" ):
100+ if (data ['authenticationkeytwitch' ] == '' ):
101+ print ("click authorize, copy the token from access_token=, till the & seperator" )
102+ webbrowser .open (link )
103+ twauthtoken = input ()
104+ with open ('token.json' , "w" ) as json_file :
105+ data ["authenticationkeytwitch" ] = twauthtoken
106+ json_file .write (json .dumps (data ))
107+ json_file .close ()
108+ data = json .load (open ('token.json' ))
109+ json_file .close ()
108110 ttv = True
109111 chnm = input ("input channel name " )
110- return [yt ,ttv ,data ,chat ,chnm ]
112+ return [yt ,ttv ,data ,chat ,chnm , config ]
0 commit comments