blog/posts/lewd-lad-infra.md
2021-07-01 22:12:17 -07:00

2.7 KiB

Lewdlad the Cronjob that became a bot and orchestrates AWS Instances

What is "Lewdlad"

Lewdlad is a Discord chat bot I created which (at the time of writing this) is used to orchestrate multiple AWS EC2 servers to provide affordable game servers to various communities that I help run.

Some history

The very first version of Lewdlad was a python script that would literally pick random images from a set of red boards on 4chan and send it to a random online person in the guild. Eventually I created a bot(that had 1 command), that would invoke this script and send the results to whoever invoked the command. That command is .roll. After some time I added some more 4chan related commands and eventually the Hanime module.

The Hanime module is weird because it was conceived out of a joke: "what if Lewdlad recommended some fire hentai". Being that it was likely 2 AM and I was bored I did some searching and found that there is no public API for Hanime. I then opened up the site and did some reverse engineering to figure out how to spoof a browser request and get some results. Some reversing and trial-and-error later and I had a working request script, and could search. Finally I took this script, wrapped with some ergonomics and hooked it into the Lewdlad's codebase.

The beginnings of orchestration

Around this time I started hosting a minecraft server for friends to play on. Being that the server had limited burst capacity I knew I had to make sure the server could replenish its burst for when the peak hours hit. To achieve this I put Lewdlad on the same server as the minecraft game files and put the start-minecraft.sh script behind a command for Lewdlad to use.

The architecture was surprisingly simple and ended up being way more flexible and easy to use than I ever expected. Basically each game had its own directory in a predetermined directory:

Lewdlad/
	<code and things>
Games/
	Minecraft/
		discord-bot.json
		start.sh
		<game files>
	ReflexArena/
		discord-bot.json
		start.sh
		stop.sh
		<game files>
	CS:Source/
		<game files>

The advantage of this structure above is that only directories with that discord-bot.json configuration file would ever be picked up by the bot. It was also really easy to setup since you only needed a start.sh script and optionally a stop.sh script since Lewdlad had its own nuke-all-the-things-function in its own back-end. This meant a minimal configuration could look like

{
	"name": "some server",
	"id": "name of parent directory",
	"script": "start.sh"
	// These below are added by the bot
	"pid": <process id here>,
	"active": true|false,
}

Adding crash safety is trivially easy as recovering is a matter of checking configuration files and determining which are falsely active.