Clients und 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.
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.
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:.
delete_message
async
¶
delete_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> None
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_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.
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_message
¶
fetch_message(message_id: int, /, **options: Unpack[WebhookMessageIn]) -> WebhookMessage
bostie.ASGIApp
¶
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.
bostie.verify_signature
¶
Check an X-Signature-Ed25519 header against the app's hex public_key.
bostie.decode_webhook_event
¶
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.
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.