Class: Lita::Handlers::LockerMisc

Inherits:
Handler
  • Object
show all
Includes:
Locker::Label, Locker::Misc, Locker::Regex, Locker::Resource
Defined in:
lib/lita/handlers/locker_misc.rb

Overview

Misc Locker handlers

Constant Summary

Constants included from Locker::Regex

Locker::Regex::COMMENT_REGEX, Locker::Regex::LABELS_REGEX, Locker::Regex::LABEL_REGEX, Locker::Regex::LOCK_REGEX, Locker::Regex::RESOURCES_REGEX, Locker::Regex::RESOURCE_REGEX, Locker::Regex::UNLOCK_REGEX, Locker::Regex::USER_REGEX

Instance Method Summary collapse

Methods included from Locker::Misc

#failed, #locked, #success, #unlocked, #user_locks

Methods included from Locker::Label

#label_dependencies, #label_ownership

Instance Method Details

#dequeue(response) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/lita/handlers/locker_misc.rb', line 56

def dequeue(response)
  name = response.match_data['label']
  return response.reply(t('subject.does_not_exist', name: name)) unless Label.exists?(name)
  l = Label.new(name)
  l.wait_queue.delete(response.user.id)
  response.reply(t('label.removed_from_queue', name: name))
end

#list(response) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/lita/handlers/locker_misc.rb', line 64

def list(response)
  username = response.match_data['username']
  user = Lita::User.fuzzy_find(username)
  return response.reply(t('user.unknown')) unless user
  l = user_locks(user)
  return response.reply(t('user.no_active_locks')) unless l.size > 0
  composed = ''
  l.each do |label_name|
    composed += "Label: #{label_name}\n"
  end
  response.reply(composed)
end

#log(response) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/lita/handlers/locker_misc.rb', line 40

def log(response)
  name = response.match_data['label']
  return response.reply(failed(t('subject.does_not_exist', name: name))) unless Label.exists?(name)
  l = Label.new(name)
  l.journal.range(-10, -1).each do |entry|
    response.reply(t('label.log_entry', entry: entry))
  end
end

#status(response) ⇒ Object



49
50
51
52
53
54
# File 'lib/lita/handlers/locker_misc.rb', line 49

def status(response)
  name = response.match_data['label']
  return response.reply(status_label(name)) if Label.exists?(name)
  return response.reply(status_resource(name)) if Resource.exists?(name)
  response.reply(failed(t('subject.does_not_exist', name: name)))
end