summaryrefslogtreecommitdiff
path: root/scripts/toy.groovy
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-06-24 20:31:12 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-06-24 20:31:12 +0100
commit557cef7e041a18a4c16c19d13870ada293c8eeac (patch)
tree6c5d654d85a1288fb5e5841fd20a142f32c13b9b /scripts/toy.groovy
parentExtract release requests into play module (diff)
downloadtoy-557cef7e041a18a4c16c19d13870ada293c8eeac.zip
Tidy up some misc functions
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r--scripts/toy.groovy30
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()