/ 

GameBot v0.3 is Live: The Shadowrun 1st-3rd Edition Discord Bot Gets an Overhaul

URL copied to clipboard
By AstroMacGuffin dated  last updated 
![Classic Shadowrun Discord bot gets a version bump and stuff](/static/img/mm/data/network-ge29fb26d8_1280.jpg) The timing was pure luck: Discord started enforcing new rules for bots the day after I started overhauling GameBot. (This resulted in about 12-24 hours where the bot was non-responsive.) The overhaul took 3 days worth of overtime hours, but version 0.3 is now live. At a glance: - The hourglass reaction will plague you no more: Google Drive is no longer the data provider for the bot. - Instead, data is saved to a database which is hosted on the same machine as the bot itself. - For those of you self-hosting, there is a data migration script. - With the exception of scenes, I got 100% data fidelity after migration (and I may cook up a solution for the scenes). - It was trivial to fix the scenes data manually -- only one person had used the scenes feature thus far anyway. - So many bug fixes. Why were there so many bugs? This was my first project after several years of not writing code. Known Issues: - The bot has occasional downtime. I'm temporarily hosting the bot at home, and we have power outages more often than I'd like. - The admin functions in `admin.js` haven't been rewritten yet, except to ensure `!showcache` and `!clearcache` work. Some or all of the other admin functions will be removed as unnecessary. [If you haven't already, you can invite the bot to your server by clicking here.](https://discordapp.com/oauth2/authorize?client_id=609274260007026689&scope=bot&permissions=3136) Read on for more details and my plans for the future.

### For Those of You Who Read Code You can see the rewrite by visiting [the project on GitHub](https://github.com/NathanHawks/SR1eGameBot). The instructions for self-hosting have been updated, albeit I can't teach you how to manage or setup a web host so you may be stuck running it from home. I don't know whether Heroku allows you to run MongoDB on their hobbyist accounts; I know their free accounts are ending very soon, at the time of this writing. Many NPM packages were removed and added. In particular, you no longer need `googleapis` or `express` or any of their many dependencies ... actually, you never needed `express`, except that I required it in the code for no good reason. You ***will*** need the NPM package `mongodb`, and `node-stream-zip` is required by the data migration script. To migrate the data, first make sure MongoDB is installed and running. Make sure `config.js` is set up with the proper `this.dbUrl` value including MongoDB user credentials if you've turned on MongoDB's password authentication. Then go to Google Drive and right-click your `UserData` folder, and choose Download. Then rename the downloaded file to simply `UserData.zip` and place it in the same folder with the bot's code files. Then run `node ./migrate.js` from the bot's folder. After migrating, you will have more entries in the `folders` collection than were reported in the `migrate.js` output. This is normal; it happens because `node-stream-zip` only reports folder endpoints: `UserData/serverID/channelID/userID` gets reported as one folder, when actually it's four folders nested in each other. [Here's how to enable password authentication for MongoDB](https://www.mongodb.com/docs/manual/tutorial/configure-scram-client-authentication/). ### The Rewrite When I started, the bot was all in one file, `main.js` which was about 5,300 lines of code. I split it up into multiple files so it's easier to work with. I upgraded the bot from discord.js v10 to discord.js v14, which wasn't quite as painful as I expected. I wanted to preserve the hourglass reaction that shows you the bot is working on your request, but a) it wasn't necessary because the bot is so fast now, and b) it seems bots now need Manage Messages permission just to remove their own reaction from a message, which strikes me as overkill so I didn't do it. With actual glee, I removed all the Google Drive code and replaced it with MongoDB code. This had the effect of shortening a great many functions down to about 10-30% of their original length. Google Drive is a pain in the @$$ to work with, and I'm glad it's gone from this project. This change is also where the speed increase came from. The bot will also be much more reliable since MongoDB on the same server is not going to drop requests like GDrive so often did. Before really digging in, I installed an IDE plugin in Atom, my code editor. This is where a lot of the bugfixes came from -- the IDE plugin pointed out little mistakes I'd made all over the place. Imagine me making scope errors in a project. A lot of them. GameBot was my first jump back into coding after several years of not writing code. I'm sorry for all the bugs and I'm sorry I left them hanging there for so long. As a side note, why does Node.js let so many things slide in error-strewn projects? I had variables not declared, but in use and working; I'm pretty sure I even had a misspelled function that didn't throw any error, but I won't swear it because I can't remember what it was, to find it in the git archive. Anyway, version 0.2 was a mess, and I'm glad I spent the time to make it better. ### Future Plans for GameBot The next step is a web interface for scenes, macros, reminders, and ammo tracking. I'll host the bot on the same server as this website, and loosely integrate the two. Anyone with an account on my website will have access to these web UI's. There will be an account-matching feature to unlock the web UI's: the website will generate a code which you'll DM to the bot, to link your accounts. Then you'll be able to browse and edit your data. In the case of scenes, reminders, and ammo tracking, these web interfaces will be much easier to work with than the bot's commands. This will be especially true for ammo tracking, where the bot commands are basically impossible to memorize. I have other, pie-in-the-sky ideas for GameBot. I don't know whether any of these will ever happen, but I'd like to see: - character sheet entry / retrieval / printable format / PDF export - rolling dice via the bot using skills, etc., on the character sheet - GM access to player character sheets (if both player and GM are members of this site and both have linked their website accounts to their Discord accounts) - perhaps rolling dice using skills, etc., via the web interface - handouts prep/deploying, including graphical and PDF handouts (text ones can already be done using the scene features) ### Oh, and (Maybe) One More Thing Speaking of Discord bot code that might find its way into a website integration project someday, I've fully encoded the Cyberpunk Red "LIfepath" system in Node.js. Again, I don't know if it'll ever happen (it would be a large feature) but I would like to someday integrate that as a web tool, too.
Profile image

About the author of this piece, AstroMacGuffin: "I enjoy coding in Node.js and JavaScript as a hobby. I find Node.js to be a welcome escape, after a lifetime of code, with previous experience with PHP and JavaScript on the LAMP stack. I'm one of those people who spends way too much time herding electric sheep in front of a computer. You can find me on the JavaScript Mastery discord, where I'm a moderator, or on the Classic Shadowrun discord, where I'm the owner and founder. "

For more by AstroMacGuffin, click here.

🔍

Valid HTML!Valid CSS!Powered by Node.js!Powered by Express.js!Powered by MongoDB!