RSS Feed for Memes in C#
Article
This is a project I had on a todo list for a while and I finally made the time to do it. The idea is I want bots to post daily memes automatically on platforms like Discord. I decided the mechanism to distribute memes would be an RSS feed, since it is platform agnostic. However, I will be focusing on Discord for the scope of this write-up.
First RSS Feed
I decided to host the RSS feed on this site, fracturedcode.net. I had to create some database schema to facilitate this. I decided to move all content on the site from the filesystem to the database, in a Content
table. Each Post
referenced some Content
. The actual content was stored in a bytea
column which just holds binary data. This means it can hold text, images, executables...pretty much anything.
I then created a PostType
table to differentiate between different types of posts, like blog vs meme. Each Post
has a PostTypeId
.
Retrieving the necessary data to construct the RSS feed involves fetching all published posts of type Meme
, and prefetching their Content
. Encoding images in base64 and returning them would be impractical considering all the bandwidth required. Instead, the RSS items contain a url. Just like any post, the post topic ("meme") followed by it's SeoName
will take you to the image:
Tying Into the Feed
Originally, I tried to use the Socialfeeds Discord bot, which was already in my server for posting certain tweets. The process seemed straightforward enough, but I couldn't get it to work. I tried adding other feeds in case it was just my feed that was causing the issue. Then, I tried contacting their support, but they didn't seem to think it was on their end. This kind of frustrated me, so I just gave up and moved onto something else for a bit.
In the meantime, I setup the Integromat bot to read and post new items from the RSS feed as a stopgap.
Submit Your Own Memes
At this point I had decided I was going to present this topic for my computer science club meeting. I wanted to get other students involved, so I set up a page for students to submit their own memes for the bot to post. I added a MemeProposal
table to the database to facilitate this. I didn't really put a lot of effort into the page.
I also have a super-secret dashboard to approve the memes and queue them up to be posted to the RSS feed. It doesn't look the greatest, but I really just needed something to make my life on the backend a little easier.
Latest Meme Sidebar
At around this point I created a "Latest Meme" sidebar for the site. It simply displays the last posted meme.
CS Club Presentation
This was the first CS club meeting of the year, which meant it was important to draw in as many students as possible. I already had a pretty good topic, that is, memes. I decided that hosting the meeting with Discord would also be a good idea because every student has it, especially CS students.
The turnout was actually really great, but only two memes have been submitted so far! Feel free to submit your own.
Getting Rid of Integromat
I had spun up an instance of the Red Discord Bot for other reasons. There is a third party plugin that allows posting of RSS feeds, so I installed that. Unfortunately, it didn't seem to like my RSS feed.
So I corrected the issues, which were encoding related to encoding. This is the code I ended up with that spits out the feed. For this I used the RssSyndication library.
Socialfeeds still wouldn't work after I corrected some of the issues, but Red did!
I disconnected Integromat, and now Red posts to both the CS club discord and my personal server.
Conclusion
I am very pleased with these results. This experiment has paved the path for future plans I have for this site. The work that was done on the backend to abstract posts into any type of post and the new way of fetching content will make things much easier in the future. I will be sure to post about those activities when they happen.
You can use the feed yourself at this endpoint: