deno.land / x / treebot@v0.0.6 / examples / example.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { TreeBot, TreeTask, BranchTask, LeafTask } from 'https://deno.land/x/treebot/mod.ts'
class IsSunday extends BranchTask { validate() { return (new Date().getDay()) === 0 }
successTask() { return new LogSunday(); }
failureTask() { return new LogNotSunday(); }}
class LogSunday extends LeafTask { execute() { console.log('Its sunday today!') }}
class LogNotSunday extends LeafTask { execute() { console.log('Its not sunday today!') }}
class ExampleBot extends TreeBot { createRootTask(): TreeTask { return new IsSunday(); }
onLoop() { console.log("Loop!!"); }
onStart() { console.log("Started"); }}
const bot = new ExampleBot();bot.run();