curious.core.state¶
Defines State
.
Functions
int_or_none (val, default) |
Returns int or None. |
Classes
GuildStore () |
A store for guilds in the state. |
State (client, max_messages) |
This represents the state of the Client - in other libraries, the cache. |
-
curious.core.state.
int_or_none
(val, default)[source]¶ Returns int or None.
Return type: Optional
[int
]
-
class
curious.core.state.
GuildStore
[source]¶ Bases:
collections.abc.MutableMapping
A store for guilds in the state.
-
guilds
= None¶ The internal actual guilds.
-
order
= None¶ The order of the guilds, as specified by the READY packet.
-
with_order
¶ Return type: Mapping
[int
,Guild
]Returns: A mapping of the guilds with the order specified in the ready packet.
-
clear
() → None. Remove all items from D.¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
-
class
curious.core.state.
State
(client, max_messages: int = 500)[source]¶ Bases:
object
This represents the state of the Client - in other libraries, the cache.
The other main purpose for this class is to parse events from the Discord websocket.
-
_user
= None¶ The current user of this bot. This is automatically set after login.
-
client
= None¶ The client associated with this connection.
-
_private_channels
= None¶ The private channel cache.
-
_guilds
= None¶ The guilds the bot can see.
-
_users
= None¶ The current user cache.
-
messages
= None¶ The deque of messages. This is bounded to prevent the message cache from growing infinitely.
-
is_ready
(shard_id)[source]¶ Checks if a shard is ready.
Parameters: shard_id ( int
) – The shard ID to check.Return type: bool
Returns: A boolean signifying if this shard is ready or not.
-
guilds_ordered
¶ Return type: Mapping
[int
,Guild
]Returns: An ordered mapping of int -> Guild
by the user’s guild ordering.
-
have_all_chunks
(shard_id)[source]¶ Checks if we have all the chunks for the specified shard.
Parameters: shard_id ( int
) – The shard ID to check.
-
for ... in
get_all_channels
()[source]¶ Return type: Generator
[Channel
,None
,None
]Returns: A generator that yields all :class:`.Channel`s the bot can see.
-
for ... in
get_all_members
()[source]¶ Return type: Generator
[Member
,None
,None
]Returns: A generator that yields all :class:`.Member`s the bot can see.
-
for ... in
get_all_roles
()[source]¶ Return type: Generator
[Role
,None
,None
]Returns: A generator that yields all :class:`.Role`s the bot can see.
-
find_member_or_user
(user_id)[source]¶ Finds a member or user by ID.
Parameters: user_id ( int
) – The user ID to find.Return type: Union
[Member
,User
]Returns: The Member
orUser
found, if any.
-
find_channel
(channel_id)[source]¶ Finds a channel by ID. This will search all guild channels, as well as private channels.
Parameters: channel_id ( int
) – The ID of the channel to find.Return type: Optional
[Channel
]Returns: A Channel
that represents the channel, or None if no channel was found.
-
find_message
(message_id)[source]¶ Finds a message in the current cache, if it exists.
Parameters: message_id ( int
) – The message ID to find.Return type: Message
Returns: A Message
to find, or None if it was not cached.
-
_check_decache_user
(id)[source]¶ Checks if we should decache a user.
This will check if there is any guild with a reference to the user.
-
make_webhook
(event_data)[source]¶ Creates a new webhook object from the event data.
Parameters: event_data ( dict
) – The event data.Return type: Webhook
Returns: A Webhook
.
-
make_private_channel
(channel_data)[source]¶ Creates a new private channel and caches it.
Parameters: channel_data ( dict
) – The channel data to cache.Return type: Channel
Returns: A new Channel
.
-
make_user
(user_data, *, user_klass=<class 'curious.dataclasses.user.User'>, override_cache=False)[source]¶ Creates a new user and caches it.
Parameters: Return type: ~U
Returns: A new :class`.User` (hopefully).
-
make_message
(event_data, cache=True)[source]¶ Constructs a new message object.
Parameters: Return type: Returns: A new
Message
object for the message.
-
await
wait_for_voice_data
(guild_id)[source]¶ Waits for the two voice data packets to be received for the specified guild.
-
async for ... in
handle_resumed
(gw, event_data)[source]¶ Called when the gateway connection is resumed.
-
async for ... in
handle_presences_replace
(gw, event_data)[source]¶ Called when presences are replaced.
-
async for ... in
handle_guild_members_chunk
(gw, event_data)[source]¶ Called when a chunk of members has arrived.
-
async for ... in
handle_guild_create
(gw, event_data)[source]¶ Called when GUILD_CREATE is dispatched.
-
async for ... in
handle_guild_update
(gw, event_data)[source]¶ Called when GUILD_UPDATE is dispatched.
-
async for ... in
handle_guild_delete
(gw, event_data)[source]¶ Called when a guild becomes unavailable.
-
async for ... in
handle_guild_emojis_update
(gw, event_data)[source]¶ Called when a guild updates its emojis.
-
async for ... in
handle_message_create
(gw, event_data)[source]¶ Called when MESSAGE_CREATE is dispatched.
-
async for ... in
handle_message_update
(gw, event_data)[source]¶ Called when MESSAGE_UPDATE is dispatched.
-
async for ... in
handle_message_delete
(gw, event_data)[source]¶ Called when MESSAGE_DELETE is dispatched.
-
async for ... in
handle_message_delete_bulk
(gw, event_data)[source]¶ Called when MESSAGE_DELETE_BULK is dispatched.
-
async for ... in
handle_message_reaction_add
(gw, event_data)[source]¶ Called when a reaction is added to a message.
-
async for ... in
handle_message_reaction_remove_all
(gw, event_data)[source]¶ Called when all reactions are removed from a message.
-
async for ... in
handle_message_reaction_remove
(gw, event_data)[source]¶ Called when a reaction is removed from a message.
-
async for ... in
handle_guild_member_add
(gw, event_data)[source]¶ Called when a guild adds a new member.
-
async for ... in
handle_guild_member_remove
(gw, event_data)[source]¶ Called when a guild removes a member.
-
async for ... in
handle_guild_member_update
(gw, event_data)[source]¶ Called when a guild member is updated.
-
async for ... in
handle_guild_ban_add
(gw, event_data)[source]¶ Called when a ban is added to a guild.
-
async for ... in
handle_guild_ban_remove
(gw, event_data)[source]¶ Called when a ban is removed from a guild.
-
await
handle_voice_server_update
(gw, event_data)[source]¶ Called when a voice server update packet is dispatched.
-
async for ... in
handle_voice_state_update
(gw, event_data)[source]¶ Called when a member’s voice state changes.
-
await
handle_webhooks_update
(gw, event_data)[source]¶ Called when a channel has a webhook updated.
This event is effectively useless.
-