#!/usr/bin/ruby # # simpleclient.rb # require 'socket' require 'open-uri' client = TCPSocket.new('mush.pennmush.org',4201) client.puts "connect bombur rubybot" definitions = Hash.new("something I don't know") while line = client.readline line.downcase! # Make the line all lower case if line =~ /^(.*) says, "bombur, (.*)"/ who = $1 command = $2 case command when /^salute!$/ client.puts "pose waves to #{who}" when /^reverse (.*)$/ client.puts "say #{$1.reverse}" when /^(.*?) is (.*?)$/ definitions[$1] = $2 client.puts "say ok" when /^(.*)\?$/ client.puts "say #{$1} is #{definitions[$1]}" when /^fetch datarealms titles$/ client.puts "say fetching!" file = open("http://feeds.feedburner.com/datarealms?format=xml",'r') body = file.read file.close # Close the file to clean up titles = [] client.puts "say parsing!" body.scan(/[\s\S]*?<\/item>/) do |item| if item =~ /(.*)<\/title>/ titles << $1 end end client.puts "say " + titles.join(', ') end end end