-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
149 lines (129 loc) · 5.01 KB
/
main.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
import API.Presence
import argparse
import math
import time
from pypresence import Presence
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--user", type=int, help = "User ID", required=True)
parser.add_argument("-r", "--refresh", type=int, default=20, help = "Refresh period")
parser.add_argument("-o", "--online", type=bool, default=False, help = "Show when you are just Online")
parser.add_argument("-s", "--security", type=str, default="", help = "A .ROBLOSECURITY token, necessary for the API to gather game info for some players")
args = parser.parse_args()
ClientID = 874664899035402283
UserID = args.user
ShowOnline = args.online
RefreshPeriod = args.refresh
RobloSecurity = args.security
ThisPresence = API.Presence.PresenceAPI(roblosecurity = RobloSecurity)
RPC = None
Connected = False
StartTime = 0
def InitRPC():
global RPC
RPC = Presence(ClientID, pipe=0)
def Connect():
global Connected
global RPC
if Connected == False:
try:
RPC.connect()
Connected = True
return True
except:
RPC = None
return False
return False
def Disconnect():
global Connected
global StartTime
global RPC
if Connected == True:
try:
RPC.close()
StartTime = 0
Connected = False
return True
except:
RPC = None
StartTime = 0
Connected = False
return False
return False
print("Started!")
while True:
if RPC is None:
try:
InitRPC()
print("Connected to Discord!")
except:
print("Failed to connect to Discord, is it running?")
CurrentPresence = None
try:
CurrentPresence = ThisPresence.GetUserPresence(UserID)
except:
print("Failed to get presence data!")
if CurrentPresence != None:
GameName = CurrentPresence["lastLocation"]
RootPlaceID = CurrentPresence["rootPlaceId"]
if GameName == None or GameName == "":
GameName = ""
Buttons = [
{"label": "Profile", "url": "https://www.roblox.com/users/" + str(UserID) + "/profile"}
]
if RootPlaceID != "" and RootPlaceID != None:
Buttons.append({"label": "Experience", "url": "https://www.roblox.com/games/" + str(RootPlaceID)})
if CurrentPresence["userPresenceType"] == 1 and ShowOnline == True:
if StartTime == 0:
StartTime = math.floor(time.time())
if Connect() == True:
print("User went Online!")
if GameName != "":
if Connected == True:
try:
RPC.update(state=GameName, details="Online", large_image="player", small_image="online", start=StartTime, buttons=Buttons)
except:
Disconnect()
else:
if Connected == True:
try:
RPC.update(details="Online", large_image="player", small_image="online", start=StartTime, buttons=Buttons)
except:
Disconnect()
elif CurrentPresence["userPresenceType"] == 2:
if StartTime == 0:
StartTime = math.floor(time.time())
if Connect() == True:
print("User opened the Player!")
if GameName != "":
if Connected == True:
try:
RPC.update(state=GameName, details="Playing", large_image="player", small_image="playing", start=StartTime, buttons=Buttons)
except:
Disconnect()
else:
if Connected == True:
try:
RPC.update(details="Playing", large_image="player", small_image="playing", start=StartTime, buttons=Buttons)
except:
Disconnect()
elif CurrentPresence["userPresenceType"] == 3:
if StartTime == 0:
StartTime = math.floor(time.time())
if Connect() == True:
print("User opened Studio!")
if GameName != "":
if Connected == True:
try:
RPC.update(state=GameName, details="Building", large_image="studio", small_image="building", start=StartTime, buttons=Buttons)
except:
Disconnect()
else:
if Connected == True:
try:
RPC.update(details="Building", large_image="studio", small_image="building", start=StartTime, buttons=Buttons)
except:
Disconnect()
else:
if Disconnect() == True:
print("User went Offline!")
time.sleep(RefreshPeriod)