7
7
from functools import partial
8
8
from operator import attrgetter
9
9
from pathlib import Path
10
- from typing import Dict , List , MutableMapping , Optional , Tuple , Type , cast
10
+ from typing import (
11
+ Dict ,
12
+ List ,
13
+ MutableMapping ,
14
+ Optional ,
15
+ Tuple ,
16
+ Type ,
17
+ TypedDict ,
18
+ cast ,
19
+ )
11
20
from weakref import WeakValueDictionary
12
21
13
22
import sqlalchemy
19
28
CommandHook ,
20
29
ConfigHook ,
21
30
EventHook ,
31
+ IrcOutHook ,
32
+ OnCapAckHook ,
33
+ OnCapAvaliableHook ,
34
+ OnConnectHook ,
35
+ OnStartHook ,
36
+ OnStopHook ,
37
+ PeriodicHook ,
38
+ PermHook ,
39
+ PostHookHook ,
22
40
RawHook ,
23
41
RegexHook ,
42
+ SieveHook ,
24
43
hook_name_to_plugin ,
25
44
)
26
45
from cloudbot .util import HOOK_ATTR , LOADED_ATTR , async_util , database
29
48
logger = logging .getLogger ("cloudbot" )
30
49
31
50
32
- def find_hooks (parent , module ):
51
+ class HookDict (TypedDict ):
52
+ command : List [CommandHook ]
53
+ on_connect : List [OnConnectHook ]
54
+ on_start : List [OnStartHook ]
55
+ on_stop : List [OnStopHook ]
56
+ on_cap_available : List [OnCapAvaliableHook ]
57
+ on_cap_ack : List [OnCapAckHook ]
58
+ sieve : List [SieveHook ]
59
+ event : List [EventHook ]
60
+ regex : List [RegexHook ]
61
+ periodic : List [PeriodicHook ]
62
+ irc_raw : List [RawHook ]
63
+ irc_out : List [IrcOutHook ]
64
+ post_hook : List [PostHookHook ]
65
+ config : List [ConfigHook ]
66
+ perm_check : List [PermHook ]
67
+
68
+
69
+ def find_hooks (parent , module ) -> HookDict :
33
70
hooks = defaultdict (list )
34
71
for func in module .__dict__ .values ():
35
72
if hasattr (func , HOOK_ATTR ) and not hasattr (func , "_not_" + HOOK_ATTR ):
@@ -44,7 +81,7 @@ def find_hooks(parent, module):
44
81
# delete the hook to free memory
45
82
delattr (func , HOOK_ATTR )
46
83
47
- return hooks
84
+ return cast ( HookDict , hooks )
48
85
49
86
50
87
def find_tables (code ):
@@ -351,7 +388,7 @@ async def load_plugin(self, path):
351
388
self ._sort_hooks ()
352
389
353
390
# we don't need this anymore
354
- del plugin .hooks ["on_start" ]
391
+ plugin .hooks ["on_start" ]. clear ()
355
392
356
393
def _sort_hooks (self ) -> None :
357
394
def _sort_list (hooks ):
0 commit comments