-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
133 lines (111 loc) · 4.64 KB
/
app.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
import tkinter as tk
import requests
import threading
import time
import logging
from tkinter import messagebox
from datetime import datetime
logging.basicConfig(level=logging.DEBUG)
# Global variables for controlling polling
polling = False
poll_thread = None
def fetch_user_presence(user_id):
url = "https://presence.roblox.com/v1/presence/users"
headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
}
payload = {
"userIds": [user_id]
}
try:
response = requests.post(url, json=payload, headers=headers)
logging.debug(f"Request payload: {payload}")
logging.debug(f"Response Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
if 'userPresences' in data and len(data['userPresences']) > 0:
user_presence = data['userPresences'][0]
presence_type = user_presence['userPresenceType']
logging.debug(f"User Presence Type: {presence_type}")
# Update GUI with the presence data
status_text.set(f"Status: {presence_type_text(presence_type)}\nResponse Code: {response.status_code}")
# Check if the current status matches the notification flags
if notify_flags[presence_type].get():
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Get the current timestamp
messagebox.showinfo("Presence Notification", f"The user is now {presence_type_text(presence_type)}!\nTimestamp: {timestamp}")
else:
logging.debug("No user presence data found")
status_text.set(f"Status: User not found or offline.\nResponse Code: {response.status_code}")
else:
logging.error(f"Failed to fetch presence data: {response.status_code}")
status_text.set(f"Error: {response.status_code}")
except requests.exceptions.RequestException as e:
logging.error(f"Request failed: {e}")
status_text.set("Error: Request failed")
def presence_type_text(presence_type):
presence_map = {
0: "Offline",
1: "Online",
2: "In-Game",
3: "In Studio",
4: "Invisible"
}
return presence_map.get(presence_type, "Unknown")
def start_polling():
global polling, poll_thread
user_id = user_id_entry.get()
if user_id.isdigit() and not polling:
polling = True
poll_thread = threading.Thread(target=poll_presence, args=(int(user_id),))
poll_thread.daemon = True # Allow thread to be killed when main program ends
poll_thread.start()
start_button.config(state=tk.DISABLED)
stop_button.config(state=tk.NORMAL)
else:
status_text.set("Error: Please enter a valid user ID or polling is already active.")
def stop_polling():
global polling
polling = False
start_button.config(state=tk.NORMAL)
stop_button.config(state=tk.DISABLED)
def poll_presence(user_id):
while polling:
fetch_user_presence(user_id)
time.sleep(2) # Polling interval in seconds
# GUI Setup
root = tk.Tk()
root.title("Roblox Presence Checker")
window_width = 400
window_height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
position_top = int(screen_height / 2 - window_height / 2)
position_right = int(screen_width / 2 - window_width / 2)
root.geometry(f'{window_width}x{window_height}+{position_right}+{position_top}')
tk.Label(root, text="Enter User ID:").pack(pady=10)
user_id_entry = tk.Entry(root)
user_id_entry.pack(pady=5)
start_button = tk.Button(root, text="Start Polling", command=start_polling)
start_button.pack(pady=10)
stop_button = tk.Button(root, text="Stop Polling", command=stop_polling, state=tk.DISABLED)
stop_button.pack(pady=10)
status_text = tk.StringVar()
status_label = tk.Label(root, textvariable=status_text, justify=tk.LEFT)
status_label.pack(pady=10)
# Now create the notify_flags after initializing the root
notify_flags = {
0: tk.BooleanVar(value=False), # Offline
1: tk.BooleanVar(value=False), # Online
2: tk.BooleanVar(value=False), # In-Game
3: tk.BooleanVar(value=False), # In Studio
4: tk.BooleanVar(value=False) # Invisible
}
# Presence Status Notification Toggles
checkbox_label = tk.Label(root, text="Select statuses you want to be notified about:")
checkbox_label.pack(pady=5)
status_frame = tk.Frame(root)
status_frame.pack(pady=10)
for presence_type, flag in notify_flags.items():
tk.Checkbutton(status_frame, text=presence_type_text(presence_type), variable=flag).pack(side=tk.LEFT)
root.mainloop()