Code Monkey home page Code Monkey logo

discord-text-adventure-bot's Introduction

Discord Text Adventure Bot

Build Status npm version

This is a Node.js bot for Discord that allows you to play classic text adventures (such as Zork) in Discord. It is not hosted for you, so you will have to run it yourself.


Roadmap

This is a list of eventual upgrades that will be made to the project.

  • Host the base bot code as a NPM project, so it can be installed as a NPM global command
  • Ability to run multiple different games on different channels
  • Ability to save state of game

Game Support

This bot uses an implementation of Frotz as its interpreter for text adventure games, called Dumb Frotz. So anything that runs in/on Frotz can be run by this bot.

Generally speaking, that means any game with a .z[number] file extension. Please open an issue if you find a game that does not work well with this bot.

How to Use

You must have Dumb Frotz installed on the machine that will run the bot, so that Frotz can be run from the command line, IE:

dfrotz /path/to/my/game.z5

Please refer to the Installing Dumb Frotz section below for more details.

You must also have Node and NPM installed.

Once you have Dumb Frotz and Node installed, refer to the installation section.

Installing Dumb Frotz

If you are a Windows user, you have a pre-compiled version of dfrotz available here (see the dfrotz.zip file). All you have to do is add the dfrotz.exe file to your PATH and you will be good to go!

For macOS and Linux users, you'll need to manually compile the lastest version of Frotz in its "dumb" mode. This is well documented on the Frotz GitLab page.

Installation

See below for the two different methods on installing the actual bot. You can either install it from NPM or manually; whatever works for you best.

NPM Installation

You can install the bot software from NPM. You'll still need to install Dumb Frotz, but you can get the bot by running the following:

npm i -g discord-frotz

Then, wherever you want, create a configuration file called discord-frotz.config.json, based on the config.json.example file available in this repository.

Once the config file is created, just run discort-frotz from the same directory as the discord-frotz.config.json config file, and it will use that config file to start the bot.

If you set up everything correctly, the bot should be online in your server and ready to play. Refer to the Bot Commands section for more information.

Manual Installation

First, clone or download the latest version of the project from the Releases section here on Github. Then, cd to project root and install all dependencies:

npm install

After that, remove the .example from config.json.example and fill in the information inside that file accordingly. You will need to create a bot user to get the token. Refer to the "Creating a Bot User" section below for more information.

Once your config.json file is set up, make sure that the bot user that you created is added to the Discord server where you want the bot to output to.

Then, run node app.js or npm run start from project root to start the bot.

If you set up everything correctly, the bot should be online in your server and ready to play. Refer to the Bot Commands section for more information.

Creating a Bot User

