Class: Lita::Handlers::Locker
Overview
Top-level class for Locker
Constant Summary
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
#failed, #locked, #success, #unlocked, #user_locks
#label_dependencies, #label_ownership
Instance Method Details
#lock(response) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/lita/handlers/locker.rb', line 63
def lock(response)
name = response.match_data['label'].rstrip
return response.reply(failed(t('label.does_not_exist', name: name))) unless Label.exists?(name)
l = Label.new(name)
return response.reply(failed(t('label.no_resources', name: name))) unless l.membership.count > 0
return response.reply(t('label.self_lock', name: name)) if l.owner == response.user
return response.reply(success(t('label.lock', name: name))) if l.lock!(response.user.id)
response.reply(label_ownership(name))
end
|
#observe(response) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/lita/handlers/locker.rb', line 93
def observe(response)
name = response.match_data['label']
return response.reply(failed(t('label.does_not_exist', name: name))) unless Label.exists?(name)
l = Label.new(name)
return response.reply(t('observe.already_observing', name: name)) if l.observer?(response.user.id)
l.add_observer!(response.user.id)
response.reply(t('observe.now_observing', name: name))
end
|
#setup_redis(_payload) ⇒ Object
58
59
60
61
|
# File 'lib/lita/handlers/locker.rb', line 58
def setup_redis(_payload)
Label.redis = redis
Resource.redis = redis
end
|
#steal(response) ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/lita/handlers/locker.rb', line 111
def steal(response)
name = response.match_data['label'].rstrip
return response.reply(failed(t('subject.does_not_exist', name: name))) unless Label.exists?(name)
l = Label.new(name)
return response.reply(t('steal.already_unlocked', label: name)) unless l.locked?
response.reply(attempt_steal(name, response.user))
end
|
#unlock(response) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/lita/handlers/locker.rb', line 75
def unlock(response)
name = response.match_data['label'].rstrip
return response.reply(failed(t('subject.does_not_exist', name: name))) unless Label.exists?(name)
l = Label.new(name)
return response.reply(success(t('label.is_unlocked', name: name))) unless l.locked?
response.reply(attempt_unlock(name, response.user))
return if l.locked?
mention_names = l.observers
.map { |observer| observer.mention_name ? "(@#{observer.mention_name})" : '' }
.reject { |mention| mention == '' }
.sort
.join(' ')
response.reply(t('label.unlocked_no_queue', name: name, mention: mention_names)) unless mention_names.empty?
end
|
#unobserve(response) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/lita/handlers/locker.rb', line 102
def unobserve(response)
name = response.match_data['label']
return response.reply(failed(t('label.does_not_exist', name: name))) unless Label.exists?(name)
l = Label.new(name)
return response.reply(t('observe.were_not_observing', name: name)) unless l.observer?(response.user.id)
l.remove_observer!(response.user.id)
response.reply(t('observe.stopped_observing', name: name))
end
|