Discourse Frotz - an Interactive Fiction game bot 🎲

Wooah, a new plugin! :tada: This one is a little less serious, though. :video_game:

This is a fully working plugin but will also no doubt evolve as it gets used and I receive feedback.

Discourse Frotz


It’s no longer necessary to @ mention the bot every step of the way. Once in play, just reply to it.

Git repo: GitHub - merefield/discourse-frotz: A plugin that uses Frotz to give you an interactive fiction experience on your Discourse forum

What is it

It’s a ‘bot’ with which to play interactive fiction aka classic text adventure games on your Discourse forum and is essentially an adaptor to the standard and amazing Z-machine interpreter called ‘frotz’ at David Griffith / frotz · GitLab

How to use it

The setup adds two games, you can add more in settings.

Each entry contains a Title, name of the story file, and three calibration settings to cull the returned text to remove the housekeeping text so users see just the story text.

To kick off the interaction you need to @ mention the bot set in settings. After that, replying to a post of theirs is enough.

To list the available games, you first need to mention the bot and ask:

@mybot list games

This will give you the range of options

To start a game type:

start game x substituting x for the option number.

If you want to switch to another game you can do so; the plugin saves your progress on every move so you can return to the first story at any time. The plugin maintains a save for every story for every user that tries it.

To continue an existing game type:

continue game x substituting x for the option number.

NB A full rebuild will destroy all save files. This is a necessary compromise.

How do I play an IF game?

Many “Meta’s” will have grown up with these things. For those less familiar, check out this cheatsheet: Play Some Interactive Fiction

Setup

Create the Bot User

(apologies, automating this is on my list!)

In an ssh session, enter your container and the rails console:

./launcher enter app
rails c

Then do this:

u = User.create!(username: "Frotz", name: "FrotzBot", id:-5, email: "not@really.valid")
u.activate

Your new bot will then be available to set up in the UI. Go to the user’s settings in the UI via the admin button and turn off all emailing. Update the avatar to taste.

Install Discourse Frotz

Update your app.yml

This is a little more invasive than a usual plugin.

add this to app.yml:

hooks:
  after_code:
    - exec:
        cd: $home
        cmd:
          - git clone https://gitlab.com/DavidGriffith/frotz
    - exec:
        cd: $home/frotz
        cmd:
          - make dfrotz
    - exec:
        cd: $home/frotz
        cmd:
          - mkdir savegames
    - exec:
        cd: $home/frotz
        cmd:
          - mkdir streams
    - exec:
        cd: $home/frotz
        cmd:
          - mkdir stories
    - exec:
        cd: $home/frotz/stories
        cmd:
          - wget --no-check-certificate http://www.batmantis.com/zorks/zork1.z5
    - exec:
        cd: $home/frotz/stories
        cmd:
          - wget --no-check-certificate http://www.douglasadams.com/creations/hhgg.z3
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/merefield/discourse-frotz

before your other plugin entries.

Rebuild with the usual ./launcher rebuild app

Now go to the plugin settings and select the bot user you added earlier:

Stories

You will note I’ve included a couple of stories. You can find more at https://ifdb.tads.org/.
However, watch rate limits here! Getting too many stories from the same location may cause an error.

Also note that the stories are not sitting on https protected servers (tut tut).

If you insist on loading more add them to app.yml. You could also add them manually from the command prompt, but realise these will be wiped on the next full rebuild.

Enable FrotzBot for private messages (caution advised)

Allows users to play in private, but usage will be less transparent. If you have a big enough server this may not be an issue for you. In any case be aware of implications for capacity. As an alternative, encourage users to play in a designated Category.

image
default: OFF

If (s)he is not enabled there, the user will get a polite message:

Restrict FrotzBot by Category

You can restrict the bot to a (list of) Category to avoid filling up other areas:

Limitations and considerations

Not all story formats and games are yet supported. I’ve found some that use paged formatting and so don’t work very well.

NB Mailing list mode is a disaster with this, so make sure this is not something you use before attempting to use this plugin!

It is arguably a bit wasteful of forum resources as it requires at least two posts for every ‘move’. It is obviously often more appropriate to play these kind of games using a chat interface, rather than a forum, but you might argue this could be used to create Walkthroughs? :wink: Having said that, we have the popular Babble chat plugin which uses the same Topic and Post models and probably generates even more data. I have not tested it with Babble btw.

