This repository was archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart.py
120 lines (107 loc) · 4.02 KB
/
start.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
from pypresence import Presence
import time
import os
import platform
import json
import subprocess
if platform.system() == "Windows": import win32com.client
CLIENT_IDS = [
"691885764124082186",
"691919061336195114",
"691925175049912380",
"691920993438007347",
"691892857149063200"
]
CUSTOM_NAMES = [
"nintendo-switch",
"nintendo-3ds",
"ps3",
"ps4",
"others"
]
CONSOLE_NAMES = [
"Nintendo Switch",
"Nintendo 3DS",
"Play Station 3",
"Play Station 4"
]
def send_ping():
arg = "-n" if platform.system() == "Windows" else "-c"
arg2 = "-W" if platform.system() == "Darwin" else "-w"
command = ["ping", arg2, "3", arg, "1", consoles["ip"]]
return subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
config = {}
if os.path.dirname(os.path.abspath(__file__)) == f"C:\\Users\\{os.getlogin()}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup":
sh_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "GameConsoleActivitytoDiscord.lnk")
wshell = win32com.client.Dispatch("WScript.Shell") # <COMObject WScript.Shell>
shortcut = wshell.CreateShortcut(sh_path)
dir_path = os.path.dirname(shortcut.TargetPath)
else:
dir_path = os.path.dirname(os.path.abspath(__file__))
try:
with open(os.path.join(dir_path,"config.json"), "r") as f:
config = json.load(f)
except:
input("First you have to run config.py(config.exe) to config.\nPress enter to exit...")
exit()
if not os.path.exists(os.path.join(dir_path,"./lang/lang.txt")):
input("Can't find lang.txt file. You have to run config.py(config.exe) to config.\nPress enter to exit...")
exit()
else:
with open(os.path.join(dir_path,"./lang/lang.txt"), "r", encoding="utf-8") as f:
lang = f.read()
message = {}
with open(os.path.join(dir_path,f'./lang/{lang}.json'), "r", encoding="utf-8") as f:
message = json.load(f)
print(message["start"])
while True:
for consoles in config:
client_id = CLIENT_IDS[consoles["console"]]
custom = CUSTOM_NAMES[consoles["console"]]
ping = send_ping()
time.sleep(1)
return_node = ping.wait()
if return_node == 0:
disConnected = False
connected = False
dscCnt = 0
while not disConnected:
# print("ping returned {0}".format(return_code))
# print(ping.stdout.read().decode("cp932"))
if return_node == 0:
if dscCnt != 0:
print(message["connected"])
dscCnt = 0
if consoles["console"] == 4:
cname = consoles["custom"]
else:
cname = CONSOLE_NAMES[consoles["console"]]
if not connected:
print(message["turned_on"].format(cname, consoles["ip"]))
RPC = Presence(client_id)
RPC.connect() # Start the handshake loop
print("Connected")
if 0 <= consoles["console"] <= 3:
# Set the presence)
RPC.update(start=time.time(), large_image=custom, large_text=cname)
else:
# Set the presence)
RPC.update(start=time.time(), state=cname, large_image="others", large_text=cname)
connected = True
else:
if connected:
if dscCnt == 2:
print(message["turned_off"])
RPC.close()
connected = False
disConnected = True
else:
dscCnt += 1
print(message["connection_lost"].format(dscCnt))
time.sleep(5)
ping = send_ping()
return_node = ping.wait()