From ca1042d3c2269486da04c079c7449063653f4255 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Tue, 19 May 2015 22:15:45 -0400 Subject: [PATCH] queue management --- package.json | 4 +++- scripts/q.coffee | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/q.coffee diff --git a/package.json b/package.json index 7060e43..77cbfcf 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "author": "Bob Bergman ", "description": "A simple helpful robot for your Company", "dependencies": { + "cron": "^1.0.9", "hubot": "^2.12.0", "hubot-business-cat": "^1.1.19", "hubot-diagnostics": "0.0.1", @@ -20,7 +21,8 @@ "hubot-scripts": "^2.5.16", "hubot-shipit": "^0.2.0", "hubot-victory": "^1.3.0", - "hubot-youtube": "^0.1.2" + "hubot-youtube": "^0.1.2", + "time": "^0.11.3" }, "engines": { "node": "0.10.x" diff --git a/scripts/q.coffee b/scripts/q.coffee new file mode 100644 index 0000000..f858994 --- /dev/null +++ b/scripts/q.coffee @@ -0,0 +1,39 @@ +next = () -> + rotation = robot.brain.get('rotation') + current = robot.brain.get('current') + if current == null || typeof current == "undefined" + current = roation[0] + else + location = rotation.indexOf current + if location < 0 || location == (rotation.length - 1) + current = rotation[0] + else + current = rotation[location + 1] + robot.brain.set('current', current) + robot.messageRoom ROOM, "#{current} is now Queue boss" + +update = new cronJob trigger, + -> + next() + null + true + TIMEZONE + +robot.respond /q add (.*)/i, (res) -> + rotation = robot.brain.get('rotation') + if rotation == null || typeof rotation == "undefined"? + rotation = [] + rotation.push res.match[0] + robot.brain.set "rotation", rotation + +robot.respond /q remove (.*)/i, res() -> + rotation = robot.brain.get('rotation') + current = robot.brain.get('current') + if(current == res.match[0]) + res.send "User is currently on rotation" + else + rotation = rotation.filter (word) -> current + robot.brain.set('rotation', rotation) + +robot.respond /q next/i, (res) -> + next()