Module: Balotelli::Core::IRC

Included in:
Base
Defined in:
lib/balotelli/core/irc.rb

Instance Method Summary collapse

Instance Method Details

#configure(host, port, nick, pass = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/balotelli/core/irc.rb', line 6

def configure(host, port, nick, pass = nil)
  @host = host
  @port = port
  @nick = nick
  @pass = pass

  @socket = nil
  @mutex = Mutex.new
end

#connect(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/balotelli/core/irc.rb', line 16

def connect(&block)
  @socket = TCPSocket.new(@host, @port)

  sputs("PASS #{@pass}") if @pass
  sputs("NICK #{@nick}")
  sputs("USER #{@nick} 0 * :#{@nick}")

  if block_given?
    instance_variable_set(:@on_connect, block)
  end
end

#join(channel, password = nil) ⇒ Object



49
50
51
# File 'lib/balotelli/core/irc.rb', line 49

def join(channel, password = nil)
  sputs("JOIN #{channel} #{password}")
end

#names(channel) ⇒ Object



57
58
59
# File 'lib/balotelli/core/irc.rb', line 57

def names(channel)
  sputs("NAMES #{channel}")
end

#pong(message) ⇒ Object



45
46
47
# File 'lib/balotelli/core/irc.rb', line 45

def pong(message)
  sputs("PONG #{message}")
end

#privmsg(channel, message) ⇒ Object



53
54
55
# File 'lib/balotelli/core/irc.rb', line 53

def privmsg(channel, message)
  sputs("PRIVMSG #{channel} :#{message}")
end

#sgetsObject



28
29
30
31
32
33
34
35
# File 'lib/balotelli/core/irc.rb', line 28

def sgets
  str = @socket.gets
  str.chomp! unless str.nil?

  puts '<< ' + str.inspect

  str
end

#sputs(str) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/balotelli/core/irc.rb', line 37

def sputs(str)
  @mutex.synchronize do
    puts '>> ' + str.inspect

    @socket.puts(str)
  end
end