class Ruboty::Adapters::Hipchat
Public Instance Methods
run()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 13 def run bind connect rescue Interrupt exit end
say(message)
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 20 def say(message) client.say( body: message[:code] ? "/quote #{message[:body]}" : message[:body], from: message[:from], to: message[:original][:type] == "chat" ? message[:to] + "/resource" : message[:to], type: message[:original][:type], ) end
Private Instance Methods
bind()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 67 def bind client.on_private_message(&method(:on_message)) client.on_room_message(&method(:on_message)) client.on_invite(&method(:on_invite)) end
client()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 31 def client @client ||= Xrc::Client.new( jid: jid, nickname: nickname, password: password, room_jid: room_jids.join(","), ) end
connect()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 73 def connect client.connect end
jid()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 42 def jid jid = Xrc::Jid.new(ENV["HIPCHAT_JID"]) jid.resource = "bot" jid.to_s end
nickname()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 63 def nickname ENV["HIPCHAT_NICKNAME"] end
on_invite(message)
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 87 def on_invite(message) client.join(message.from) end
on_message(message)
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 77 def on_message(message) robot.receive( body: message.body, from: message.from, from_name: username_of(message), to: message.to, type: message.type, ) end
password()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 59 def password ENV["HIPCHAT_PASSWORD"] end
room_jids()
click to toggle source
@note HIPCHAT_ROOM_NAME can be ASCII-8BIT
# File lib/ruboty/adapters/hipchat.rb, line 49 def room_jids room_names.map do |room_name| room_name.force_encoding("UTF-8") + "@conf.hipchat.com" end end
room_names()
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 55 def room_names ENV["HIPCHAT_ROOM_NAME"].split(",") end
username_of(message)
click to toggle source
# File lib/ruboty/adapters/hipchat.rb, line 91 def username_of(message) case message.type when "groupchat" Xrc::Jid.new(message.from).resource else client.users[message.from].name end end