Add before_identify_hook to have finer control over IDENTIFY syncing

This commit is contained in:
Rapptz
2020-04-11 17:28:03 -04:00
parent 9c7ae6b9dc
commit 394b514cc9
4 changed files with 57 additions and 19 deletions

View File

@ -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