Magic Eight Ball is a wondrous device that lets a user offload any important decision to a plastic ball. Well, this one you don't even need to shake! I've built a GitHub Action that would allow you to tempt fate and receive answers to the most important questions right in the comments to a PR or an issue!
I wanted to build something magical, fun, a bit chaotic and over-the-top! I asked a magic eight ball if my fortune cookie idea was any good and it said that magic eight ball was a better one :)
How I built it
I've started with the actual magic eight ball script. The most important part was, of course, to write the answers. I've learned that a classic magic eight ball has 20 answers, but they are so boring...
I wanted something opposite of boring! Therefore I went to ChatGPT and politely asked it to generate some funny responses:
Of course, I've asked it for an algorithm as well, but it was too plain:
constresponses=["It is certain","Without a doubt","Yes – definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yes","Signs point to yes","Reply hazy, try again","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","Outlook not so good","My sources say no","Very doubtful"];functiongenerateEightBallResponse(){constrandomIndex=Math.floor(Math.random()*responses.length);returnresponses[randomIndex];}// Example usageconsole.log(generateEightBallResponse());
I've asked to rewrite it with crypto.randomBytes, because I sure wanted cryptographically secure random answers (who wouldn't? ):
This was a bit better, but one can never have enough magic and so I settled for the following overkill version ( writing it myself this time was faster than trying to explain to an AI what I had in mind ):
And created a workflow to test this action in the same repository:
on:issue_comment:types:[created]jobs:test_8ball:name:Magic Eight Ballruns-on:ubuntu-latestpermissions:pull-requests:writeissues:writecontents:readsteps:-name:Checkoutuses:actions/checkout@v3-name:Run action from mainuses:./
It didn't work on the first try and I've learned about permissions (originally I was missing contents: read and my workflow was failing to checkout the repo).
Then, I've learned that default action runners support node16 at most and I couldn't use crypto.getRandomValues just yet. With a heavy heart I've settled for a little bit less magical random generator (by using crypto.randomBytes twice):