#!/usr/bin/ruby ## ## an experimental irc bot ## require 'socket' channel = '#hackdmz' server = 'ircd.hackdmz.net' port = 6667 username = 'rubybot' hostname = 'hackdmz.net' servername = 'ircd.hackdmz.net' realname = ':rubybot' nick = 'rubybot' TCPSocket.open(server, port) do |sock| sock.puts "USER #{username} #{hostname} #{servername} #{realname}\r\n" sock.puts "Nick #{nick}\r\n" sock.puts "JOIN #{channel}\r\n" while !sock.closed? line = sock.readline.chomp puts "#{line}\n" # Support PING sock.puts "PONG #{$1}\r\n" if line =~ /PING :(.*)/ # echo what people !say me to do sock.puts "PRIVMSG #{channel} :#{$1}\r\n" if line =~ /.*?PRIVMSG #{channel} :!say (.*)/ # Try to get the nowlistening track of a lastfm user if line =~ /.*?PRIVMSG #{channel} :!lfm_nl (.*)/ page = %x[wget -O - http://www.last.fm/user/'#{$1}'] if page =~ /(.*)<\/a> - (.*)<\/a>/ sock.puts "PRIVMSG #{channel} :#{$1} - #{$2}\r\n" end end # try to find out how long a lastfm user has been registered. if line =~ /.*?PRIVMSG #{channel} :!lfm_reg (.*)/ page = %x[wget -O - http://www.last.fm/usr/'#{$1}'] page.each_line do |line| if line =~ /Registered:<\/strong> (.*)$/ sock.puts "PRIVMSG #{channel} :#{$1}\r\n" end end end end end