For a less invasive solution, consider: Turning a topic into interactive fiction ;)

Architectural Considerations

Before I created this, I thought about utilising the existing RESTful service credited below (and in plugin.rb), but I felt this would over complicate the setup. It would require users to set up a separate server. Instead, I decided to port that code into my code and extend it as a local service. I may regret that decision though as clearly there is always a maintenance overhead with these things. I can’t promise I won’t switch to or add a RESTful interface later on.

Feedback

All feedback is welcome!

Credits

This plugin exploits two main repos:

Thanks to @P16 for allowing me to use excerpts of code from a closed source chatbot we worked on together.

35 Likes

Wooah, back again!

New Feature-rettes

Enable FrotzBot for private messages (at your peril! :wink: )

Allows users to play in private, but usage will be less transparent. If you have a big enough server this may not be an issue for you.

https://github.com/merefield/discourse-frotz/commit/cf8c459307c50adeb4f7eccd39071bdf076dfdc9

image
default: OFF

If (s)he is not enabled there, the user will get a polite message:

Restrict to a list of Categories, or allow all:

https://github.com/merefield/discourse-frotz/commit/b621c91f9e145d4511b7d1b649c10f3044ceb356


default: ON for all Categories

9 Likes

Hi Robert! Thank you, I really like this plugin !
I tried to install it on dev environment (without docker) and my system asked for the ncursesw lib when making dfrotz, after installing that it worked, will it be the case with a prod env with docker?

1 Like

I tested on Production and building on Docker (to my surpirse) worked out of the box. Feel free to deploy to a Production instance and let me know how you get on.

Glad you like it!!

2 Likes

For those like me, who might loose their last few hairs about that:

hhgg.z3,9,7,3
that’s :

  story_header_lines = 9
  story_load_lines = 7
  story_save_lines = 3

and now, how to adapt it… :sweat_smile:, that’s an adventure inside an adventure…!

1 Like

I’m currently working with the maintainer of Frotz to see if we can do away with those. It’s an approach I ported from restful-Frotz but hardly perfect :slight_smile:

1 Like

Yes ! found it !
kheper.z8,20,15,4 almost works
for this one :


:smiley:

it’s nothing, but there is something weird

) Line-type display OFF
Compression mode MAX, hiding top 0 lines

is displayed once by Pause() with

[Pause notNeeded;
@read_char 1 notNeeded;
rtrue;
];

1 Like

Ha, yeah, there are lots of quirks and a considerable amount of variety in the stories. I cannot promise to support all.

Right now my focus is on:

  1. simplifying code
  2. making the code more secure
  3. adding formatting where pragmatic.

#3 is surprisingly hard.

1 Like

I’ve pushed some improvements to a feature branch:

This does away with the silly suppression settings, introduces translation to BBCode to support formatting and colour, leverages the Dumb Frotz command line options better, obviates the need to write to a text stream and squashes a vulnerability.

This branch requires the official BBCode plugin to be installed.

I’m still experimenting with it. Feel free to do so too.

I’ll probably merge after some significant trials.

1 Like

Does the plugin need the whole frotz repo clone or does it just need $home/frotz/dfrotz to exist? Because I’d rather just compile it once and save the binary between rebuilds.

Not sure why you would care? The resources we are talking about are comparatively tiny. (6MB for the entire repo post make versus Gigabytes for the forum?). It clones the whole repo, then just makes dfrotz. Perhaps that is slightly wasteful, but the simplicity and repeatability is more important I feel. I could go into greater detail and perform a sparse clone, but that would make the build script more complex and less robust. Would it be worth it? Feel free to suggest an optimisation. This is all building inside the container, so will get cleaned whenever the container does.

I’m just trying to optimize for my tiny server, not asking you to change the general install.

1 Like

This is a really cool plugin! This reminds me of a “classic” computer game that was created years ago(I forgot the name).

3 Likes

It’s a great suggestion for a future optimisation if I can keep it simple and robust. Thanks!

1 Like

Yes there are many playable classics. More via the link in the OP.

2 Likes