1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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