Software / code / prosody-modules
Comparison
mod_pastebin/mod_pastebin.lua @ 12:316e8437f233
mod_pastebin: Allow configurable message length threshold
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 25 Sep 2009 21:54:16 +0100 |
| parent | 5:9c1c6c5344dc |
| child | 13:135855b685d6 |
comparison
equal
deleted
inserted
replaced
| 10:7d70faba234c | 12:316e8437f233 |
|---|---|
| 1 | 1 |
| 2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 3 local httpserver = require "net.httpserver"; | 3 local httpserver = require "net.httpserver"; |
| 4 local uuid_new = require "util.uuid".generate; | 4 local uuid_new = require "util.uuid".generate; |
| 5 local os_time = os.time; | |
| 5 | 6 |
| 6 local os_time = os.time; | 7 local length_threshold = config.get("*", "core", "pastebin_threshold"); |
| 7 | 8 |
| 8 local base_url; | 9 local base_url; |
| 9 | 10 |
| 10 local pastes = {}; | 11 local pastes = {}; |
| 11 | 12 |
| 44 if not body then return; end | 45 if not body then return; end |
| 45 body = body:get_text(); | 46 body = body:get_text(); |
| 46 | 47 |
| 47 module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); | 48 module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); |
| 48 | 49 |
| 49 if body and #body > 500 then | 50 if body and #body > length_threshold then |
| 50 local url = pastebin_message(body); | 51 local url = pastebin_message(body); |
| 51 module:log("debug", "Pasted message as %s", url); | 52 module:log("debug", "Pasted message as %s", url); |
| 52 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | 53 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); |
| 53 stanza[bodyindex][1] = url; | 54 stanza[bodyindex][1] = url; |
| 54 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | 55 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); |