+ # If we return a single, full result, change the output to a more compact representation
+ if single
+ m.reply "Result for %s: %s -- %s" % [what, results, Utils.get_first_pars(urls, first_pars)], :overlong => :truncate
+ return
+ end
+
+ m.reply "Results for #{what}: #{results}", :split_at => /\s+\|\s+/
+
+ return unless first_pars > 0
+
+ Utils.get_first_pars urls, first_pars, :message => m
+
+ end
+
+ def gcalc(m, params)
+ what = params[:words].to_s
+ searchfor = CGI.escape(what)
+
+ debug "Getting gcalc thing: #{searchfor.inspect}"
+ url = GOOGLE_SEARCH + searchfor
+
+ begin
+ html = @bot.httputil.get(url)
+ rescue => e
+ m.reply "error googlecalcing #{what}"
+ return
+ end
+
+ debug "#{html.size} bytes of html recieved"
+
+ results = html.scan(GOOGLE_CALC_RESULT)
+ debug "results: #{results.inspect}"
+
+ if results.length != 1
+ m.reply "couldn't calculate #{what}"
+ return
+ end
+
+ result = results[0][0].ircify_html
+ debug "replying with: #{result.inspect}"
+ m.reply "#{result}"
+ end
+
+ def gdef(m, params)
+ what = params[:words].to_s
+ searchfor = CGI.escape("define " + what)
+
+ debug "Getting gdef thing: #{searchfor.inspect}"
+ url = GOOGLE_WAP_SEARCH + searchfor
+
+ begin
+ html = @bot.httputil.get(url)
+ rescue => e
+ m.reply "error googledefining #{what}"
+ return
+ end
+
+ debug html
+ results = html.scan(GOOGLE_DEF_RESULT)
+ debug "results: #{results.inspect}"
+
+ if results.length != 1
+ m.reply "couldn't find a definition for #{what} on Google"
+ return
+ end
+
+ head = results[0][0].ircify_html
+ text = results[0][1].ircify_html
+ link = results[0][2]
+ m.reply "#{head} -- #{link}\n#{text}"