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

Commit 1350624

Browse files
committed
event decorator
1 parent ffe097f commit 1350624

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

vrcpy/wss.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ def _update_friend(self, newUser, id):
114114
self.me.friends = self.me.offlineFriends + self.me.onlineFriends
115115
return oldUser
116116

117+
# WS Event decorator
118+
119+
def event(self, func):
120+
"""Decorator that overwrites class ws event hooks
121+
122+
Example
123+
---------
124+
125+
@client.event
126+
def on_connect():
127+
print("Connected to wss pipeline.")
128+
129+
"""
130+
131+
if func.__name__.startswith("on_") and hasattr(self, func.__name__):
132+
setattr(self, func.__name__, func)
133+
return func
134+
else:
135+
raise TypeError("Registered event must be a valid event function")
136+
117137

118138
class WSSClient(Client, _WSSClient):
119139
# User WS overwrites

0 commit comments

Comments
 (0)