             value = false
         cb value
 
-  withCurrentOncall = (msg, cb) ->
+  withScheduleMatching = (msg, q, cb) ->
+    query = {
+      query: q
+    }
+    pagerDutyGet msg, "/schedules", query, (json) ->
+      if json.schedules and json.schedules.length == 1
+        cb(json.schedules[0])
+      else
+        # maybe look for a specific name match here?
+        msg.send "#{q} matched #{json.schedules.length} schedules. Can you be more specific?"
+        return
+
+  withCurrentOncall = (msg, scheduleId, cb) ->
     oneHour = moment().add('hours', 1).format()
     now = moment().format()
 

      until: oneHour,
      overflow: 'true'
    }
    pagerDutyGet msg, "/schedules/#{pagerDutyScheduleId}/entries", query, (json) ->
      if json.entries and json.entries.length > 0
        cb(json.entries[0].user.name)


    msg.send "Okay, I'll remember your PagerDuty email is #{email}"

  # Assumes your Campfire usernames and PagerDuty names are identical
  robot.respond /pager( me)? (.+) (\d+)$/i, (msg) ->
    campfireUserToPagerDutyUser msg, msg.message.user, (user) ->

      userId = user.id
      return unless userId

      if !msg.match[2] || msg.match[2] == 'me'
        msg.reply "Please specify a schedule with 'pager me ops 60.'' Use 'pager schedules' to list all schedules."
        msg.finish
        return

      withScheduleMatching msg, msg.match[2], (schedule) ->

        scheduleId = schedule.id
        return unless scheduleId

        start     = moment().format()
        minutes   = parseInt msg.match[3]
        end       = moment().add('minutes', minutes).format()
        override  = {
          'start':     start,
          'end':       end,
          'user_id':   userId
        }
        withCurrentOncall msg, scheduleId, (old_username) ->
          data = { 'override': override }
          pagerDutyPost msg, "/schedules/#{scheduleId}/overrides", data, (json) ->
            if json.override
              start = moment(json.override.start)
              end = moment(json.override.end)
              msg.send "Rejoice, #{old_username}! #{json.override.user.name} has the pager on #{schedule.name} until #{end.format()}"

  robot.respond /(pager|major)( me)? incident (.*)$/, (msg) ->
    pagerDutyIncident msg, msg.match[3], (incident) ->
