Created
August 23, 2010 20:48
-
-
Save andsve/546307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module("modules/define/define") | |
function parse_message(bot, msg) | |
local i,j,sender,chan,q = string.find(msg, ":(.-)!.- PRIVMSG (.-) :" .. tostring(bot.config.triggerprefix) .. "define (.+)") | |
if not (i == nil) then | |
if not (string.sub(chan, 1, 1) == "#") then | |
chan = sender | |
end | |
local http = require("socket.http") | |
local ltn12 = require("ltn12") | |
q = string.gsub(q, " ", "+") | |
local request_body = "q=define%3A" .. tostring(q) | |
local b, c, h = http.request("http://www.google.com/search?" .. request_body) | |
function get_html_translation_table() | |
local table = {} | |
table['"'] = """ | |
table["'"] = "'" | |
table["&"] = "&" | |
table["<"] = "<" | |
table[">"] = ">" | |
table[" "] = " " | |
table["¡"] = "¡" | |
table["¢"] = "¢" | |
table["£"] = "£" | |
table["¤"] = "¤" | |
table["¥"] = "¥" | |
table["¦"] = "¦" | |
table["§"] = "§" | |
table["¨"] = "¨" | |
table["©"] = "©" | |
table["ª"] = "ª" | |
table["«"] = "«" | |
table["¬"] = "¬" | |
table[""] = "­" | |
table["®"] = "®" | |
table["¯"] = "¯" | |
table["°"] = "°" | |
table["±"] = "±" | |
table["²"] = "²" | |
table["³"] = "³" | |
table["´"] = "´" | |
table["µ"] = "µ" | |
table["¶"] = "¶" | |
table["·"] = "·" | |
table["¸"] = "¸" | |
table["¹"] = "¹" | |
table["º"] = "º" | |
table["»"] = "»" | |
table["¼"] = "¼" | |
table["½"] = "½" | |
table["¾"] = "¾" | |
table["¿"] = "¿" | |
table["×"] = "×" | |
table["÷"] = "÷" | |
table["?"] = "&#%d+;" | |
return table | |
end | |
local a,c,def = string.find(b, '.-Definitions of.-<ul type="disc" class=std><li>(.-)<.+') | |
if not (a == nil) then | |
local t = get_html_translation_table() | |
for k,v in pairs(t) do | |
def = string.gsub(def, v, k) | |
end | |
bot:say(chan, tostring(def)) | |
else | |
bot:say(chan, "Definition not found.") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment