Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions ExtendedExpressions/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>"));
},

sendCommand: function(chunks, asts, evalResults, inline, from, labels){
// constants
var BINARY_FUNCTIONS = {
'||': function(x, y){ return x || y; },
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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); }
}
Expand All @@ -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, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>"));
},

showHelp: function(who){
var helpMsg = "";
helpMsg += "Usage: !exroll command\n";
Expand Down Expand Up @@ -661,14 +667,14 @@ var ExExp = ExExp || {
}
}
chunks.push(state.s);
ExExp.sendCommand(chunks, asts, [], inline, msg.who);
ExExp.sendCommand(chunks, asts, [], inline, msg.who, {});
},

handleChatMessage: function(msg){
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(){
Expand Down
2 changes: 1 addition & 1 deletion ExtendedExpressions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ExtendedExpressions",
"version": "0.1",
"version": "0.3",
"description": "Extended roll expression syntax, supporting conditionals, variable references, bitwise operators, and more.",
"authors": "manveti",
"roll20userid": "503018",
Expand Down
10 changes: 5 additions & 5 deletions cron/Help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 &amp;{template:default} {{name=Test}} {{foo=bar}}
Note that the "&" must be "&amp;", 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) &amp;-escaping.
2 changes: 1 addition & 1 deletion cron/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down