Simple Dice Roller Plugin

(Dave Jensen) #1

Continuing the discussion from Brand new plugin interface:

I would like to create a dice roller plugin for the new Axis & Allies .org forums (link to current/old forums but I’m sure many others might want a generic dice roller as well. The site currently has two versions of the dice roller, one is generic and one is specific for Axis & Allies. For this discussion, I’m only interested in the simple, generic version. Once we have something simple to work from, then people can go create their own versions for Axis & Allies, Risk, RPG, etc.

You can see how it currently works on this post. The “mod” updates the post with some html with the dice results. The problem is that the use can update the post and delete (not modify) the results. So the work around has been that game play forums do no allow editing of posts.

In terms of workflow, I’ll try to separate what I want from the solution because maybe there is a better way.

Functional requirements/workflow

  1. User indicates that they are about to roll for something. (optional)
    • “Rolling my attacks for 6 infantry and 1 tank.”
  2. User performs an action to roll dice
    • 6d6 and 1d6
  3. The dice rolling result is posted
    • 1, 2, 4, 1, 3, 6 and 2
  4. User responds to the dice rolls in a post (optional)
    • “Two of my infantry hit and my tank hits for 3 total hits”

Non-functional requirements

  1. Dice results may not be deleted
  2. Dice results may not be edited
  3. Editing/deleting any post in the discussion does not change the dice results
    Basically, dice results are permanent. Preferably only the admin can remove them and only because, for some reason, people really like to “test” the dice roller.

@sam Does this answer your questions and help get the conversation going?

(Dave Jensen) #2

Now for my thoughts for the solution.

The user types a special command in the markdown of their post

I’m going to roll some dice! [dice 6d6 1d6]

When the user hits “post” or “reply” the plugin sees the special command and after the original post is saved/committed, then the plugin makes a new reply, as “dice user,” with the results. If the user goes back and edits out their [dice 6d6 1d6], then it does not remove the dice roll because, as I mentioned, dice rolls should be permanent.

Now the code. I’ve started a gist for this. The following is untested but it’s a possible starting point unless @sam has a better idea (and I’m sure he will :smile:).

(Sam Saffron) #3

I think I understand now. Would something like this work.

User types: Bla bla bla [dice 6d6 1d6]

Preview window shows: Bla bla bla you are about to roll 6d6 and 1d6, this will be permanent

User posts the post, PrettyText on the server injects the actual dice roll AND makes the post only editable by admins.

Post now says: Bla bla bla 1, 2, 4, 1, 3, 6 and 2

I like this cause it does not inject superfluous posts into the stream and still leaves a recourse for editing in outlier cases (user can flag her own post and ask a mod to change)

I think all editing should be guarded in games cause people can muck with context around the dice roll.

(Voxel Pirate) #4

What would prevent the user from posting this text directly into his text, without asking for the roll of a dice? Only the user might see that the post is not anylonger editable, so this might not help to assess if it was a real dice roll or a fake one.

(Sam Saffron) #5

I think it should have a unique CSS class that is only ever assigned to the dice rolling blocks.


Couldn’t that be kinda faked with BBCode? What about an “addition” to the old post, kinda like the metadata shown under the first post? So its not a post in and of itself, but it is in a separate, non-user-editable space.

(Dave Jensen) #7

I do like the idea of meta-data but @sam has a point. Even the context around the dice rolling should be preserved.

I could roll some dice, not like the result, and edit the post to say it was practice. On the other hand, there is still the edit history.

Plugin questions for @sam or others on the Discourse team?

  1. How can I modify a post for something like a special bbcode?
  2. How can I lock (prevent editing) of a post/reply via a plugin?
  3. Can I create meta data for a post like what @nightpool suggests?

(Dave Jensen) #8

It’s been almost a month, I’m still not sure how to execute on this idea. Even just some simple pointers to “start reading the code here” would be super helpful.


(Dorthu) #9

I realize this topic is quite old, but it’s the at the top of the results when googling for “Discourse dice roller,” so I figure it’s worth reviving. I’m writing a plugin that does exactly this - it’s on github here.

(Dave Jensen) #10

I’m actually working on a dice plugin for another modern OSS forum (NodeBB) and for that plugin, I’m have a hook on posts that matches a pattern. When the pattern matches a dedicated “dice bot” user posts the dice rolls. I imagine there would be a way to do this on Discourse as well.

Aside: I’ve decided to deploy NodeBB instead of Discourse (I much prefer the Discourse UI but don’t want to manage a Ruby/SQL stack, prefer Node.js and NoSQL).

(Jeff Atwood) #11

What is there to manage? It is in a Docker container and we push updates to the container. So every six months do a git pull, rebuild, and you are done.

(Erlend Sogge Heggen) #12

Cool! Please start a new topic for this in the #plugin category when you feel like the plugin is ready for primetime :wink:

(Dave Jensen) #13

It’s a personal preference and a control issue :wink:

If something breaks or I want to write a plugin, I prefer Node.js that’s all. No knock against Discourse.

(Jeff Atwood) #14

Wait didn’t @gwwar write this plugin at some point?


I wrote a bot, to work around folks editing their rolls.

Hubot Adapter for Discourse
(Dave Jensen) #16

Very cool. I’ll have to try this out.

(Jeff Atwood) #17

Our official built in greeting bot has die roll functionality now so I suggest using that — see Who is Discobot?