To create a bot user, follow these steps:

  1. Go to the Discord site and sign in (or make an account)
  2. Once you are signed in, follow this link to get to the developer page
  3. Click on the "My Apps" section on the left side (if you aren't already in that section), and then click "New App" and setup your new app. This app will wrap your bot user, so name it appropriately
  4. On the new app's page, click the "Create a Bot User" button
  5. Click the "click to reveal" button next to the Token section in the bot user this is the token that you will use in the api.discord.token field in the config.json

That's all the steps to create your bot user. The last step required is adding the bot user to your server, if you would like:

To add the bot user, following the instructions found here. These instructions are for a python server but they apply just the same to your bot as well.

After the bot user is added, you can boot up the application and interact with it normally in your server.

Bot Commands

The bot has a set of commands that can be run to load games and play.

Get Bot Info

Useage: $info

Will cause the bot to print out its current state.

Get Bot Help

Useage: $help

Prints out help information on how to use the bot.

List Available Games

Usage: $list

Lists all available games (based on your config.json file).

Set Target Output Channel

Useage: $targetChannel

Will set the target output channel to the channel in which this message was sent. You must set this before starting a game, or you will not see the output of the game.

Set Target Listening Channel

Usage: $adventureListenChannel

Will set the channel that this command is typed in the be the only channel that accepts commands for the bot.

Start an Adventure

Useage: $start [gameName]

Starts the specified gamename, which is the name specified in the config.json.

Quit an Adventure

Useage: $quit or $q

Quits the current game. Will only work when in game mode (aka when a game has been started with the $start command).

Set Yourself as Bot Admin

Useage: $admin [admincode]

Sets your Discord account (the one that sends the $admin ... message) as the admin account for the bot. The admin account has special priviledges and can run special commands.

You can and should send this message in a private message to the bot, as the admin code will be visible in chat history for anyone to see otherwise.

Kill the Bot

Useage: $qqq

This command can only be run by a bot admin.

Stops the currently running game, closes the connection with Discord, and kills the bot.

Config

As mentioned prior, all config should live in config.json, and an example config is provided for you: config.json.example

Development

Tests

Tests are written using Mocha, and run with the following:

npm run test

Linting

Linting uses eslint and is run with the following:

npm run lint

You can also run eslint with the automated --fix flag using:

npm run lint-fix

Issues, Bugs, Questions, Suggestions

If you find a bug, have an issue with the implementation, or just have a suggestion, please just open an issue. I'll try to respond to you as quickly as possible. Don't bother getting frustrated, I'll happily help you set up an instance of this bot if you get stuck.

Legal

The name "Discord" is copyright and trademarked Discord Inc.

discord-text-adventure-bot's People

Contributors

ava-cassiopeia avatar dependabot[bot] avatar jifish avatar thesofox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discord-text-adventure-bot's Issues

DiscordAPIError: Invalid Form Body content: Must be 2000 or fewer in length.

Zork Zero crashes the bot at move 6 with the following console output:

discord-frotz\node_modules\discord.js\src\rest\RequestHandler.js:154
      throw new DiscordAPIError(request.path, data, request.method, res.status);
            ^

DiscordAPIError: Invalid Form Body
content: Must be 2000 or fewer in length.
    at RequestHandler.execute (C:\msys64\home\exander\Development\frotzbot\node-v16.13.0-win-x64\node_modules\discord-frotz\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\msys64\home\exander\Development\frotzbot\node-v16.13.0-win-x64\node_modules\discord-frotz\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/910621836138676234/messages',
  code: 50035,
  httpStatus: 400
}

Improve Installation Guide

After speaking with a few people trying to use this bot, its clear my installation guide should cover specifics better.

Bot now works on Windows

Hey, thanks for writing this fun bot! It runs just fine now on Windows 10, so you can remove the disclaimer from the main page. It does require a newer version of discord.io (the solution to izy521/discord.io#234 describes how to install this version), since the current version is broken.

Listing multiple games.

I've got the bot running but can't seem to figure out how to add multiple games. Can you give an example of a config.json file with more than one game?

CRASH ON $start A

crash on game load and yes i got dfrotz.exe but where do i place it in what path and who to get a .z5 game to run

Loaded Game: A
events.js:183
throw er; // Unhandled 'error' event
^

Error: spawn dfrotz ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

Write Basic Tests

Write basic unit tests for the application. May need to mock the Discord Bot object to get more advanced tests.

don't encode UTF-8

My terminal locale is UTF-8, my dfrotz puts plain Unicode (not ASCII) output, so the bot encodes Unicode twice into gibberish.

Here's a patch: src/MessageHandler.js, like 310

-    var final = stripAnsi(utf8.encode(this.compiledOutput));
+    var final = stripAnsi(this.compiledOutput);

Messed up formatting on responses.

Hi! Great bot. I've been looking for something just like this.

I've been getting some screwed up formatting in my responses. I was wondering if this is something fixable.

Some examples:

JiFish - Today at 6:09 PM
$look
frotz-botBOT - Today at 6:09 PM
look
1
West of House
You are standing in an open field west of a white house, with a boarded front
oor.
There is a small mailbox here.
>
JiFish - Today at 6:09 PM
$w
frotz-botBOT - Today at 6:09 PM
w
Forest       5
Forest
This is a forest, with trees in all directions. To the east, there appears to besunlight.
>
$take
frotz-botBOT - Today at 6:11 PM
take
dWhat do you want to take?
>

Other the the obvious issues, I'm not sure if repeating your command and the ">" prompt is intentional or part of my issue. If either of those are, is there a way to exclude those?

I don't mind dipping in to the code if required, but I would appreciate some pointers.

unable to start game

Loaded Game: zork
events.js:182
throw er; // Unhandled 'error' event
^

Error: spawn dfrotz ENOENT
at _errnoException (util.js:1021:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

z5 files stuck in loading

Hi! I was able to run the bot successfully.
But I found out it only works with .z3 files.
I'm unsure if .z5 files are supported.

Thank you!

Need help.

So i have everything installed but Idk how to set the bot up please help.

Cannot install discord bot, not working for some reason.

I have node.js and npm installed

C:>npm i -g discord-frotz
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for [email protected]: wanted {"os":"!win32","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! notsup Valid OS: !win32
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: win32
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR!

CRASH ON $start A (Raspian)

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

Migrate From discord.io to discord.js

Discord.io has unfortunately caused, or seems to be causing, some issues for users (#39, #34). To that end, I think it's time to switch over to discord.js. I've used it before on other projects with great success, and I don't think the translation process should be too hard.

Add Support for Discord Character Limit to the Bot

Currently, if the bot produces a message that is too long for the Discord single-message character limit, the bot crashes, as seen in #53. Improve the bot by making it split up messages that are too long, noting that we need to maintain some level of consistent formatting.

Running on Raspberry Pi

I'm trying to run this on a raspberry pi and am running into an issue when I try to launch, I'm assuming that it's because some version of node or something is too old, but I'm unsure.

to be clear: dfrotz is installed and runs. I tried both the npm install and manual install of discord-text-adventure-bot, both went smooth. But then when I launch either install I get the following error:

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/home/greg/discord-text-adventure-bot/client-spawner.js:1:86)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)

running 'node --use_strict app.js' returns:

discord-text-adventure-bot/MessageHandler.js:157
    setTargetChannel(channelID, notify = false, doWrite = true){
                                                                     ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/home/greg/discord-text-adventure-bot/client-spawner.js:1:86)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)

I've run into errors before while running programs on the raspberry pi where the packages I was using were a bit out of date. I'm assuming something similar is here, but don't know enough to figure out the specifics. Any ideas?

And thanks. This is a cool project.

Implement Saving

Implement the ability to save the game using the command $save.

Should have a limit to 3 saves per game, and will save all the saves in saves/[gamename]/.

Discord Times Out After Too Long

The Discord API will time out after too long if there is no activity for the bot. This should be fixed by either renewing the connection on timeout or in some way keeping the connection alive longer.

Bot Gives Near-Meaningless Error When It Fails to Find Game File

Definitely caused #39 and probably #34.

The bot gives fairly meaningless errors when write() is called to the dfrotz subprocess but its been closed because dfrotz self-destructed when given a bad file path.

The bot itself should verify game file's existence ahead of this to give the user a more meaningful error.

Really simple issue.....

I preface this by saying I am a layman with anything like this.

But really would like to get this working as a discord bot.

System: Windows 10 pro

Issue: The initial steps.

This is probably an issue with my understanding more than anything.

I have downloaded all the bot files the .json etc.

I have also downloaded dfrotz from the website as instructed as a windows user.

I am then stuck on the next sentence:

"All you have to do is add the dfrotz.exe file to your PATH and you will be good to go!"

I have no idea what to do next, pretty much, and as a layman, don't understand what I have to do.

Do I have to open a cmd prompt in windows and execute something from there?

The dfrotz.exe does not seem to do anything when clicked on....a brief window....then nothing.

So clearly, I am not understanding the instruction.

Apologies for being a bit of a dunce.

Regards

(Suggestion) Ability to run multiple games on different channels.

The ability to run multiple games on different channels (and even servers) from a single bot would be a nice addition. Something like $adventureStart gamename #channel. One game per channel would allow easy reference to running games. e.g. $adventureStop #channel.

A MessageHandler could be created for each channel, and a new administration handler to maintain them. A fairly large change.

Can't get bot to work

I'm using Ubuntu on windows 10, I followed the instructions, I opened the bash in my folder where the config file is and ran "npm i -g discord-frotz", everything seemed to go fine, (had to use sudo) but where do I find the discort-frotz and how do I run it?

bot isnt starting up

hi, ive done everything in the instructions,
now when i start the bot using node app.js it just kind of sits there and does nothing and the bot doesnt go online

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.