From 9f4e1b7be10509149ecdb3176c4066fac13b6866 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sun, 31 Jan 2016 19:09:09 +0100 Subject: [PATCH] =?UTF-8?q?Suche=20f=C3=BCr=20Aka's=20Blog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/akasblog_search.lua | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 plugins/akasblog_search.lua diff --git a/plugins/akasblog_search.lua b/plugins/akasblog_search.lua new file mode 100644 index 0000000..7a23e84 --- /dev/null +++ b/plugins/akasblog_search.lua @@ -0,0 +1,94 @@ +do + +local makeOurDate = function(dateString) + local pattern = "(%d+)%-(%d+)%-(%d+)" + local year, month, day = dateString:match(pattern) + return day..'.'..month..'.'..year +end + +local function search_post(tag) + local url = 'http://akamaru.de/?json=get_search_results&search='..tag + local res,code = http.request(url) + local data = json:decode(res).posts[1] + if code ~= 200 then return "HTTP-Fehler" end + if not data then return "Nichts gefunden!" end + + local title = data.title + -- Character encoding + title = string.gsub(title, "´", "´") + title = string.gsub(title, "&", "&") + title = string.gsub(title, ">", ">") + title = string.gsub(title, """, '"') + title = string.gsub(title, "<", "<") + title = string.gsub(title, "—", "—") + title = string.gsub(title, "∇", "∇") + title = string.gsub(title, "–", "–") + title = string.gsub(title, "Ψ", "ψ") + title = string.gsub(title, "ψ", "ψ") + title = string.gsub(title, "»", "»") + title = string.gsub(title, "ß", "ß") + title = string.gsub(title, "™", "™") + title = string.gsub(title, "&", "&") + title = string.gsub(title, "'", "'") + title = string.gsub(title, "'", "'") + title = string.gsub(title, "|", "|") + title = string.gsub(title, " ", " ") + title = string.gsub(title, "»", "»") + title = string.gsub(title, "ß", "ß") + title = string.gsub(title, "–", "–") + title = string.gsub(title, "’", "'") + title = string.gsub(title, "“", "“") + title = string.gsub(title, "”", "”") + title = string.gsub(title, "„", "„") + title = string.gsub(title, "‹", "‹") + title = string.gsub(title, "€", "€") + -- Ä Ö Ü + title = string.gsub(title, "ä", "ä") + title = string.gsub(title, "Ä", "Ä") + title = string.gsub(title, "ä", "ä") + title = string.gsub(title, "Ä", "Ä") + title = string.gsub(title, "ö", "ö") + title = string.gsub(title, "Ö", "Ö") + title = string.gsub(title, "ö", "ö") + title = string.gsub(title, "Ö", "Ö") + title = string.gsub(title, "ü", "ü") + title = string.gsub(title, "Ü", "Ü") + title = string.gsub(title, "ü", "ü") + title = string.gsub(title, "Ü", "Ü") + + local from = data.author.name + local date = makeOurDate(data.date) + local content = string.match(data.excerpt, '

(.*)

') + local url = data.url + if data.thumbnail then + image_url = data.thumbnail + end + + local text = title..' ('..from..' am '..date..')\n\n'..content..'...\n'..url + + if data.thumbnail then + return text, image_url + else + return text + end +end + +local function run(msg, matches) +local tag = matches[1] + local text, image_url = search_post(tag) + local receiver = get_receiver(msg) + if image_url then + local file = download_to_file(image_url) + send_photo(receiver, file, ok_cb, false) + end + return text +end + +return { + description = "Suche für Aka's Blog", + usage = "/aka [BEGRIFF]", + patterns = {"^/[Aa][Kk][Aa] (.*)$"}, + run = run +} + +end \ No newline at end of file