-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
38 lines (29 loc) · 820 Bytes
/
hooks.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
# hooks.py
from dataclasses import dataclass
from util import core
# {
# 'member_join': [{
# id: 'wordleserver',
# func: () => {},
# },]
# }
@dataclass
class Hook:
id: str
func: callable
def load(_):
def register_hook(name, id, func):
print('registering a hook rn')
hooks = core.exports.get('hooks')
core.exports.put_if_none('hooks', {})
if name not in hooks().keys():
hooks()[name] = []
# check to see if this id exists
for hook_obj in hooks()[name]:
if hook_obj.id == id:
hook_obj.func = func
return
# otherwise just put it in
hooks()[name].append(Hook(id, func))
core.exports.put('register_hook', register_hook)
print('Exported register_hook')