Saltar a contenido

Clientes y HTTP

bostie.RESTClient

RESTClient(token: str | None = None, *, api_url: str | None = None, http_settings: HTTPSettings = DEFAULT_HTTP, allowed_mentions: AllowedMentions = DEFAULT_ALLOWED_MENTIONS)

Bases: _Client[REST]

bot.rest without a gateway, for scripts and web backends.

Open it with async with RESTClient(token) as client:; the token defaults to the BOSTIE_TOKEN environment variable.

http property

http: HTTPClient

The client for any endpoint, inside async with.

rest property

rest: REST

Discord's REST operations by resource, as on bot.rest.

bostie.BearerClient

BearerClient(access_token: str | None = None, *, api_url: str | None = None, http_settings: HTTPSettings = DEFAULT_HTTP)

Bases: _Client[BearerREST]

What an OAuth2 access token reaches, for the user who granted it.

Open it with async with BearerClient(access_token) as user:. Without a token it only reaches rest.oauth2, to exchange a code or credentials for one.

http property

http: HTTPClient

The client for any endpoint, inside async with.

rest property

rest: BearerREST

bostie.WebhookClient

WebhookClient(url: str, *, api_url: str | None = None, http_settings: HTTPSettings = DEFAULT_HTTP, allowed_mentions: AllowedMentions = DEFAULT_ALLOWED_MENTIONS)

Bases: _Client[Webhooks]

One webhook, from its URL alone, with no bot token.

Open it with async with WebhookClient(url) as webhook:.

http property

http: HTTPClient

The client for any endpoint, inside async with.

id instance-attribute

id = int(found['id'])

token instance-attribute

token: str = found['token']

delete async

delete() -> None

delete_message async

delete_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> None

edit async

edit(**options: Unpack[WebhookEditWithToken]) -> Webhook

edit_message async

edit_message(message_id: int, /, **parts: Unpack[WebhookEditMessage]) -> WebhookMessage

Edit what the webhook sent: a part not given stays and None clears it.

execute async

execute(content: str | None = None, **parts: Unpack[WebhookExecute]) -> WebhookMessage

Send a message and return it once Discord saved it.

execute_github async

execute_github(payload: Mapping[str, Any], **options: Unpack[WebhookExecuteCompatible]) -> None

Post a GitHub webhook event payload, as GitHub would.

execute_slack async

execute_slack(payload: Mapping[str, Any], **options: Unpack[WebhookExecuteCompatible]) -> None

Post a message in Slack's incoming webhook format.

fetch async

fetch() -> Webhook

fetch_message async

fetch_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> WebhookMessage

bostie.SyncWebhookClient

SyncWebhookClient(url: str, *, api_url: str | None = None, http_settings: HTTPSettings = DEFAULT_HTTP, allowed_mentions: AllowedMentions = DEFAULT_ALLOWED_MENTIONS)

A WebhookClient for code without an event loop, each call running its own.

id instance-attribute

id = checked.id

token instance-attribute

token = checked.token

delete

delete() -> None

delete_message

delete_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> None

edit

edit(**options: Unpack[WebhookEditWithToken]) -> Webhook

edit_message

edit_message(message_id: int, /, **parts: Unpack[WebhookEditMessage]) -> WebhookMessage

Edit what the webhook sent: a part not given stays and None clears it.

execute

execute(content: str | None = None, **parts: Unpack[WebhookExecute]) -> WebhookMessage

Send a message and return it once Discord saved it.

execute_github

execute_github(payload: Mapping[str, Any], **options: Unpack[WebhookExecuteCompatible]) -> None

Post a GitHub webhook event payload, as GitHub would.

execute_slack

execute_slack(payload: Mapping[str, Any], **options: Unpack[WebhookExecuteCompatible]) -> None

Post a message in Slack's incoming webhook format.

fetch

fetch() -> Webhook

fetch_message

fetch_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> WebhookMessage

bostie.ASGIApp

ASGIApp(bot: Bot, *, token: str | None = None, public_key: str | None = None)

An ASGI app for the app's Interactions Endpoint and Webhook Events URLs.

Interactions reach the bot's commands and routes, webhook events its listeners. start(), which the server's lifespan calls, starts the bot's REST without a gateway unless the bot already runs, and reads the app's public key.

bot instance-attribute

bot = bot

start async

start() -> None

Start the bot's REST if the bot is not running, sync its commands.

close async

close() -> None

Close the bot if start() started it.

bostie.verify_signature

verify_signature(public_key: str, signature: str, timestamp: str, body: bytes) -> bool

Check an X-Signature-Ed25519 header against the app's hex public_key.

bostie.decode_webhook_event

decode_webhook_event(body: bytes) -> Event | None

A webhook event request's event, a RawEvent if untyped, or None for a PING.

bostie.http.HTTPClient

HTTPClient(bridge: Bridge)

Sends requests to Discord's REST API through bostie's rate limiter.

request async

request(method: str, route: str, /, *, json: Any = None, files: Sequence[File] = (), form: Mapping[str, object] | None = None, urlencoded: Mapping[str, str] | None = None, query: Query | None = None, reason: str | None = None, **params: object) -> Any

Send a request to a route like /channels/{channel_id}; return its JSON.

form adds named form fields, and files under their own names, to the multipart body; urlencoded sends fields as a form-urlencoded body. An empty body returns None; an error status raises the matching bostie error.

read async

read(source: Attachment | str) -> bytes

Download an attachment or a CDN URL, with no token and no rate limits.

save async

save(source: Attachment | str, path: str | PathLike[str]) -> None

Download an attachment or a CDN URL into the file at path.

to_file async

to_file(source: Attachment | str) -> File

Download an attachment or a CDN URL as a File to upload again.

send async

send(method: str, route: str, /, *, json: Any = None, files: Sequence[File] = (), form: Mapping[str, object] | None = None, urlencoded: Mapping[str, str] | None = None, query: Query | None = None, reason: str | None = None, **params: object) -> bytes

Send a request like request; return the raw body of the answer.

bostie.HTTPSettings dataclass

HTTPSettings(*, global_rate_limit: int = 50, max_rate_limit_wait: float = 30.0, retries: int = 2, connect_timeout: float = 10.0, read_timeout: float = 60.0, rate_limiter: bool = True, proxy: str | None = None)

How bostie paces, retries and times out its REST requests, and its proxy.

global_rate_limit class-attribute instance-attribute

global_rate_limit: int = 50

max_rate_limit_wait class-attribute instance-attribute

max_rate_limit_wait: float = 30.0

retries class-attribute instance-attribute

retries: int = 2

connect_timeout class-attribute instance-attribute

connect_timeout: float = 10.0

read_timeout class-attribute instance-attribute

read_timeout: float = 60.0

rate_limiter class-attribute instance-attribute

rate_limiter: bool = True

proxy class-attribute instance-attribute

proxy: str | None = None

bostie.File dataclass

File(name: str, data: bytes, description: str | None = None, spoiler: bool = False, title: str | None = None, duration_secs: float | None = None, waveform: bytes | None = None)

A file to upload with a message; spoiler blurs it until clicked.

With duration_secs and waveform, an audio file makes a voice message.

name instance-attribute

name: str

data instance-attribute

data: bytes

description class-attribute instance-attribute

description: str | None = None

spoiler class-attribute instance-attribute

spoiler: bool = False

title class-attribute instance-attribute

title: str | None = None

duration_secs class-attribute instance-attribute

duration_secs: float | None = None

waveform class-attribute instance-attribute

waveform: bytes | None = None