-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
125 lines (98 loc) · 3.1 KB
/
Copy pathclient.py
File metadata and controls
125 lines (98 loc) · 3.1 KB
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
import requests
from datetime import datetime
import numbers
import base64
userheader = "test"
def en(input):
return base64.urlsafe_b64encode(bytes(input, "utf-8")).replace(b'=', b'~')
def time2string(time):
return datetime.strftime(time, timestd)
def ltime(time):
dif = get_time() - string2time(time)
newtime = string2time(time) + dif
return time2string(newtime)
def get_time():
return datetime.now()
def clean_time(time):
return time[9:17:]
def string2time(string):
return datetime.strptime(string, timestd)
# requests routines
def connect(username):
r = requests.get("http://glitchtech.top:8/connect",
params={"username": en(username)})
result = r.json()
return result["result"]
def join(*args):
if localusername == "local":
return "Connect to the server first"
room = args[0][0]
r = requests.get("http://glitchtech.top:8/join",
params={
"username": en(localusername),
"room": en(room)
})
result = r.json()
if result["result"] == 1:
global localroom
localroom = room
return "Connected to %s" % room
elif result["result"] == 0:
return "User/Room not found"
def message(msg):
#cl_write(en(msg))
r = requests.get("http://glitchtech.top:8/message",
params={
"username": en(localusername),
"message": en(msg)
})
result = r.json()
if result["result"] == 1:
return msg
else:
return "User/Room not found"
def users(*args):
r = requests.get("http://glitchtech.top:8/users")
res = r.json()
usercount = len(res)
userlist = [
"There are %s users online" % usercount,
"Username Last Updated Activity"
]
for user in list(res):
if isinstance(res[user]["activity"], numbers.Number):
activity = activitychart[res[user]["activity"]]
else:
activity = res[user]["activity"]
time = clean_time(res[user]["keepalive"])
userlist.append("%s%s%s" % (user.ljust(16), time.ljust(20), activity))
return userlist
def keepalive(username):
r = requests.get("http://glitchtech.top:8/keepalive",
params={"username": en(username)})
result = r.json()
#{'timestamp': '09:10:23:00:12:02:049792', 'author': 'a', 'message': 'ok'}
return result
def rooms():
r = requests.get("http://glitchtech.top:8/rooms")
res = r.json()
roomcount = len(res)
r = requests.get("http://glitchtech.top:8/users")
userlist = r.json()
roomlist = [
"There are %s rooms open" % roomcount,
"Room Last Updated Users"
]
for room in list(res):
presentusers = 0
for user in list(userlist):
numbercheck = isinstance(userlist[user]["activity"], numbers.Number)
if not numbercheck and userlist[user]["activity"] == room:
presentusers += 1
#time = clean_time(res[room]["lifetime"])
#Properly store lifetimes serverside first
time = clean_time(time2string(get_time()))
roomlist.append("%s%s%s" % (room.ljust(16), time.ljust(20), presentusers))
return roomlist
def superconnect():
print("hi")