5 # :title: Oxford Dictionary lookup plugin for rbot
7 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 # Copyright:: (C) 2006-2007 Giuseppe Bilotta
12 class OxfordPlugin < Plugin
13 Config.register Config::IntegerValue.new('oxford.hits',
15 :desc => "Number of hits to return from a dictionary lookup")
16 Config.register Config::IntegerValue.new('oxford.first_par',
18 :desc => "When set to n > 0, the bot will return the first paragraph from the first n dictionary hits")
22 @oxurl = "http://www.oxforddictionaries.com/definition/english/%s"
25 def help(plugin, topic="")
26 'oxford <word>: check for <word> on the oxford english dictionary.'
30 justcheck = params[:justcheck]
32 word = params[:word].join
33 [word, word + "_1"].each { |check|
34 url = @oxurl % CGI.escape(check)
38 h = @bot.httputil.get(url, :max_redir => 5)
40 defs = h.split("<span class=\"definition\">")
41 defs = defs[1..-1].map {|d| d.split("</span>")[0]}
43 return false if justcheck
44 m.reply "#{word} not found"
47 m.reply("#{word}: #{url}") unless justcheck
49 m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate)
56 return oxford(nil, :word => word, :justcheck => true, :british => true)
60 plugin = OxfordPlugin.new
61 plugin.map 'oxford *word', :action => 'oxford', :threaded => true