From fbe47818902601c1af3090238cfbc274ec036b7f Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 1 Jul 2021 22:12:17 -0700 Subject: [PATCH] + Start of lewdlad bot post --- posts/lewd-lad-infra.md | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 posts/lewd-lad-infra.md diff --git a/posts/lewd-lad-infra.md b/posts/lewd-lad-infra.md new file mode 100644 index 0000000..2c0911c --- /dev/null +++ b/posts/lewd-lad-infra.md @@ -0,0 +1,64 @@ +# 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/ + +Games/ + Minecraft/ + discord-bot.json + start.sh + + ReflexArena/ + discord-bot.json + start.sh + stop.sh + + CS:Source/ + + +``` + +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": , + "active": true|false, +} +``` + +Adding crash safety is trivially easy as recovering is a matter of checking configuration files and determining which are _falsely active_. + +