Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

Commit 75ef6de

Browse files
author
emlo40
committed
added seperat file for commands(lets you use all functions unlike old method)
1 parent 5b53ea0 commit 75ef6de

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

setup.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
import configparser
34

45
import asyncio
56
import 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]

vsyt.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313

1414
async def main():
1515
try:
16-
vtubestudio = await websockets.connect('ws://127.0.0.1:8001')
16+
websocket = await websockets.connect('ws://127.0.0.1:8001')
1717
except:
1818
print("Couldn't connect to vtube studio")
1919
input("press enter to quit program")
2020
quit()
2121
twitch = await websockets.connect('ws://irc-ws.chat.twitch.tv:80')
22-
setu = await setup(vtubestudio)
22+
setu = await setup(websocket)
2323
chat = setu[3]
2424
data = setu[2]
25+
cmm = setu[5]
2526
channel = setu[4]
2627
if (setu[0] == True):
2728
while True:
@@ -31,7 +32,7 @@ async def main():
3132
p = [f"{c.datetime}", f"{c.author.name}", f"{c.message}"]
3233
print(p)
3334
if p[2] == key:
34-
mdinf = await getmd(vtubestudio)
35+
mdinf = await getmd(websocket)
3536
s = mdinf["data"]["modelPosition"]["size"]
3637
r = mdinf["data"]["modelPosition"]["rotation"]
3738
x = mdinf["data"]["modelPosition"]["positionX"]
@@ -50,18 +51,18 @@ async def main():
5051
print(res)
5152
while True:
5253
res = await twitch.recv()#getting twitch chat is soo fucking easy
53-
for key in data["data"]:
54-
message_list = res.split(':')#thanks to elburz article:https://interactiveimmersive.io/blog/content-inputs/twitch-chat-in-touchdesigner/
55-
user_message = message_list[-1]
56-
user_name = message_list[1].split('!')[0]
57-
58-
print(user_message,user_message[0:len(user_message)-2])
54+
message_list = res.split(':')#thanks to elburz article:https://interactiveimmersive.io/blog/content-inputs/twitch-chat-in-touchdesigner/
55+
user_message = message_list[-1]
56+
user_name = message_list[1].split('!')[0]
57+
print(user_message,user_message[0:len(user_message)-2])
58+
for key in cmm['COMMANDS']:
5959
if user_message[0:len(user_message)-2] == key:
60-
mdinf = await getmd(vtubestudio)
60+
print('executing')
61+
mdinf = await getmd(websocket)
6162
s = mdinf["data"]["modelPosition"]["size"]
6263
r = mdinf["data"]["modelPosition"]["rotation"]
6364
x = mdinf["data"]["modelPosition"]["positionX"]
6465
y = mdinf["data"]["modelPosition"]["positionY"]
65-
cm = data["data"][key]
66+
cm = cmm['COMMANDS'][key]
6667
await eval(cm)
6768
asyncio.run(main())

0 commit comments

Comments
 (0)