If you want to use the Online Dice Roller capabilities in your app, you
can use the official API to do that. Here's how it works!
Dice Room Data
A JSON feed of your dice room log is available at
https://rolz.org/api/roomlog?room=lobby^ you can replace "lobby" with your room name. The data will typically look like this:
{ "room": { "key": "4261", "name": "lobby", "created": "1289487891", "data": { "motd": "This is the lobby where you can meet up and/or try out the dice rooms.", "motd_from": "udo" } }, "items": [ { "type": "txtmsg", "from": "Nanana", "text": "test", "key": "716707", "h_time": "2015-03-23 21:14 UTC", "time": "1427145274", "room_id": "4261" } ] }There are several kinds of messages, as indicated by the "type" field:
txtmsg, dicemsg, timeinfo, and srvmsg
.
Numerical timestamps are given in Unix time, all times are UTC.
Dice Room Client API
Tools like Greasemonkey and
Tampermonkey allow people to customize
the functionality of their websites. The Rolz.org dice rooms have JavaScript
hooks you can use for that purpose:
-
document.onMessage: by setting this variable to your own handler
function you can listen in on all room messages that are coming from the
server.
Example:document.onMessage = function(msg) { console.log(msg) }
-
document.onMessageRender: If you define this you can modify the message
HTML before it's put into the document. This is the place where you would insert
link or image HTML. document.onMessageRender(html, msg) expects that you return the
HTML should be rendered on the screen.
Example:document.onMessageRender = function(html, msg) { return('!'+html); }
- document.isActive: this is a variable you can read from your script to determine if the window or tab containing Rolz is currently active or in the background.
Posting Text to a Dice Room
As the owner of a room, you can allow text to be posted through an API. To enable this,
enter your room and use the command
By default, using this API function will return the dice roll message in JSON format. Alternatively, you can use the 'redirect' parameter to instead force a redirect to your dice room or table:
/room api=onThen use the command
/room infoto show your room's ID number. Make note of that number. After that, you will be able to post text to your room by issuing requests like this:
https://rolz.org/api/post?room=ID&text=TEXT&from=MYAPPAs the ID parameter, use the room's ID number. TEXT can be any text up to 1kb in length. You can embed dice codes in TEXT by using the square bracket syntax like this: "axe attack [d20 18-20=x2] damage [d12+10]". The 'from' parameter is an optional user name you can use to post as.
By default, using this API function will return the dice roll message in JSON format. Alternatively, you can use the 'redirect' parameter to instead force a redirect to your dice room or table:
https://rolz.org/api/post?room=ID&text=TEXT&from=MYAPP&redirect=dr^ will redirect you to your Dice Room
https://rolz.org/api/post?room=ID&text=TEXT&from=MYAPP&redirect=table^ will redirect you to your Table
Dice Rolling API
Access to the REST API is available via the base URL
https://rolz.org/api/?
To get back a roll result, just append the die code to the URL:
https://rolz.org/api/?6d6
This example gets you the result of 6D6 in an extended stringlist text format like this:
result=11 details= [ 1+1+2+3+1+3 ] code=6d6 illustration=<span class="dc_dice_a">6</span><span class="dc_dice_d">D6</span> timestamp=1248210819You can also choose from the available result formats explicitly:
https:///api/?6d6.json^ returns a JSON array containing the result (you probably want this one).
https://rolz.org/api/?6d6.txt^ delivers in the extended text list format.
https://rolz.org/api/?6d6.simple^ gets you just the result number.
https://rolz.org/api/?6d6.xml^ returns an XML document containing the result.
Downloads
C# Dice Code Parser
A long time ago, I wrote a rudimentary C# Dice Code Parser class.
You can download it here.