Skip to content

Runs your tweet on an 8-bit computer emulator

License

Notifications You must be signed in to change notification settings

mattgodbolt/BBCMicroBot

 
 

Repository files navigation

BBCMicroBot

Node.js CI

A twitter bot that runs mentions on a BBC Micro emulator and responds with a tweet of 3 second, 50fps video after 30 seconds of emulated execution time. See more background on BBC Micro Bot here.

Try it now!

You can try the bot now live at https://twitter.com/bbcmicrobot

Running your own bot instance

For development and testing you can run your own instance of the bot on a Linux machine. I've been running it on:

  • AWS Arm-based instances (Amazon Linux AMI)
  • Raspberry Pi 4 (Raspbian and Raspberry Pi OS)
  • Apple Mac OS X

Installation

  • Install Node.js v12.x
  • Install ffmpeg (e.g. sudo apt install ffmpeg)
  • Download or clone this BBCMicroBot repository and cd into the directory
  • npm install

Local testing

To run a set of test tweets defined in test.js and output the video or image capture to the ./tmp/ folder. For each test a checksum of the last frame of emulator video is compared against a known good value. To run the tests type:

npm test

You should see output like the following:

[14/06/2020 09:06:49 ] [LOG]    Cli0: Running BASE2048 from @<TEST SERVER>
[14/06/2020 09:06:49 ] [LOG]    Cli0: Base 2048 decode
[14/06/2020 09:06:49 ] [LOG]    Cli0: Loading OS from roms/os.rom
[14/06/2020 09:06:49 ] [LOG]    Cli0: Loading ROM from roms/BASIC.ROM
[14/06/2020 09:06:49 ] [LOG]    Cli0: Loading ROM from roms/b/DFS-0.9.rom
[14/06/2020 09:06:49 ] [LOG]    Cli0: Loading ROM from roms/gxr.rom
[14/06/2020 09:06:59 ] [LOG]    Cli0: JSbeeb DONE in 9.807s 
[14/06/2020 09:07:01 ] [LOG]    Cli0: JSbeeb captured 150 frames (1 unique)
[14/06/2020 09:07:01 ] [LOG]    Cli0: Ffmpeg DONE in 0.172s 
[14/06/2020 09:07:01 ] [LOG]    Cli0: checksum: 80f830477fc1632c3f8a65702825f33b3d6c069e
[14/06/2020 09:07:01 ] [LOG]    Cli0: BASE2048 TEST - OK

In the tmp folder you should also see the test output files:

image

Connecting to a Twitter account

Set-up

To run the bot on a Twitter account you need to apply for a Twitter developer account, generate API keys for your bot application and put them into a .env file to be accessed by tweet.js.

You can then run the bot with

npm run

Please refer to the https://developer.twitter.com if you are unfamiliar with these processes.

Notes / excuses from the creator

BBCMicroBot was a side project that got unexpectedly successul. There are definitely some areas that can be improved and enhancement to be added which I have not had time for. I'm hoping the talent of the bot users can be focussed there! If you have suggestions please go for it. Let's keep discussion around code issues on github rather than on the bot account as much as possible.

Architecture

The bot uses Twitter mentions timeline polling and hardcoded delays instead of using webhooks or querying the rate limit APIs. There are more elegant ways of doing this but it's worked solidly for months! Some advantages of this approach is it only needs the free tier Twitter Dev account and doesn't require any open incoming ports on the host machine (definitely a bonus if you run it a home).

Security

The purpose of the bot is to allow remote execution of arbitrary code (albeit BASIC) submitted by strangers on the Internet - this is in general not a good idea. The fact that user input is sanitized by first passing through Twitter, and is run on a BBC Micro 'VM' is a big plus, but security is certainly a concern. There is more that can and should be done to sandbox the emulator for example.

Thanks

Thanks to Matt Godbolt for the JSBeeb emulator that made this project possible and to all the @bbcmicrobot users for their support - I hope this source code is interesting or useful.

About

Runs your tweet on an 8-bit computer emulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.9%
  • Shell 3.1%