Class: Lita::Handlers::Status
Constant Summary
StatusHelper::Regex::PASSWORD_PATTERN, StatusHelper::Regex::STATUS_PATTERN, StatusHelper::Regex::USER_PATTERN
Instance Method Summary
collapse
#find_user
#delete_status, #fetch_password, #fetch_status, #format_status, #remove_password, #retrieve_keys, #store_password, #store_status
Instance Method Details
#get(response) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/lita/handlers/status.rb', line 84
def get(response)
lita_user = find_user response.match_data['user']
if lita_user.nil? && !response.match_data['user'].nil?
return response.reply t('error.no_user', name: response.match_data['user'])
end
lita_user ||= response.user
status = fetch_status lita_user
return response.reply t('error.no_status', name: lita_user.name) if status.nil?
response.reply t('get', name: lita_user.name, status: status)
end
|
#on_behalf_remove(response) ⇒ Object
Allows your status to be removed by bots (EX: IFTTT)
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/lita/handlers/status.rb', line 115
def on_behalf_remove(response)
lita_user = find_user response.match_data['user']
return response.reply t('error.no_user', name: lita_user.name) if lita_user.nil?
stored_password = fetch_password lita_user
if stored_password.eql? response.match_data['password']
delete_status lita_user
return response.reply t('remove', name: lita_user.name)
end
return response.reply t('error.password_nil', action: 'remove', name: lita_user.name) if stored_password.nil?
response.reply t('error.password_mistmatch', action: 'remove', name: lita_user.name)
end
|
#on_behalf_set(response) ⇒ Object
Allows your status to be set by bots (EX: IFTTT)
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/lita/handlers/status.rb', line 73
def on_behalf_set(response)
lita_user = find_user response.match_data['user']
return response.reply t('error.no_user', name: lita_user.name) if lita_user.nil?
stored_password = fetch_password lita_user
if stored_password.eql? response.match_data['password']
return set response, lita_user
end
return response.reply t('error.password_nil', action: 'set', name: lita_user.name) if stored_password.nil?
response.reply t('error.password_mistmatch', action: 'set', name: lita_user.name)
end
|
#password_remove(response) ⇒ Object
132
133
134
135
|
# File 'lib/lita/handlers/status.rb', line 132
def password_remove(response)
remove_password response.user
response.reply_privately t('password.remove', name: response.user.name)
end
|
#password_set(response) ⇒ Object
127
128
129
130
|
# File 'lib/lita/handlers/status.rb', line 127
def password_set(response)
store_password response.user, response.match_data['password']
response.reply_privately t('password.set', name: response.user.name)
end
|
#remove(response) ⇒ Object
109
110
111
112
|
# File 'lib/lita/handlers/status.rb', line 109
def remove(response)
delete_status response.user
response.reply t('remove', name: response.user.name)
end
|
#set(response, lita_user = nil) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/lita/handlers/status.rb', line 64
def set(response, lita_user = nil)
status = response.match_data['status']
lita_user ||= response.user
store_status lita_user, status
response.reply t('set.new', name: lita_user.name)
end
|
#statuses(response) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/lita/handlers/status.rb', line 96
def statuses(response)
ids = retrieve_keys
ids.each do |id|
lita_user = find_user id.gsub('status_', ''), :find_by_id
status = fetch_status lita_user
if status.nil?
response.reply t('error.no_status', name: lita_user.name)
else
response.reply t('get', name: lita_user.name, status: status)
end
end
end
|