Перейти к содержанию

Шлюз и кэш

bostie.gateway.GatewayClient

GatewayClient(bridge: Bridge, token: str, *, intents: int, shard_count: int, shard_ids: Iterable[int], large_threshold: int = start, session_file: Path | None = None)

The bot's gateway shards: send commands, reconnect, and measure latency.

shard_count instance-attribute

shard_count = shard_count

shard_ids property

shard_ids: tuple[int, ...]

The shards this process runs.

latency property

latency: float | None

Mean seconds from a heartbeat to its ACK over shards that measured one.

shard

shard(shard_id: int) -> Shard

The shard with this id; ValueError when this process does not run it.

shard_for

shard_for(guild_id: int) -> int

The shard Discord sends this guild's events to.

send

send(op: int, d: Any = None) -> None

Send a gateway command to the shards it belongs to.

Op 3 goes to every shard, a payload with a guild_id to that guild's shard, one with guild_ids to each of their shards with its share of the ids, and anything else to shard 0. Replies arrive only for event names someone listens to.

reconnect

reconnect() -> None

Drop every shard's connection and resume its session on a new one.

bostie.gateway.Shard

Shard(bridge: Bridge, shard_id: int)

One gateway connection of the bot.

id instance-attribute

id = shard_id

latency property

latency: float | None

Seconds from the last heartbeat to its ACK, or None when there is none.

send

send(op: int, d: Any = None) -> None

Send a gateway command on this shard.

reconnect

reconnect() -> None

Drop the connection and resume the session on a new one.

bostie.RequestedMembers dataclass

RequestedMembers(members: tuple[Member, ...], presences: tuple[Presence, ...], not_found: tuple[int, ...])

The answer to bot.request_members(); not_found holds unknown user ids.

members instance-attribute

members: tuple[Member, ...]

presences instance-attribute

presences: tuple[Presence, ...]

not_found instance-attribute

not_found: tuple[int, ...]

bostie.cache.Cache

Cache(max_messages: int = 0, *, members: bool = False, presences: bool = False, max_dm_channels: int = 0)

Guilds, channels, active threads, voice states and the bot's member and user.

Scheduled events, stage instances and soundboard sounds are kept too.

Members, presences, the latest messages and DM channels are kept only when asked for. Channels are stored as received, obfuscated ones included, except the fields CHANNEL_UPDATE does not keep current (last_message_id, message_count, member_count, last_pin_timestamp), which are None.

names instance-attribute

names = frozenset(event.NAME for event in self._handlers)

guild

guild(id: int) -> Guild | None

guilds

guilds() -> list[Guild]

channel

channel(id: int) -> Channel | None

guild_channels

guild_channels(guild_id: int) -> list[Channel]

The guild's channels, active threads included.

role

role(id: int) -> Role | None

guild_roles

guild_roles(guild_id: int) -> list[Role]

scheduled_event

scheduled_event(id: int) -> ScheduledEvent | None

guild_scheduled_events

guild_scheduled_events(guild_id: int) -> list[ScheduledEvent]

stage_instance

stage_instance(id: int) -> StageInstance | None

guild_stage_instances

guild_stage_instances(guild_id: int) -> list[StageInstance]

soundboard_sound

soundboard_sound(id: int) -> SoundboardSound | None

guild_soundboard_sounds

guild_soundboard_sounds(guild_id: int) -> list[SoundboardSound]

voice_state

voice_state(guild_id: int, user_id: int) -> VoiceState | None

The user's voice state, or None when they are in no voice channel.

guild_voice_states

guild_voice_states(guild_id: int) -> list[VoiceState]

Everyone in a voice channel of the guild.

me

me(guild_id: int) -> Member | None

The bot's own member in a guild.

member

member(guild_id: int, user_id: int) -> Member | None

A member; only the bot's own unless the cache keeps members.

guild_members

guild_members(guild_id: int) -> list[Member]

presence

presence(guild_id: int, user_id: int) -> Presence | None

A member's presence when the cache keeps presences; None when offline.

guild_presences

guild_presences(guild_id: int) -> list[Presence]

The presences of the guild's members who are not offline.

user

user(id: int) -> User | None

The bot's user, or the user of a cached member or DM channel.

dm_channel

dm_channel(user_id: int) -> Channel | None

The bot's DM channel with a user, if it is one of the latest kept.

message

message(id: int) -> _CachedMessage | None

One of the latest max_messages messages.

permissions

permissions(channel_id: int, member: AnyMember | None = None) -> Permissions | None

A member's permissions in a channel, else the bot's; None if unknown.

guild_permissions

guild_permissions(guild_id: int, member: AnyMember | None = None) -> Permissions | None

A member's guild-wide permissions, else the bot's; None if unknown.

clear

clear() -> None

bostie.lookup.Lookup

Lookup(bot: Bot)

bot.lookup: an object from the cache, or from REST without caching it.

user async

user(user_id: int) -> User

member async

member(guild_id: int, user_id: int) -> Member

channel async

channel(channel_id: int) -> Channel

guild async

guild(guild_id: int) -> Guild

role async

role(guild_id: int, role_id: int) -> Role

message async

message(channel_id: int, message_id: int) -> Message | WebhookMessage