3 DEMAURO_LEMMA = /<anchor>(.*?)(?: - (.*?))<go href="lemma.php\?ID=(\d+)"\/><\/anchor>/
\r
4 class DeMauroPlugin < Plugin
\r
7 @dmurl = "http://www.demauroparavia.it/"
\r
8 @wapurl = "http://wap.demauroparavia.it/"
\r
12 def help(plugin, topic="")
\r
13 return "demauro <word> => provides a link to the definition of the word from the Italian dictionary De Mauro/Paravia"
\r
16 def demauro(m, params)
\r
17 parola = params[:parola].downcase
\r
18 url = @wapurl + "index.php?lemma=#{URI.escape(parola)}"
\r
19 xml = @bot.httputil.get(url)
\r
21 info = @bot.httputil.last_response
\r
22 info = info ? "(#{info.code} - #{info.message})" : ""
\r
23 m.reply "An error occurred while looking for #{parola}#{info}"
\r
26 if xml=~ /Non ho trovato occorrenze per/
\r
27 m.reply "Nothing found for #{parola}"
\r
30 entries = xml.scan(DEMAURO_LEMMA)
\r
32 if !entries.assoc(parola) and !entries.assoc(parola.upcase)
\r
33 text += " not found. Similar words"
\r
36 text += entries[0...5].map { |ar|
\r
37 "#{ar[0]} - #{ar[1].gsub(/<\/?em>/,'')}: #{@dmurl}#{ar[2]}"
\r
43 plugin = DeMauroPlugin.new
\r
44 plugin.map 'demauro :parola', :action => 'demauro'
\r