From 1b311521f5d4bb762d2171b7ea09564d72748c31 Mon Sep 17 00:00:00 2001 From: manveti Date: Tue, 26 May 2015 14:49:33 -0700 Subject: [PATCH 1/5] Update documentation and bump version numbers for roll templates fix --- ExtendedExpressions/package.json | 2 +- cron/Help.txt | 6 +++--- cron/package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ExtendedExpressions/package.json b/ExtendedExpressions/package.json index 545b353f18..eef049ec8d 100644 --- a/ExtendedExpressions/package.json +++ b/ExtendedExpressions/package.json @@ -1,6 +1,6 @@ { "name": "ExtendedExpressions", - "version": "0.1", + "version": "0.2", "description": "Extended roll expression syntax, supporting conditionals, variable references, bitwise operators, and more.", "authors": "manveti", "roll20userid": "503018", diff --git a/cron/Help.txt b/cron/Help.txt index 9ed07782f5..02da773493 100644 --- a/cron/Help.txt +++ b/cron/Help.txt @@ -101,6 +101,6 @@ Examples: around commands which contain tokens which are valid !cron arguments (e.g. "-R"). Without the quotes, this will immediately remove job 42. -!cron -a 1 &{template:default} {{name=Test}} {{foo=bar}} - Note that the "&" must be "&", otherwise the "&{template:default}" will - be consumed by the chat system before the message is passed to the script. +!cron -a 1 &{template:default} {{name=Test}} {{foo=bar}} + As of version 0.5, templates are handled correctly, and do not need (or + support) &-escaping. diff --git a/cron/package.json b/cron/package.json index c40cbad8ed..4ef756bd1e 100644 --- a/cron/package.json +++ b/cron/package.json @@ -1,6 +1,6 @@ { "name": "cron", - "version": "0.4", + "version": "0.5", "description": "Schedule (possibly recurring) commands to run at some point in the future.", "authors": "manveti", "roll20userid": "503018", From e09464f43c94623e25f8b1d020abccd843707db1 Mon Sep 17 00:00:00 2001 From: manveti Date: Tue, 26 May 2015 15:55:15 -0700 Subject: [PATCH 2/5] Fix time zone note in example to match v0.4 switch to GMT --- cron/Help.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cron/Help.txt b/cron/Help.txt index 02da773493..ee0310b04c 100644 --- a/cron/Help.txt +++ b/cron/Help.txt @@ -87,8 +87,8 @@ Examples: roll each round. !cron -f Nanny -t 23:00 Bedtime for sleepy-head. Time to wrap things up. - Be aware that the time zone is based on the API server, not the client who - runs the command. + Be aware that the time zone is GMT, not local time of the client who runs + the command. !cron -a 30 Hey! It's 30 seconds later than when I typed this. Probably more useful with larger delay amounts. From 1bc3e8662b60bde5ba430281e3795be349766d13 Mon Sep 17 00:00:00 2001 From: manveti Date: Tue, 26 May 2015 17:13:51 -0700 Subject: [PATCH 3/5] Fix !exroll with tail and purely-extended expression (e.g. "!extroll 1d3**2 foo"). It turns out that, while "/roll 1" works, "/roll 1 foo" fails, so we need to submit "/r 1d0 + 1 foo" instead. Preserve labels across recursive calls to sendCommand. In certain cases (e.g. "`(1d20[foo]+1)[bar]`, `(${bar}>10?(${foo}=20?"critical hit":"hit"):"miss")`), we'd need to evaluate a tree containing a label before we were done referencing the label. Report errors to the user who invoked the command, rather than just returning the error message (which would discard it, so commands with errors would fail silently). --- ExtendedExpressions/extend.js | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/ExtendedExpressions/extend.js b/ExtendedExpressions/extend.js index 5ced42e423..6a9ce6581b 100644 --- a/ExtendedExpressions/extend.js +++ b/ExtendedExpressions/extend.js @@ -237,7 +237,15 @@ var ExExp = ExExp || { return operands.pop(); }, - sendCommand: function(chunks, asts, evalResults, inline, from){ + + write: function(s, who, style, from){ + if (who){ + who = "/w " + who.split(" ", 1)[0] + " "; + } + sendChat(from, who + s.replace(//g, ">").replace(/\n/g, "
")); + }, + + sendCommand: function(chunks, asts, evalResults, inline, from, labels){ // constants var BINARY_FUNCTIONS = { '||': function(x, y){ return x || y; }, @@ -273,7 +281,7 @@ var ExExp = ExExp || { // local variables - var labels = {}, references = {}, unevalRefs = [], evalReqs = []; + var references = {}, unevalRefs = [], evalReqs = []; // helper functions function lazyEval(t, labels, references, unevalRefs, evalReqs, force){ @@ -488,9 +496,14 @@ var ExExp = ExExp || { if (t.type == "string"){ return t.value; } var retval = flattenAST(t); if (inline){ retval = "[[" + retval + "]]"; } + else if (t.type == "number"){ retval = "1d0 + " + retval; } return retval; } + function reportError(err){ + ExExp.write("Error: " + err, from); + } + // substitute in results of base evaluation for (var i = 0; i < evalResults.length; i++){ var t = evalResults[i][0]; @@ -508,7 +521,7 @@ var ExExp = ExExp || { if (asts[i].baseValid){ continue; } // can be handled by base expression evaluator if ((asts[i].type == "string") || (asts[i].type == "number")){ continue; } // tree is fully evaluated var err = lazyEval(asts[i], labels, references, unevalRefs, evalReqs, false); - if (typeof(err) == typeof("")){ return err; } + if (typeof(err) == typeof("")){ return reportError(err); } } // do variable substitution; repeat until we don't make any more progress @@ -518,12 +531,12 @@ var ExExp = ExExp || { // substitute in values for variables for which we already have names for (var label in references){ if (!labels[label]){ - return "Variable '" + label + "' not defined"; + return reportError("Variable '" + label + "' not defined"); } if ((labels[label].type != "string") && (labels[label].type != "number")){ // variable exists but not yet evaluated; try to evaluate var err = lazyEval(labels[label], labels, references, unevalRefs, evalReqs, true); - if (typeof(err) == typeof("")){ return err; } + if (typeof(err) == typeof("")){ return reportError(err); } } if ((labels[label].type == "string") || (labels[label].type == "number")){ // variable fully evaluated; substitute it in @@ -541,7 +554,7 @@ var ExExp = ExExp || { var newUneval = []; while (unevalRefs.length > 0){ var r = lazyEval(unevalRefs.shift(), labels, references, unevalRefs, evalReqs, true); - if (typeof(r) == typeof("")){ return err; } + if (typeof(r) == typeof("")){ return reportError(err); } if ((r.type == "string") || (r.type == "number")){ doSubstitution = true; } else{ newUneval.push(r); } } @@ -563,25 +576,18 @@ var ExExp = ExExp || { for (var i = 0; i < evalReqs.length; i++){ evalResults.push([evalReqs[i], msg.inlinerolls[i].results.total]); } - ExExp.sendCommand(chunks, asts, evalResults, inline, from); + ExExp.sendCommand(chunks, asts, evalResults, inline, from, labels); }; sendChat(from, cmd, evalRecurse); } if (asts.length > 0){ // need to finish evaluating some ASTs; recurse directly - return ExExp.sendCommand(chunks, asts, [], inline, from) + return ExExp.sendCommand(chunks, asts, [], inline, from, labels) } // if we got here, we're done evaluating everything; submit results via sendChat sendChat(from, chunks.join("")); }, - write: function(s, who, style, from){ - if (who){ - who = "/w " + who.split(" ", 1)[0] + " "; - } - sendChat(from, who + s.replace(//g, ">").replace(/\n/g, "
")); - }, - showHelp: function(who){ var helpMsg = ""; helpMsg += "Usage: !exroll command\n"; @@ -661,7 +667,7 @@ var ExExp = ExExp || { } } chunks.push(state.s); - ExExp.sendCommand(chunks, asts, [], inline, msg.who); + ExExp.sendCommand(chunks, asts, [], inline, msg.who, {}); }, handleChatMessage: function(msg){ From 0abd18d4d03761d9065f23a45605d812f220299e Mon Sep 17 00:00:00 2001 From: manveti Date: Tue, 26 May 2015 17:21:18 -0700 Subject: [PATCH 4/5] Bump version number for substantial bugfix revision --- ExtendedExpressions/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExtendedExpressions/package.json b/ExtendedExpressions/package.json index eef049ec8d..e9bd8e39df 100644 --- a/ExtendedExpressions/package.json +++ b/ExtendedExpressions/package.json @@ -1,6 +1,6 @@ { "name": "ExtendedExpressions", - "version": "0.2", + "version": "0.3", "description": "Extended roll expression syntax, supporting conditionals, variable references, bitwise operators, and more.", "authors": "manveti", "roll20userid": "503018", From 25085403e7a456a62c25243c8ddb0c3d7a594e68 Mon Sep 17 00:00:00 2001 From: manveti Date: Wed, 27 May 2015 16:42:38 -0700 Subject: [PATCH 5/5] Fix bad copypasta --- ExtendedExpressions/extend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExtendedExpressions/extend.js b/ExtendedExpressions/extend.js index 6a9ce6581b..812ad86fdb 100644 --- a/ExtendedExpressions/extend.js +++ b/ExtendedExpressions/extend.js @@ -674,7 +674,7 @@ var ExExp = ExExp || { if (msg.type != "api"){ return; } if ((msg.content.indexOf("!exroll") != 0) && (msg.content.indexOf("!extend") != 0)){ return; } - return ExExp.handleCronMessage(msg.content.split(" "), msg); + return ExExp.handleExExpMessage(msg.content.split(" "), msg); }, registerExExp: function(){