#!/usr/bin/ruby
server = 'localhost' # 'localhost' 'irc.freenode.net'
port = 6667
channel = '#kolibria' # '#bidule'
nick = 'jessica971'
require 'socket'
socket = TCPSocket.new server, port
["NICK #{nick}", "USER #{nick} 0 * :Jessica From Gwadada", "JOIN #{channel}"].each { |command|
socket.puts command
}
x=0
while line = socket.gets
line.strip!
if line =~ /PING/
socket.puts "PONG"
end
puts line
if line =~ /PRIVMSG ([^ :]+) +:!(.+)/
m, sender, target, command = *line.match(/:([^!]*)![^ ].* +PRIVMSG ([^ :]+) +:!(.+)/)
arg = command[/[^ ]+ +(.+)/, 1]
case command
when /^42/
msg = "The Answer to Life, the Universe, and Everything"
when /^hello/
msg = "#{sender} te dit bonjour, #{arg}" if arg
# autres commandes
#else
# msg = "Unknown command"
end
socket.puts "PRIVMSG #{channel} :#{msg}"
end
end