This repository has been archived by the owner. It is now read-only.
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (68 sloc) 2.75 KB
# Description:
# Decides where you should go
# Dependencies:
# None
# Configuration:
# None
# Commands:
# hubot remember <location> as a <group> location - Remembers the location for the group
# hubot forget <location> as a <group> location - Forgets the location from the group
# hubot forget all locations for <group> - Forgets all the locations for the group
# hubot where can we go for <group>? - Returns a list of places that exist for the group
# hubot where should we go for <group>? - Returns a randomly selected location for the group
# Author:
# lukesmith
class Locations
constructor: (@robot) -> = {}
add: (groupname, name) ->
if[groupname] is undefined[groupname] = []
for location in[groupname]
if location.toLowerCase() is name.toLowerCase()
return[groupname].push name
remove: (groupname, name) ->
group =[groupname] or [][groupname] = (location for location in group when location.toLowerCase() isnt name.toLowerCase())
removeAll: (groupname) ->
group: (name) ->
return[name] or []
module.exports = (robot) ->
locations = new Locations robot
robot.respond /(remember|add) (.*) as a (.*) location/i, (msg) ->
locationname = msg.match[2]
locationgroup = msg.match[3]
locations.add locationgroup, locationname
if locationname.toLowerCase() is "nandos"
msg.send "Nom peri peri. My fav."
robot.respond /forget (.*) as a (.*) location/i, (msg) ->
locationname = msg.match[1]
locationgroup = msg.match[2]
locations.remove locationgroup, locationname
msg.send "I've forgotten #{locationname} from #{locationgroup}"
robot.respond /forget all locations for (.*)/i, (msg) ->
locationgroup = msg.match[1]
locations.removeAll locationgroup
msg.send "I've forgotten all locations from #{locationgroup}"
robot.respond /where can we go for (.*)\?$/i, (msg) ->
locationgroup = msg.match[1]
grouplocations =
if grouplocations.length > 0
for location in grouplocations
msg.send location
msg.send "I don't know anywhere to go for #{locationgroup}"
robot.respond /where (should|shall) we go for (.*)\?$/i, (msg) ->
locationgroup = msg.match[2]
grouplocations =
if grouplocations.length is 0
msg.send "I dont know anywhere to go for #{locationgroup}"
location = msg.random grouplocations
msg.send "I think you should go to #{location}"