!7 cmodule NLRulesBot extends DynTalkBot2<.ByServer> { start { makeByServer = () -> new ByServer; useAGIBlueForDropPunctuation = false; preprocessAtSelfToMyName = false; dropPunctuation = false; } sclass Rule { GlobalID globalID = aGlobalIDObj(); bool enabled = true; S text; *() {} *(S *text) {} } S renderRule(Rule r) { ret r == null ? null : "Rule " + r.globalID + (enabled ? "" : " [disabled]") + ": " + r.text; } class ByServer extends DynTalkBot2.ByServer { new L rules; synchronized S processSimplifiedLine(S s, O... _) { try answer super.processSimplifiedLine(s, _); new Matches m; if null (s = dropMyPrefixOrNull(s)) null; if "on * say *|on *, image-google X" { Rule r = firstWhereIC(rules, text := s); if (r != null) ret "Rule exists: " + r.globalID; rules.add(r = new Rule(s)); change(); ret "Rule added with ID " + r.globalID; } if "rules" ret lines(map(r -> renderRule(r), rules)); if "delete rule *|delete rule with id *" { try answer checkAuth(_); Rule r = firstWhere(rules, globalID := GlobalID($1)); if (r == null) ret "Rule " + $1 + " not found"; rules.remove(r); change(); ret "Rule deleted, " + nRule(rules) + " remain"; } if (eqic(s, "help")) ret ltrim([[ I execute simple English rules. Stuff to say. @me on "hello bot" say "who are you" @me masters / add master / delete master @me help / support / source code [Bot made by https://BotCompany.de] ]]).replace("@me", atSelf()); // find rule to execute for (Rule r : rules) pcall { if (!r.enabled) continue; if (match("on * say *", r.text, m)) { S in = $1, out = $2; if (match(in, s, m)) ret out; } } null; } } }