Force twitch bot to stay connected or workarounds

I’m trying to code a twitch bot to handle a game that common extensions like streamlabs or streamelements don’t seem to know how to handle (or at least I haven’t figured it out yet). I’ve set up a glitch javascript bot using tmi, and it seemed pretty straightforward. The bot reacts to certain messages in the chat to register players, their points, and when the game is over it decides who won and how they scored. You can find it here:

The problem is that the bot keeps disconnecting and reconnecting, and as a game is supposed to last ~5 mins, this happens up to several times throughout. Whenever the bot reconnects, the script runs again from scratch, forgetting all the information and what time the game was at.

I’m not a javascript expert, but it was easy for me to keep all the information in the single script file, setting up a setTimeInterval to handle the game duration and in-file variables to store the players and their points. However, due to the common disconnecting, this doesn’t actually allow people to play the game.

I’m looking for advice on what’s the best & easiest way to get the bot connected or to store the information in a more stable manner. Is it best to set up a small database to keep the scores? But then how do I do the timer? Should I try to split to code into two .js files to make sure the main one is running just once while the other is reconnecting?

Any ideas, suggestions and improvements are welcome! (and of course, feel free to check out the stream, TheSocialHermit, it’s an IRL exploration of Japanese landscape, and an escape from lockdown :))