From 94949a9a0bc637905447a0dd666958ea5f08e729 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 28 Jul 2012 18:41:07 +0100 Subject: Simple XEP script for Swiftob diff --git a/Swiftob/scripts/xep.lua b/Swiftob/scripts/xep.lua new file mode 100644 index 0000000..7d73c97 --- /dev/null +++ b/Swiftob/scripts/xep.lua @@ -0,0 +1,54 @@ +last_fetched = 0 +xeps_by_number = {} +xeps_by_shortname = {} + +function parse_xeps(body) + for xep_string in body:gmatch(".-") do + local number = xep_string:match("(.+)") + local name = xep_string:match("(.+)") + local xeptype = xep_string:match("(.+)") + local status = xep_string:match("(.+)") + local updated = xep_string:match("(.+)") + local shortname = xep_string:match("(.+)") + local abstract = xep_string:match("(.+)"):gsub("\n", "") + xep = {number=number, name=name, type=xeptype, status=status, updated=updated, shortname=shortname, abstract=abstract} + xeps_by_number[tonumber(number)] = xep + xeps_by_shortname[shortname] = xep + end +end + +function update_xeps() + local http = require("socket.http") + http.TIMEOUT = 5 + if os.time() > (last_fetched + 30 * 60) then + b, c, h = http.request("http://xmpp.org/extensions/xeps.xml") + if c == 200 then + last_fetched = os.time() + parse_xeps(b) + end + end +end + +function xep_to_string(xep) + return "XEP-"..xep["number"].."(Shortname "..xep["shortname"].."): "..xep["name"].."\n"..xep["type"].."/"..xep["status"].." Updated: "..xep["updated"] +end + +function xep_command(command, params, message) + update_xeps() + local xep_number = tonumber(params) + local xep + if xep_number then + xep = xeps_by_number[xep_number] + else + xep = xeps_by_shortname[params] + end + local reply + if xep then + reply = xep_to_string(xep) + else + reply = "Sorry, that XEP doesn't seem to exist" + end + swiftob_reply_to(message, reply) +end + +swiftob_register_command("xep", "Anyone", "Lookup XEP data", xep_command) -- cgit v0.10.2-6-g49f6