DDBKitUtilities
Extensions
DDBKitUtilities exposes a collection of useful extensions for your Discord bots.
BucketRatelimiting
Your Discord bot may have a number of commands that use expensive resources or external service limits.
To prevent abuse, you can use the BucketRatelimiting
extension to rate limit these commands.
To get started, register the extension at boot.
@_spi(Extensions) import DDBKitUtilities
struct MyNewBot: DiscordBotApp { func onBoot() async throws { // ...
RegisterExtension(BucketRatelimiting()) }}
You can now use the ratelimited()
modifier on your commands to rate limit them.
Command("ratelimited") { i in try await i.respond(with: "This command is rate limited!")}.ratelimited()
You can customise it by passing in a configuration object.
Command("ratelimited") { i in try await i.respond(with: "This command is rate limited!")}.ratelimited(.init(maxUses: 10, timeWindow: 60))
The example above would rate limit the command to 10 uses per minute.
Builders
DDBKitUtilities provides a collection of utiltity builders for various structured types. This allows for a more concise and readable way to instance these types.
Message builder
You can build a simple message with text content with the Message
struct.
Text Content
Message { Text("Hello World!")}
MessageContentComponent
types such asText
can be used at the root of aMessage
builder to set the message content easily.
Text Formatting
The following example demonstrates many of the available modifiers and components.
Message { Heading { Text { Text("Welcome to ") Text("The Test") .italic() Text("!") } .underlined() } Heading("We're testing the Message DSL") .medium() Text("Actually scratch that") .strikethrough() Link("https://llsc12.me") .disableEmbedding() .maskedWith { Text("check out this!") .bold() } Blockquote { Heading { Text("Blockquote!") .underlined() } .medium() Text("yep, we got em") }}