Continuation of the original GMacLak.wsend() method in ClockBot v3.
Tasks
What?
Upon invoking ctx.wsend(content, ...), automatically fetch and cache the webhook,
and send a webhook message to the target channel with given arguments.
The goal is to make the task of sending a webhook message as trivial as normal .send() calls.
Why?
ClockBot and its cogs frequently need to send webhook messages in various forms.
It's tedious to deal with above every time, and without caching it can take up to a few seconds.
How?
wsend()
- Try searching the cache (
channel: webhook mapping)
- Try fetching existing channel's webhook owned by the bot
- Try creating a new webhook
- Cache the result, or report failure with
ctx.send_error()
- Send the webhook message with given arguments
Webhookable
https://discordpy.readthedocs.io/en/stable/search.html?q=channel.webhooks
- Currently, Forum, Stage, Text, and Voice channels support webhooks
- Exact same methods
.webhooks() and .create_webhook() are provided for all of them
- There is no ABC or mixin, each of them have their own, exact same implementation
The goal is to restrict channels that can be used with wsend() through type hints.
@typing.runtime_checkable
class Webhookable(typing.Protocol): ...
# or
Webhookable = ForumChannel | StageChannel | TextChannel | VoiceChannel`
Caching
Simple. It's just dict[Webhookable, Webhook].
But where do I store this, and how do I pass it around?
Continuation of the original
GMacLak.wsend()method in ClockBot v3.Tasks
wsend(to: Webhookable, **options)without cachingWebhookable- choose betweenProtocolorUnion.wsend()available to custom contexts as a methodWhat?
Upon invoking
ctx.wsend(content, ...), automatically fetch and cache the webhook,and send a webhook message to the target channel with given arguments.
The goal is to make the task of sending a webhook message as trivial as normal
.send()calls.Why?
ClockBot and its cogs frequently need to send webhook messages in various forms.
It's tedious to deal with above every time, and without caching it can take up to a few seconds.
How?
wsend()channel: webhookmapping)ctx.send_error()Webhookablehttps://discordpy.readthedocs.io/en/stable/search.html?q=channel.webhooks
.webhooks()and.create_webhook()are provided for all of themThe goal is to restrict channels that can be used with
wsend()through type hints.Caching
Simple. It's just
dict[Webhookable, Webhook].But where do I store this, and how do I pass it around?