# TODO: cache results and reuse them if get_cached returns a cache copy\r
\r
DEMAURO_LEMMA = /<anchor>(.*?)(?: - (.*?))<go href="lemma.php\?ID=(\d+)"\/><\/anchor>/\r
+CHAMBERS_LEMMA = /<p><span class="hwd">(.*?)<\/span> <span class="psa">(.*?)<\/span>(.*?)<\/p>/\r
\r
class DictPlugin < Plugin\r
- BotConfig.register BotConfigIntegerValue.new('dict.hits',\r
+ Config.register Config::IntegerValue.new('dict.hits',\r
:default => 3,\r
:desc => "Number of hits to return from a dictionary lookup")\r
- BotConfig.register BotConfigIntegerValue.new('dict.first_par',\r
+ Config.register Config::IntegerValue.new('dict.first_par',\r
:default => 0,\r
:desc => "When set to n > 0, the bot will return the first paragraph from the first n dictionary hits")\r
\r
entries = xml.scan(DEMAURO_LEMMA)\r
text = word\r
urls = []\r
- if !entries.assoc(word) and !entries.assoc(word.upcase)\r
+ if not entries.transpose.first.grep(/\b#{word}\b/)\r
return false if justcheck\r
text += " not found. Similar words"\r
end\r
return unless first_pars > 0\r
\r
Utils.get_first_pars urls, first_pars, :message => m,\r
- :strip => /^\S+\s+-\s+/\r
+ :strip => /^.+?\s+-\s+/\r
\r
end\r
\r
word = params[:word].join\r
[word, word + "_1"].each { |check|\r
url = @oxurl % CGI.escape(check)\r
- h = @bot.httputil.head(url, :max_redir => 5)\r
- if h\r
- m.reply("#{word} found: #{url}") unless justcheck\r
+ if params[:british]\r
+ url << "?view=uk"\r
+ end\r
+ h = @bot.httputil.get(url, :max_redir => 5)\r
+ if h and h.match(%r!<h2>#{word}(?:<sup>1</sup>)?</h2>!)\r
+ m.reply("#{word} : #{url}") unless justcheck\r
+ defn = $'\r
+ m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate)\r
return true\r
end\r
}\r
end\r
\r
def is_british?(word)\r
- return oxford(nil, :word => word, :justcheck => true)\r
+ return oxford(nil, :word => word, :justcheck => true, :british => true)\r
end\r
\r
\r
when /No exact matches for <b>.*?<\/b>, but the following may be helpful./\r
return false if justcheck\r
m.reply "Nothing found for #{word}, but see #{url} for possible suggestions"\r
- else\r
- return true if justcheck\r
- m.reply "#{word}: #{url}"\r
+ return\r
end\r
+ # Else, we have a hit\r
+ return true if justcheck\r
+ m.reply "#{word}: #{url}"\r
+ entries = xml.scan(CHAMBERS_LEMMA)\r
+ hits = @bot.config['dict.hits']\r
+ entries[0...hits].map { |ar|\r
+ m.reply(("#{Bold}%s#{Bold} #{Underline}%s#{Underline}%s" % ar).ircify_html, :overlong => :truncate)\r
+ }\r
end\r
\r
def is_english?(word)\r