diff options
Diffstat (limited to 'discord/state.py')
| -rw-r--r-- | discord/state.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/discord/state.py b/discord/state.py index 6148889d..8b793c20 100644 --- a/discord/state.py +++ b/discord/state.py @@ -64,7 +64,7 @@ log = logging.getLogger(__name__) ReadyState = namedtuple('ReadyState', ('launch', 'guilds')) class ConnectionState: - def __init__(self, *, dispatch, handlers, syncer, http, loop, **options): + def __init__(self, *, dispatch, handlers, hooks, syncer, http, loop, **options): self.loop = loop self.http = http self.max_messages = options.get('max_messages', 1000) @@ -75,6 +75,7 @@ class ConnectionState: self.syncer = syncer self.is_bot = None self.handlers = handlers + self.hooks = hooks self.shard_count = None self._ready_task = None self._fetch_offline = options.get('fetch_offline_members', True) @@ -170,6 +171,14 @@ class ConnectionState: else: func(*args, **kwargs) + async def call_hooks(self, key, *args, **kwargs): + try: + coro = self.hooks[key] + except KeyError: + pass + else: + await coro(*args, **kwargs) + @property def self_id(self): u = self.user |