hookt banner

hookt

6 devlogs
19h 40m 4s

A simple Kotlin DSL for using Discord webhooks, most notably supporting easy rich embeds and other endpoints for e.g. deletion and edit of the webhook. Also, it has support for Discord’s new Components V2, which definitely makes it worth it!

Demo Repository

Loading README...

Tiazzz

Shipped this project!

Hours: 1.03
Cookies: 🍪 7
Multiplier: 6.33 cookies/hr

Release 1.0.1 is mostly a minor fix around the fact I forgot to remove debug printlns from the build. I added a verbose mode option to the webhook context and added a few more places where this is used for logging. I also did a few minor tweaks to the README and other things that I don’t even remember doing, but they happened I guess.

Tiazzz

Fixed a small thing where the execute form and webhook URL would be printed.

You can now set verbose to true in the webhook builder to enable the logging of these values and a few more. This is disabled by default. It also logs the queries and whether files were added.

Alongside this, I switched the library to use SLF4J Loggers instead of println.

Attachment
0
Tiazzz

Shipped this project!

Hours: 18.64
Cookies: 🍪 204
Multiplier: 10.93 cookies/hr

Making this small library started because I needed one for Khat, and when I asked some people that work a lot with Kotlin and Discord, they told me “Well, I don’t know many libraries, but Webhooks are stupidly uncomplicated, so you could just make it yourself.”

And make it myself I did, and I went a little overboard I believe. Half of what I added, no one will probably use, but I had a fun time tinkering with all the little details, from DSL to HTTP Content Types, and all the way to different asserts in tests. It was truly an exciting way to get introduced to all these new things.

It might have some flaws (I think mostly because I was too lazy to make all the fields for the message type, but okay, those are largely irrelevant anyway), but not everything is perfect and in the end I can always fix it, plus, I think I have what I need for now. Happy days!

Tiazzz

As a last bit of stuff before the shipment, I fixed up some of the message stuff, polished the tests, and we’re good to go!

So lo and behold, passing tests!

Attachment
0
Tiazzz

This time I added file support for components and general attachments!

At first I was pretty discouraged because I’d have to work with the HTTP multipart/form-data Content Type rather than the usual application/json. The reason is because one part is for the JSON, and the others for the files, of course. Luckily, when I checked how well Ktor was made for this, it turned out it was surprisingly easy. With a small setup (which excludes the builders and DSL, and also the whole attachments block in the execute form) it already worked out of the box. Of course I still added DSL for files, that pretty automatically manages the attachments too, and it also works perfectly fine.

Alongside this I also quickly added a minimal data class for messages, so it can be returned from the execute function’s HttpResult, and used for the other message-related functions.

Happy new year!

Attachment
Attachment
0
Tiazzz

This time I went ahead and added DSL functions to add components to your Discord message! As far as I’m aware there aren’t a lot of libraries that natively support Components V2, let alone make it a concise process.

Adding components was actually surprisingly easy, but I had to come up with some very interesting code that uses types, reflection and all that in order to “automatically” be able to add a universal component DSL function. It’s even developer in such a way that it’s pretty modular, you can probably add your own custom components in case this library does not support them. Again, everything is “properly” documented.

Next up: adding file uploading support, because a lot of these components include media and having to use just https probably won’t cut it for longer. Also, I want to write a GitHub wiki. Happy days!

Attachment
Attachment
0
Tiazzz

The latter goal has been achieved, and I have added three helper functions that can retrieve environmental values!

getEnv, getEnvOrNull and getEnvOrElse. The first tries to get the value and throws if it can’t be found, the second simply returns null in that case and the third returns whatever you passed from the lambda (for when you maybe want to do user config via .env files!) Alongside this I added fitting JUnit tests for them (which was a beast, I liked tinkering around with the somewhat unused JUnit asserts, like assertThrows, which checks whether the code block provided throws a certain exception, handy in the case of getEnv.)

Now the only thing that remains is components and perhaps files.

Attachment
0
Tiazzz

Webhooks are stupidly simple, yet when I check to see if there are any ready-to-use wrappers with some decent DSL I can only find either bad ones, or old ones. Because of this, I decided to make my own since I desperately needed it for Khat (https://github.com/Tywrap-Studios/Khat), and maybe for other projects too, may they use webhooks.

In this quick session I added the bare-bones basics of webhooks: simple content messages and rich embeds. No files, although I might not add those, and no components. Considering Components V2 is very nifty to have, however, I am excited to try to implement using it through more comprehensive DSL.

So that’s next up, I want to add Components (V2) support, and utilities for getting environment variables.

Attachment
0