           s.name == q
         if matchingExactly.length == 1
           schedule = matchingExactly[0]
-
+      cb(schedule)
+
+  withScheduleMatching = (msg, q, cb) ->
+    oneScheduleMatching msg, q, (schedule) ->
       if schedule
         cb(schedule)
       else

        msg.send "No open incidents"

  robot.respond /(pager|major)( me)? (?:trigger|page) ([\w\-]+) (.+)$/i, (msg) ->
    fromUser       = msg.message.user.name
    userOrSchedule = msg.match[3]
    reason         = msg.match[4]
    description    = "#{reason} - @#{fromUser}"

    if campfireUserToPage = robot.brain.userForName(msg.match[3])
      campfireUserToPagerDutyUser msg, msg.message.user, (user) ->

        requesterId = user.id
        return unless requesterId

        pagerDutyIntegrationAPI msg, "trigger", description, (json) ->
          query = {
            incident_key: json.incident_key
          }
          msg.reply ":page: triggered! now assigning it to #{userOrSchedule}..."
          campfireUserToPagerDutyUser msg, campfireUserToPage, (userToPage) ->
            setTimeout () ->
              pagerDutyGet msg, "/incidents", query, (json) ->
                if json?.incidents.length == 0
                  console.log inspect query
                  console.log inspect json
                  msg.reply "Couldn't find the incident we just created to reassign :/"
                else
                  data = {
                    requester_id: requesterId,
                    incidents: json.incidents.map (incident) ->
                      {
                        'id':               incident.id,


                  pagerDutyPut msg, "/incidents", data , (json) ->
                    if json?.incidents.length == 1
                      msg.reply ":page: assigned to #{userToPage.name}!"
                    else
                      console.log inspect data
                      console.log inspect json
                      msg.reply "Problem reassigning the incident :/"
            , 5000

  robot.respond /(?:pager|major)(?: me)? ack(?:nowledge)? (.+)$/i, (msg) ->
    incidentNumbers = parseIncidentNumbers(msg.match[1])
