Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def event_hook(self, *args, **kwargs):
"""
The event hook for the commands manager.
"""
async with anyio.create_task_group() as tg:
tg: anyio.TaskGroup
for (plugin, scope) in self.plugins.values():
body = inspect.getmembers(plugin, predicate=lambda v: hasattr(v, "is_event"))
ctx = current_event_context()
for _, handler in body:
if ctx.event_name not in handler.events:
continue
cofunc = partial(
self.client.events._safety_wrapper, handler, ctx, *args, **kwargs
)
await tg.spawn(cofunc)
def __init__(self):
#: The task manager used to spawn events.
self.task_manager: anyio.TaskGroup = None
#: A list of event hooks.
self.event_hooks = set()
#: A MultiDict of event listeners.
self.event_listeners = MultiDict()
#: A MultiDict of temporary listeners.
self.temporary_listeners = MultiDict()
self.chunker = md_chunker.Chunker(self)
self.chunker.register_events(self.events)
self._ready_state = {}
#: The :class:`.HTTPClient` used for this bot.
self.http = HTTPClient(self._token)
#: The cached gateway URL.
self._gw_url = None # type: str
#: The application info for this bot. Instance of :class:`.AppInfo`.
self.application_info = None # type: AppInfo
#: The task manager used for this bot.
self.task_manager: anyio.TaskGroup = None
for (name, event) in scan_events(self):
self.events.add_event(event)
async def _wait_for_manager(manager, name: str, predicate):
"""
Helper class for managing a wait_for.
"""
async with anyio.create_task_group() as tg:
tg: anyio.TaskGroup
try:
partial = functools.partial(manager.wait_for, name, predicate)
await tg.spawn(partial)
yield
except:
await tg.cancel_scope.cancel()
raise
async def task_group(self) -> AsyncIterator[TaskGroup]:
async with create_task_group() as group:
yield group