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
# 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}")

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

#join(channel, password = nil) ⇒ Object



47
48
49
# File 'lib/balotelli/core/irc.rb', line 47

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

#names(channel) ⇒ Object



55
56
57
# File 'lib/balotelli/core/irc.rb', line 55

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

#pong(message) ⇒ Object



43
44
45
# File 'lib/balotelli/core/irc.rb', line 43

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

#privmsg(channel, message) ⇒ Object



51
52
53
# File 'lib/balotelli/core/irc.rb', line 51

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

#sgetsObject



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

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

  puts '<< ' + str.inspect

  str
end

#sputs(str) ⇒ Object



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

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

    @socket.puts(str)
  end
end