curious.core.event¶
Special helpers for events.
Functions
event (name[, scan]) |
Marks a function as an event. |
scan_events (obb) |
Scans an object for any items marked as an event and yields them. |
Classes
EventContext (cl, shard_id, event_name) |
Represents a special context that are passed to events. |
EventManager () |
A manager for events. |
Exceptions
ListenerExit |
Raised when a temporary listener is to be exited. |
-
exception
curious.core.event.
ListenerExit
[source]¶ Bases:
Exception
Raised when a temporary listener is to be exited.
def listener(ctx, message): if message.author.id == message.guild.owner_id: raise ListenerExit
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
async with
curious.core.event.
_wait_for_manager
(manager, name, predicate)[source]¶ Helper class for managing a wait_for.
-
class
curious.core.event.
EventManager
[source]¶ Bases:
object
A manager for events.
This deals with firing of events and temporary listeners.
-
task_manager
= None¶ The task manager used to spawn events.
-
event_hooks
= None¶ A list of event hooks.
-
event_listeners
= None¶ A MultiDict of event listeners.
-
temporary_listeners
= None¶ A MultiDict of temporary listeners.
-
remove_event
(name, func)[source]¶ Removes a function event.
Parameters: - name (
str
) – The name the event is registered under. - func – The function to remove.
- name (
-
add_temporary_listener
(name, listener)[source]¶ Adds a new temporary listener.
To remove the listener, you can raise ListenerExit which will exit it and remove the listener from the list.
Parameters: - name (
str
) – The name of the event to listen to. - listener – The listener function.
- name (
-
remove_listener_early
(name, listener)[source]¶ Removes a temporary listener early.
Parameters: - name (
str
) – The name of the event the listener is registered under. - listener – The listener function.
- name (
-
add_event_hook
(listener)[source]¶ Adds an event hook.
Parameters: listener – The event hook callable to use.
-
await
_safety_wrapper
(func, *args, **kwargs)[source]¶ Ensures a coro’s error is caught and doesn’t balloon out.
-
await
_listener_wrapper
(key, func, *args, **kwargs)[source]¶ Wraps a listener, ensuring ListenerExit is handled properly.
-
await
wait_for
(event_name, predicate=None)[source]¶ Waits for an event.
Returning a truthy value from the predicate will cause it to exit and return.
Parameters: - event_name (
str
) – The name of the event. - predicate – The predicate to use to check for the event.
- event_name (
-
wait_for_manager
(event_name, predicate)[source]¶ Returns a context manager that can be used to run some steps whilst waiting for a temporary listener.
async with client.events.wait_for_manager("member_update", predicate=...): await member.nickname.set("Test")
This probably won’t be needed outside of internal library functions.
Return type: AsyncContextManager
[None
]
-
-
curious.core.event.
event
(name, scan=True)[source]¶ Marks a function as an event.
Parameters: - name – The name of the event.
- scan (
bool
) – Should this event be handled in scans too?
-
for ... in
curious.core.event.
scan_events
(obb)[source]¶ Scans an object for any items marked as an event and yields them.
Return type: Generator
[None
,Tuple
[str
,Any
],None
]
-
class
curious.core.event.
EventContext
(cl: curious.core.client.Client, shard_id: int, event_name: str)[source]¶ Bases:
object
Represents a special context that are passed to events.
Parameters: -
shard_id
= None¶ The shard this event was received on.
-
shard_count
= None¶ The shard for this bot.
-
event_name
= None¶ The event name for this event.
-
handlers
¶ Return type: List
[Callable
[[EventContext
],None
]]Returns: A list of handlers registered for this event.
-
await
change_status
(*args, **kwargs)[source]¶ Changes the current status for this shard.
This takes the same arguments as
Client.change_status
, but ignoring the shard ID.Return type: None
-
gateway
¶ Return type: GatewayHandler
Returns: The Gateway
that produced this event.
-