HUBOT_TRELLO_KEY and HUBOT_TRELLO_TOKEN to enable Trello subscriptions" return robot.brain.data.trelloSubscriptions ?= {} robot.brain.data.trelloState ?= {} # UTILITIES sendToRooms = (listid, message) -> # Figure out which rooms get this message for roomid of robot.brain.data.trelloSubscriptions if listid in robot.brain.data.trelloSubscriptions[roomid] robot.messageRoom roomid, message isReportable = (listid, action) -> switch action.type when 'updateCard' then action.data.listAfter.id == listid else true listName = (action) -> if action.data.list? action.data.list.name else action.data.listAfter.name updateStateForList = (listid) -> new TrelloApp(robot).fetchAddActionsForList listid, (actions) -> for a in actions when isReportable(listid, a) unless robot.brain.data.trelloState[a.id]? sendToRooms listid, "Trello card '#{a.data.card.name}' added to '#{listName a}'\n" + ":point_right: https://trello.com/c/#{a.data.card.shortLink}" robot.brain.data.trelloState[a.id] = true updateState = -> # Get a set of lists to query listids = {} for roomid of robot.brain.data.trelloSubscriptions for listid in robot.brain.data.trelloSubscriptions[roomid] listids[listid] = true for listid of listids updateStateForList listid # Check status every 30 seconds setInterval updateState, 30*1000 updateState()