Class: YAIB::IRC

Inherits:
Object
  • Object
show all
Defined in:
lib/yaib/irc.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, port, nick, name, host, pass, log) ⇒ IRC

Returns a new instance of IRC.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yaib/irc.rb', line 5

def initialize(server, port, nick, name, host, pass, log)
    @log = log
    @log.info("Creating Connection")
    @con = TCPSocket.new(server, port)
    @log.info("Sending Identification")
    send("USER #{nick} #{host} bla :#{name}")
    send("NICK #{nick}")
    @log.info("Getting Response")
    msg = recv
    while msg !~ /^:.* 001.*/
        @log.info("Received: #{msg}")
        if msg =~ /433/
            @log.info("Nickname was taken adding a _")
            nick += "_"
            send("NICK #{nick}")
        end
        msg = @con.recv(512)
    end
    @log.info("Setting nickname variable")
    @nick = nick
end

Instance Method Details

#join(channel) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/yaib/irc.rb', line 37

def join(channel)
    @log.info("Joining #{channel}")
    send("JOIN #{channel}")
    msg = recv
    while msg =~ /25[0-5]/
        msg = nil
        msg = recv unless msg =~ /255/
    end
end

#part(channel) ⇒ Object



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

def part(channel)
    send("PART #{channel}")
end

#recvObject



27
28
29
# File 'lib/yaib/irc.rb', line 27

def recv
    @con.recv(512)
end

#send(s) ⇒ Object



31
32
33
34
35
# File 'lib/yaib/irc.rb', line 31

def send(s)
    s = s.gsub(/\n/,'').gsub(/\r/,'')
    @log.info("Sending: #{s}")
    @con.send(s + "\n", 0)
end