class Ruboty::Adapters::Irc

Public Instance Methods

on_message(message) click to toggle source
# File lib/ruboty/adapters/irc.rb, line 26
def on_message(message)
  if do_auto_encode?
    body = message.body.dup.force_encoding(encoding)
  else
    body = message.body.encode('utf-8', encoding)
  end

  robot.receive(
    type: message.type,
    body: body,
    from: message.from,
    to:   message.to,
  )
end
run() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 15
def run
  irc.on_privmsg(&method(:on_message))
  irc.run!
end
say(message) click to toggle source
# File lib/ruboty/adapters/irc.rb, line 20
def say(message)
  message[:body].each_line do |msg|
    irc.notice(message[:from], ": #{msg}")
  end 
end

Private Instance Methods

channel() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 69
def channel
  ENV['IRC_CHANNEL']
end
do_auto_encode?() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 77
def do_auto_encode?
  ENV['IRC_DISABLE_ENCODE_BODY'] != '1'
end
encoding() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 73
def encoding
  ENV['IRC_ENCODING'] || 'utf-8'
end
irc() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 43
def irc
  @irc ||= Zircon.new(
    server: server,
    port: port,
    channel: channel,
    username: username,
    password: password,
  )
end
password() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 65
def password
  ENV['IRC_PASSWORD']
end
port() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 57
def port
  ENV['IRC_PORT'] || 6667
end
server() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 53
def server
  ENV['IRC_SERVER']
end
username() click to toggle source
# File lib/ruboty/adapters/irc.rb, line 61
def username
  ENV['IRC_USERNAME'] || 'ruboty'
end