REACTOR
- 4 Devlogs
- 13 Total hours
REACTOR is a CLI tool for testing and developing bots for Defector, a hack club event (https://defector.hackclub.com)
REACTOR is a CLI tool for testing and developing bots for Defector, a hack club event (https://defector.hackclub.com)
This is a very speedy devlog, since it’s only like 30 mins of bugfixing so I can reship, but Ill give some details:
So basically, when I wrote the error handling in the last devlog, turns out I was trying to write to a dictionary (the bot’s data dictionary) without actually initializing it first, causing a silent crash.
I just did a little switcharoo to move the init statement (which was right after
) to run first and now it works fine! I also just added some more error logging with the textual notification system in case something goes wrong and bumped up the PyPi python package version to 1.0.4 instead of 1.0.3.
Also, for the shipwrights, I just want to clarify that it only loads files if they are .js or if they have no extension at all, so no .txt or any other file.
Feedback
Fails to list bots in current directory or sub-directories. Fix this and reship!
Shipwright walkthrough
Hello guys! Ive been a little busy the past week, but I finally got around to making some progress, and so here’s what I have to show for it:
I managed to upload Reactor to pypi under the name reactor_mindstormpro3 (Check it out here!)
It took a while to get everything set up but basically I just used hatchling to build and twine to upload, with a pyproject.toml I borrowed from some guide and modified to require some dependencies like py_mini_racer. (Hippity Hoppity Your Code Is Now My Property)
I fixed the following issues:
A lot has happened since my last devlog! I locked in and implemented a bunch of new features, such as:
This one is kinda the most self-explanitory. Basically, The mini_racer engine for python uses an old version of javascript, so some features, like table.at() isnt supported. For table.at() I just added a filler script to the front of the src that defines it, but I can’t realistically catch everything so I a segment in the loading of the bot that runs the code once and checks for a crash or parsing error from the engine and if it fails then it doesn’t import the bot into the bot table. (AI wrote the filler script, but I originally found the bug and also made the error handling section)
The request system is arguably the coolest part of this project, but I feel obligated to also explain that some of the request system was assisted by AI (meaning that AI wrote code, I read it, and then reimplemented it with the same general idea) and also ai DID write the leaderboard grabber which just grabs all of the bots’ id’s that I can use to find their links and grab the src, but ONLY the leaderboard parser, not the bot page parser.
Ok, with that out of the way, how does this really work?
well basically I take and parse the current leaderboard stream at defector.hackclub.com/_app/remote/1jsclqx/leaderboardData. Then with that info, I manually take the bot IDs given with that and shove them into this template: https://defector.hackclub.com/bot/(bot ID here). That spits out an HTML page, so I use BeautifulSoup to parse it with this absolute horror of a line: BeautifulSoup(response.text, "html.parser").find_all("pre")[-1].get_text() and extract the source code, before writing them into a file in the botCache folder in the CWD. Then I load the file as normal, just like any other bot.
The bot selection system works by just replacing the normal leaderboard widget with a DirectoryTree widget and then setting it to show the current working directory, or CWD. I then use a custom sorter script to show only folders and .js files. whenever a JS script is clicked, it just imports it as a normal bot.
I added zebra tiling to the leaderboard to make it more readable, made buttons disable themselves during certain actions like disabling the run button when refreshing, and fixed a few little UI bugs.
well after this I’m going to try to ship, with only 9 days left in Stardance. I Just need to package it with PyPi and I’m done!
Reactor is a tool to test bots made for Defector without having to publish your bot to the website and go through all that hassle.
mini_racer for python and wrote a basic function to take a .js script and run the bot function inside it.mini_racer lacking array.at() due to mini_racer using an outdated version of js by just defining it myself :)So basically, whenever I want to to play two bots against each other, I define a new mini_racer context with a modified version of their src (changed the export default with export default", "globalThis.botFunc = because otherwise mini_racer wouldnt be able to see it, and added a polyfill to the front of the script to define table.prototype.at()) and then evaluate the bot () function for both bots and simulate a match between them! I then just made a function to loop through each possible robot matchup and run the game of 100-150 rounds, and then delegated the whole thing to a thread so the UI could still render while it runs.
- Elio :3