diff options
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r-- | scripts/toy.groovy | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 93d231b..bfebfc4 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -129,6 +129,14 @@ return new Object() { void setAway(String a) { save("toy.owner.away", a) } int randRange(int min, int max) { min + getRandom(1 + max - min) } int randRange(double min, double max) { randRange((int)min, (int)max) } + def setDefault = { prop, val -> + if (loadString(prop) == null) { + save(prop, val); + } + }; + // This exists because calling .wait(t) in a metaClass method + // calls it on the metaClass, not on the original object + void pause(int t) { wait(t); } // Events static class Event { @@ -290,38 +298,24 @@ return new Object() { adjustPunish(5); return false; }; + final activityList = [:]; final addActivity = { String name, func -> activityList[name] = func; } - // Setup - def setDefault = { prop, val -> - if (loadString(prop) == null) { - save(prop, val); - } - }; - def namedEvents = [ - permit: { name, arg, schedTime, rt -> givePermission(arg) } - ]; - def showFaq = { - useUrl("http://toy.randomdan.homeip.net/"); - }; + final namedEvents = [:]; final addNamedEvent = { String name, func -> namedEvents[name] = func; } - def requestables = [ - faq: [ lbl: "FAQ (webpage)", act: showFaq ], - ]; + + final requestables = [:]; final addRequestable = { String name, String label, func, cond = null -> requestables[name] = [lbl: label, act: func, cond: cond]; }; final removeRequestable = { String name -> requestables.remove(name); }; - // This exists because calling .wait(t) in a metaClass method - // calls it on the metaClass, not on the original object - void pause(int t) { wait(t); } String main() |