ava-cassiopeia / discord-text-adventure-bot

A bot for Discord to play text adventure games in Discord
ISC License
45 stars 7 forks source link

CRASH ON $start A (Raspian) #39

Closed ava-cassiopeia closed 4 years ago

ava-cassiopeia commented 4 years ago

Direct copy of #34 comment


Experiencing same issue. dfrotz is installed normally, can be used to play the game from any location. Bot works until starting a game and entering a command, crashes with the same "throw er, unhandled error event".

Running Raspbian (Debian variant). All packages reinstalled and updated with npm wherever possible.

Capture

2020-06-18T15_37_36_232Z-debug.log

ava-cassiopeia commented 4 years ago

The error doesn't seem to be coming directly from my code, which makes me suspect that one of the deps has an update that is causing this, or I'm incorrectly calling one of the deps and its triggering this. If providing your package.lock.json wouldn't reveal too much about your system, that could be greatly useful, otherwise I'll attempt to repro by installing the bot from latest.

KawaiiFiveO commented 4 years ago

This contains the file generated by npm upon install.

package-lock.zip

ava-cassiopeia commented 4 years ago

@KawaiiFiveO Since you've got the bot installed locally, can you do the following:

  1. npm i --save discord.io (from the bot directory)
  2. Verify that the version of Discord.io is 2.4.0 in your package lock after doing step 1
  3. Run the bot and see if it works

I have discord.io pinned at a specific release because of previous bugs with it, and this looks like its the same category. Pinning to latest (ie. what the above does) seems to fix locally for me. Please let me know if that works for you.

If that doesn't work, I'll considering switching the codebase over to discord.js instead of discord.io. I've been using discord.js for new projects lately and it has been a lot more stable.

KawaiiFiveO commented 4 years ago

NPM seems to be very confused on which version to install. On the initial install of the bot, it installs the latest commit of the gateway-v6 branch. If run using --save discord.io, it installs version 2.5.3 according to the package lock and the bot crashes upon startup. If run using --save discord.io@2.4.0, it installs 2.4.0 and the bot also crashes upon startup.

ava-cassiopeia commented 4 years ago

That's very strange, especially given that 2.5.3 isn't a valid version according to the releases page for that code.

On the readme for discord.io, it does say that you can get true latest by installing izy521/discord.io instead of discord.io. Perhaps that's worth a shot? Not sure if that will play nicely with the require() imports I have in the code though.

Really, though, it seems like the right strategy—as I mentioned before—is to just switch from discord.io to discord.js. I use the .js one in other projects and it works fine. I've created #41 and will try to set aside some time sooner rather than later (this weekend, or hopefully earlier) to take a look and start migrating code. Updates on that will be posted to said bug.

Sorry for the inconvenience, I'm hopeful that this migration will solve your issue.

ava-cassiopeia commented 4 years ago

I've now fully migrated the bot to the new framework, discord.js.

@KawaiiFiveO could you please install the latest version of the bot (0.14.0) and try again?

KawaiiFiveO commented 4 years ago

log

I reinstalled the bot and when running it I got this error instead. It seems very similar to the previous one.

ava-cassiopeia commented 4 years ago

Indeed it does, that's disappointing. Out of curiosity, what version of node are you running?

KawaiiFiveO commented 4 years ago

Originally I was using latest stable (12.18.1). I just tried updating to current (14.4.0) and now the problem is different. Instead of crashing upon being given a game command, the bot now does nothing at all. There is no output to either the console or server.

I reinstalled the bot using the npm method instead of manually and the problem still occurred.

ava-cassiopeia commented 4 years ago

That's strange, I'm not sure what to make of that, especially if your logs have nothing.

Well, if you can revert back to Node 12.18.1, there's one more thing I can think of that might yield additional information: have you tried different games?

ava-cassiopeia commented 4 years ago

Also, when you ran the games using dfrotz, did you specify the -p flag? If not, could you, and see if that has a meaningful difference?

ava-cassiopeia commented 4 years ago

Also also (sorry stream of consciousness as I flip through the code), can you double-check that the game file is in the right place as specified in the config.json?

KawaiiFiveO commented 4 years ago

I got the bot to work. Apparently the error thrown will occur whenever the location of the game file is invalid. I tried several methods to direct the program to the game file before finding the one that worked (place the game in the same directory and just entering the name of the file). Thank you for helping.

More questions: Is it possible to add multiple games to the config? Is there a way to kill the bot when it's running in the background? It seems to spawn multiple processes (two node processes and an sh process) and trying to kill it causes the terminal to hang completely. There also isn't a way to kill it via Discord.

ava-cassiopeia commented 4 years ago

Hooray! I'm glad you've got it working now. That being said, I think this probably brings up a point that maybe I should, in the actual code, double-check the file paths are valid, so I can give a better error than this barely-meaningful error. I've created #43 to address this.

To answer your questions:

Is it possible to add multiple games to the config?

Totally! The games component of the config accepts an array of game objects, for example:

{
    "api": {
        "discord": {
            "token": "[bot token goes here]"
        }
    },
    "games": [
        {
            "name": "exampleName",
            "prettyName": "Example Name",
            "path": "/tmp/foobar.z5"
        },
        {
            "name": "secondGame",
            "prettyName": "Second Game",
            "path": "/tmp/secondGame.z5"
        },
    ],
    "settings": {
        "commandPrefix": "$",
        "commentPrefix": "//"
    }
}

Is there a way to kill the bot when it's running in the background?

Strange, the bot is specifically built to clean itself up when someone tries to kill it (code). I've tested killing the bot before and it seems to clean up the child process correctly. Perhaps the way you are killing it doesn't trigger Node's process.on("exit", ...? How are you killing it, just with [ctrl]-[c]?

There also isn't a way to kill it via Discord.

True, that might be a good feature to add. #44 opened.

KawaiiFiveO commented 4 years ago

I have the bot running as a background process using npm run start > /dev/null &. When run this way, ps will list 3 different bot processes, two called "node" and one called "sh". I attempted to close all of them via different methods (kill, pkill, killall) etc but these would all cause the terminal to either hang completely or become very buggy, unable to display input text unless cleared with reset. However I did find a working solution by asking fkill to kill the node processes instead of using the built-in tools, so this is basically a non-issue now.

ava-cassiopeia commented 4 years ago

Fair enough, I'll still probably add the feature (since it's pretty easy to do so) at some point. In the meantime, I'm going to close this bug in favor of the followup bugs I created. Feel free to reopen it if you have any other questions or problems.