Sleepy Discord Turns 3 Years Old

written on May 30, 2019 by Hao Qi Wu

Yes, that’s right. It’s been 3 years now. For the first time ever, I’m going to be doing a look back at over one year of progress. Since this project is mostly made by one person, I might go into my own personal life and how it affects the library.

Do, note that most of these changes aren’t in the master branch and are only available in the develop branch.

Voice

A bit of over a year ago, voice support was started on the develop branch. To get this working, it required the library to be able to handle more than one WebSockets connection. WebSockets Connections are what Discord uses to send messages to users in real time. The library used to assume that only one WebSockets connection was needed, that connection being used for incoming information for text channels. In order to connect to a voice channel, 2 WebSockets connections are needed. One to get the information needed to start the voice WebSockets connection and the voice WebSockets connection. The interface used to handle WebSockets connection had to be extended so that the library knows which WebSockets connection is being handled.

Voice receive is still being worked on. It’s not documented so support for it might change in the future.

Switching to CMake

Since the easily days of the library, MSBuild or Visual Studio’s build system and Make was the only thing that compiled the library. There have been requests to support CMake. I was pretty new to CMake and never used it before, so I didn't add support for it. However, during the summer, I had to learn CMake when I was contributing to the Dolphin Emulator.

CMake solves some long-standing issues that would take time to fix in the build script. Mainly with linking and including the library files. Now thanks to CMake, it’s a solved problem.

JSON Rewrite

There were a lot of issues with the old way the library parsed and serialized JSON. The old JSON library that was used, used a lot of memory when parsing the complex objects that Discord was sending. Most objects couldn’t be serialized or it was too much effort to implement. So a solution was needed.

Switching to RapidJSON

The solution I came up with was to switch to a better JSON library. RapidJSON is fast and uses less memory. However, Sleepy Discord had a lot of code that used the old JSON library and all that code needed to be rewritten. The rewrite was done and in the process, I made writing the logic needed to parse and serialized Discord structures much easier to write thanks to some heavy use of C++ templates.

Embeds

One feature that was often requested for sending Embeds. You could send Embeds before but they were hard and complex to do. You were basically writing the code to create the embed as if you weren’t using a library. Now, thanks to the JSON Rewrite, creating embeds can be done by setting values in an object and then passing that object to the sendMessage function. This is thanks to the rewrite making it much simpler for Sleepy Discord’s Discord objects to be serialized into JSON.

SleepyDiscord::Embed embed;
embed.title = "Hello World!";
embed.description = "This is an embed.";
client.sendMessage(channelID, "", embed);

More Advance Version Control

The library now knows what version is being used. You can know easily at runtime or compile time check the branch, build number, version hash, and if there are any modifications were made to the library.

You can also check the version based on if some features are available.

//get the branch name
std::string branch = SleepyDiscord::branch;
//check if feature is avaiable at runtime
if(isFeatureAvaiable("List of Available Features"))
	a = 0; //do stuff

Longer uptime

There was a long-standing infinite reconnect loop bug. It was pretty random and it caused the longest uptime of the library to be only 3 weeks at most. This has now been fixed and now the library can run a bot for months.

Discord Server

I’ve been holding back on making a Discord Server. I mostly held back because I didn’t feel like the idea of being a Discord Server admin, but Sharon, the owner of the Aegis.cpp library, made me bite the bullet.

Discord Server

Personal Life

You can skip to Plans for the Future if you don't care about my personal life.

Discord Rich Presence for Dolphin

Earlier I mentioned in the article that I contributed to Dolphin. I made a pull request to add Discord Rich Presence into Dolphin and it was accepted. Dolphin uses CMake to configure their macOS and Linux builds and I needed to make changes to their builds so I had to learn some CMake. This actually benefited Sleepy Discord as written above.

College

I finally graduated from High School and I’m now in my first year of college. This effects the library in that I now have less time to spend working on the library because college in my experience requires more study time to pass classes.

Plans for the Future

Last year, I promised that I’ll talk about the future of the library. Well, this is it. I was going to write a whole article about until I realized how little it was about plans for the future. Also, for more up to date plans, check out my to-do list.

Async

This is partially already available in the library but not easy to use. This one feature going to pretty big for a lot of bots. Having the bot block on every request isn’t going to cut it for bots that are on more servers. It’s not good for bots that need to scale up.

Better Optional Caching

Right now, the optional cache can easily take up the most memory. Optimizations, like not storing duplicates and adding some limits to the cache, are plans for I will be making the cache use up less memory.

Auto Generate Docs

The docs are barely updated. And it's an issue, docs are very important to help make the library easier to use. So, I plan on looking into my options on how docs are going to be auto generated instead of having to manually write everything.