Sha256: 8c068a57685c276b7577dc379fd804312e9269d2a7a11ebc562c6e9ba3d12954

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

# based on :
# https://github.com/sr/shout-bot
#
# libs to take note of :
# https://github.com/tbuehlmann/ponder
# https://github.com/cinchrb/cinch
# https://github.com/cho45/net-irc

require "socket"

class IrcClient
  attr_accessor :channel, :socket

  def initialize(server, nick, options = {})
    @socket = TCPSocket.open(server, options[:port] || 6667)
    socket.puts "PASS #{options[:password]}" if options[:password]
    socket.puts "NICK #{nick}"
    socket.puts "USER #{nick} #{nick} #{nick} :#{nick}"
  end

  def join(channel, key = nil)
    self.channel = channel
    socket.puts "JOIN ##{self.channel} #{key}".strip
  end

  def run(&block)
    instance_eval(&block) if block_given?
  end

  def leave
    socket.puts "PART ##{channel}"
  end

  def say(message)
    socket.puts "PRIVMSG ##{channel} :#{message}" if channel
  end

  def quit
    socket.puts "QUIT"
    socket.gets until socket.eof?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/irc_client.rb