#!/usr/local/bin/ruby
require 'aimbot.rb'
DICTCMD = "dict --html"
CHATS = ["TicToc"]
MAXWORD = 32
BLKSIZE = 380
BRTAG = "
"
def define(ab, c, w)
d = ""
a = []
p = IO::popen("#{DICTCMD} '#{w}'", 'r')
while p.gets
l = chomp
if (d.length + (l.length + BRTAG.length)) > BLKSIZE
a << d
d = ""
else
d+= BRTAG + l
end
end
a << d unless d.empty?
p.close
if a.length <= 3
dt = 0.5
elsif a.length <= 5
dt = 1
else
dt = 1.5
end
a.each do |s|
ab.chat(c, s)
sleep dt
end
end
def resp(ab, c, sn, m)
s = "[#{sn}: #{m}]"
if c
ab.chat(c, s)
else
ab.im(sn, s)
end
end
ab = AIMBot::new
CHATS.each {|c| ab.join(c)}
ab.run do |m|
mf = false
if m =~ /^<([^:]+):([^>]+)> \.def (.*)$/
c, n, w = $1, $2, $3
mf = true
elsif m =~ /^<\*([^*]+)\*> (.*)$/
c, n, w = nil, $1, $2
end
if mf
if w.length > MAXWORD
resp(ab, c, s, "Word is more than #{MAXWORD} characters")
elsif w !~ /^[\w\s]+$/
resp(ab, c, n, "Word contains illegal characters")
else
resp(ab, c, n, "Looking up \"#{w}\"")
define(ab, c, w)
end
sleep 2.5
end
end