Skip to content

feat: automated webhook management and caching #13

@WieeRd

Description

@WieeRd

Continuation of the original GMacLak.wsend() method in ClockBot v3.

Tasks

  • Implement wsend(to: Webhookable, **options) without caching
  • Webhookable - choose between Protocol or Union
  • Where, and how do I manage the cache?
  • Make .wsend() available to custom contexts as a method

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()

  1. Try searching the cache (channel: webhook mapping)
  2. Try fetching existing channel's webhook owned by the bot
  3. Try creating a new webhook
  4. Cache the result, or report failure with ctx.send_error()
  5. 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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Backlog

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions