Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit 1562beb

Browse files
committed
Decorator examples
1 parent 1350624 commit 1562beb

File tree

2 files changed

+175
-5
lines changed

2 files changed

+175
-5
lines changed

examples/async/WebSocket Client.py

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
from vrcpy.wss import AWSSClient
22
import asyncio
3-
import time
3+
4+
"""
5+
2 examples
6+
7+
1. Class inheratence
8+
2. Decorators
9+
10+
Remember you don't have to overwrite every event, just the ones you want to use!
11+
"""
12+
13+
# Example 1
14+
415

516
class AClient(AWSSClient):
617
async def on_friend_location(self, friend, world, location, instance):
718
print("{} is now in {}.".format(friend.displayName,
8-
"a private world" if location == None else world.name))
19+
"a private world" if location == None else world.name))
920

1021
async def on_friend_offline(self, friend):
1122
print("{} went offline.".format(friend.displayName))
@@ -26,7 +37,8 @@ async def on_friend_update(self, friend):
2637
print("{} has updated their profile/account.".format(friend.displayName))
2738

2839
async def on_notification(self, notification):
29-
print("Got a {} notification from {}.".format(notification.type, notification.senderUsername))
40+
print("Got a {} notification from {}.".format(
41+
notification.type, notification.senderUsername))
3042

3143
async def on_unhandled_event(self, event, content):
3244
print("Recieved unhandled event '{}'.".format(event))
@@ -50,4 +62,78 @@ def __init__(self):
5062
except KeyboardInterrupt:
5163
asyncio.get_event_loop().run_until_complete(self.logout())
5264

65+
5366
c = AClient()
67+
68+
# Example 2
69+
70+
client = AWSSClient()
71+
72+
73+
@client.event
74+
async def on_friend_location(friend, world, location, instance):
75+
print("{} is now in {}.".format(friend.displayName,
76+
"a private world" if location == None else world.name))
77+
78+
79+
@client.event
80+
async def on_friend_offline(friend):
81+
print("{} went offline.".format(friend.displayName))
82+
83+
84+
@client.event
85+
async def on_friend_active(friend):
86+
print("{} is now {}.".format(friend.displayName, friend.state))
87+
88+
89+
@client.event
90+
async def on_friend_online(friend):
91+
print("{} is now online.".format(friend.displayName))
92+
93+
94+
@client.event
95+
async def on_friend_add(friend):
96+
print("{} is now your friend.".format(friend.displayName))
97+
98+
99+
@client.event
100+
async def on_friend_delete(friend):
101+
print("{} is no longer your friend.".format(friend.displayName))
102+
103+
104+
@client.event
105+
async def on_friend_update(friend):
106+
print("{} has updated their profile/account.".format(friend.displayName))
107+
108+
109+
@client.event
110+
async def on_notification(notification):
111+
print("Got a {} notification from {}.".format(
112+
notification.type, notification.senderUsername))
113+
114+
115+
@client.event
116+
async def on_unhandled_event(event, content):
117+
print("Recieved unhandled event '{}'.".format(event))
118+
119+
120+
@client.event
121+
async def on_connect():
122+
print("Connected to wss pipeline.")
123+
124+
125+
@client.event
126+
async def on_disconnect():
127+
print("Disconnected from wss pipeline.")
128+
129+
130+
async def wait_loop():
131+
await client.login2fa(input("Username: "), input("Password: "), input("2FA Code: "), True)
132+
133+
while True:
134+
await asyncio.sleep(1)
135+
136+
try:
137+
asyncio.get_event_loop().run_until_complete(wait_loop())
138+
except KeyboardInterrupt:
139+
asyncio.get_event_loop().run_until_complete(client.logout())

examples/sync/WebSocket Client.py

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
from vrcpy.wss import WSSClient
22
import time
33

4+
"""
5+
2 examples
6+
7+
1. Class inheratence
8+
2. Decorators
9+
10+
Remember you don't have to overwrite every event, just the ones you want to use!
11+
"""
12+
13+
# Example 1
14+
15+
416
class Client(WSSClient):
517
def on_friend_location(self, friend, world, location, instance):
618
print("{} is now in {}.".format(friend.displayName,
7-
"a private world" if location == None else world.name))
19+
"a private world" if location == None else world.name))
820

921
def on_friend_offline(self, friend):
1022
print("{} went offline.".format(friend.displayName))
@@ -25,7 +37,8 @@ def on_friend_update(self, friend):
2537
print("{} has updated their profile/account.".format(friend.displayName))
2638

2739
def on_notification(self, notification):
28-
print("Got a {} notification from {}.".format(notification.type, notification.senderUsername))
40+
print("Got a {} notification from {}.".format(
41+
notification.type, notification.senderUsername))
2942

3043
def on_unhandled_event(self, event, content):
3144
print("Recieved unhandled event '{}'.".format(event))
@@ -49,4 +62,75 @@ def __init__(self):
4962
super().__init__()
5063
self.wait_loop()
5164

65+
5266
c = Client()
67+
68+
# Example 2
69+
70+
client = WSSClient()
71+
72+
73+
@client.event
74+
def on_friend_location(friend, world, location, instance):
75+
print("{} is now in {}.".format(friend.displayName,
76+
"a private world" if location == None else world.name))
77+
78+
79+
@client.event
80+
def on_friend_offline(friend):
81+
print("{} went offline.".format(friend.displayName))
82+
83+
84+
@client.event
85+
def on_friend_active(friend):
86+
print("{} is now {}.".format(friend.displayName, friend.state))
87+
88+
89+
@client.event
90+
def on_friend_online(friend):
91+
print("{} is now online.".format(friend.displayName))
92+
93+
94+
@client.event
95+
def on_friend_add(friend):
96+
print("{} is now your friend.".format(friend.displayName))
97+
98+
99+
@client.event
100+
def on_friend_delete(friend):
101+
print("{} is no longer your friend.".format(friend.displayName))
102+
103+
104+
@client.event
105+
def on_friend_update(friend):
106+
print("{} has updated their profile/account.".format(friend.displayName))
107+
108+
109+
@client.event
110+
def on_notification(notification):
111+
print("Got a {} notification from {}.".format(
112+
notification.type, notification.senderUsername))
113+
114+
115+
@client.event
116+
def on_unhandled_event(event, content):
117+
print("Recieved unhandled event '{}'.".format(event))
118+
119+
120+
@client.event
121+
def on_connect():
122+
print("Connected to wss pipeline.")
123+
124+
125+
@client.event
126+
def on_disconnect():
127+
print("Disconnected from wss pipeline.")
128+
129+
130+
client.login2fa(input("Username: "), input("Password: "), input("2FA Code: "), True)
131+
132+
try:
133+
while True:
134+
time.sleep(1)
135+
except KeyboardInterrupt:
136+
client.logout()

0 commit comments

Comments
 (0)