21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/absentee_camper/monitor.rb', line 21
def start
log "monitoring room #{Config.room_id} at #{API.base_uri} ..."
url = URI.parse("http://#{Config.token}:[email protected]/room/#{Config.room_id}/live.json")
begin
Yajl::HttpStream.get(url) do |message|
if message['type'] == 'TextMessage'
body = message['body']
log body
body.scan(/@\w+/).each do |mention|
mentioned = mention[1..-1]
if Config.users.keys.include? mentioned
begin
unless users_in_room(@room).map { |u| u['id'] }.include? user_id_from_config(mentioned)
@room.message("[Notified #{mentioned}.]")
NotificationManager.new(Config.users[mentioned]).send_notifications body
end
rescue
log $!
end
end
end
end
end
retry_connection
rescue Yajl::HttpStream::HttpError => e
log "Error connecting to campfire: #{e.message}"
end
end
|