5 # :title: Oxford Dictionary lookup plugin for rbot
7 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 # Copyright:: (C) 2006-2007 Giuseppe Bilotta
13 class OxfordPlugin < Plugin
14 Config.register Config::IntegerValue.new(
17 :desc => 'The number of lines to respond with.')
21 @base_url = "https://www.lexico.com"
24 def help(plugin, topic="")
25 'oxford <word>: check for <word> on the lexico english dictionary (powered by oxford english dictionary).'
29 word = params[:word].join
31 url = "#{@base_url}/definition/#{CGI.escape word}"
34 response = @bot.httputil.get(url, resp: true)
35 definition = parse_definition(response)
38 closest = response.xpath('//div[@class="no-exact-matches"]//ul/li/a').first
40 url = @base_url + closest['href']
42 m.reply "did you mean: #{Bold}#{closest.content.ircify_html}#{NormalText}"
44 response = @bot.httputil.get(url, resp: true)
45 definition = parse_definition(response)
48 m.reply "error accessing lexico url -> #{url}"
54 m.reply definition.ircify_html, max_lines: @bot.config['oxford.max_lines']
56 m.reply "couldn't find a definition for #{word} on oxford dictionary"
62 def parse_definition(r)
63 r.xpath('//section[@class="gramb"]//text()').map(&:content).join(' ')
67 plugin = OxfordPlugin.new
68 plugin.map 'oxford *word', :action => 'oxford', :threaded => true