a mastodon bot that plays snake, using polls
check it out at https://botsin.space/@snake_game
- snakebot-core contains the code for the snake game
- snakebot-masto is the actual mastodon bot
- snakebot-web is a web ui for testing the bot, without needing to run a mastodon instance. i made it because i didn't want to run a mastodon instance. i probably put too much effort into it but who cares
npm i --workspaces
to install dependenciesnpm run start-bot
to build and run the mastodon botnpm run start-web
to build start the web ui
snakebot-masto requires some environment variables to be either defined, or provided in a .env file in its folder
- searches for the last post by the bot user that begins with the game's, as well as the bot's replies to it
- the header matches the pattern
/^➡ (.+) - GAME (\d+) (END )?⬅️/
- the header matches the pattern
- decodes the game's state from the invisible text in the post's text
- the text is made out of the characters U+2061, U+2062, U+2063, U+2064
- check
hiddenEncode.ts
for how exactly it works
- checks the result of the poll to decide where to move next
- if the poll is tied, the topmost option is picked
- the snake's current direction is always at the top, so if no one votes, the snake keeps moving forward
- update's the game's state and posts the next image and poll
- they have to be in separate posts because mastodon doesn't allow having both an image and a poll in one ..