[ create a new paste ] login | about

Link: http://codepad.org/dLXlHmoG    [ raw code | fork ]

Ruby, pasted on Jan 24:
#!/usr/bin/ruby/
require 'socket'
CHANNEL_POS = 3

def irc_send(msg, channel, sock)
        sock.write msg + "\r\n"
end

def irc_recieved(msg, channel)
        pos = /#{channel}/ =~ msg
        if msg.include? "PRIVMSG #{channel} : " 
                return msg[pos + CHANNEL_POS .. -1]
        end

        return false
end

unless ARGV.length == 2
        puts "usage: ruby rirc.rb <host> <channel>"
        exit 
end     

host = ARGV[0]
channel = ARGV[1]

sock = TCPSocket.open(host, 6667)

sock.write "NICK wowwbot\r\n"
sock.write "USER wowwbot #{host} the bot :Brobot\r\n"
sock.write "JOIN #{channel}\r\n" 

while line = sock.gets
        if line.include? "001"
                puts "Connected to IRC server."
        end     
        
        if irc_recieved(line, channel) == "!8ball"
                puts "!8ball message received"
        end     
end     

sock.close


Create a new paste based on this one


Comments: