Mercurial > prosody-modules
comparison mod_pastebin/mod_pastebin.lua @ 156:b51741b7e86d
mod_pastebin: Optionally bin if message starts with a configurable trigger string
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Sun, 23 May 2010 17:24:09 +0200 |
| parents | 1fc4e8dc66a6 |
| children | 0d37d18ea073 |
comparison
equal
deleted
inserted
replaced
| 155:7a037cb5ab9e | 156:b51741b7e86d |
|---|---|
| 10 | 10 |
| 11 local base_url = config.get(module.host, "core", "pastebin_url"); | 11 local base_url = config.get(module.host, "core", "pastebin_url"); |
| 12 | 12 |
| 13 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours | 13 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours |
| 14 local expire_after = math.floor((config.get(module.host, "core", "pastebin_expire_after") or 24) * 3600); | 14 local expire_after = math.floor((config.get(module.host, "core", "pastebin_expire_after") or 24) * 3600); |
| 15 | |
| 16 local trigger_string = config.get(module.host, "core", "pastebin_trigger"); | |
| 17 trigger_string = (trigger_string and trigger_string .. " ") or ""; | |
| 15 | 18 |
| 16 local pastes = {}; | 19 local pastes = {}; |
| 17 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; | 20 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; |
| 18 | 21 |
| 19 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; | 22 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; |
| 55 if not body then return; end | 58 if not body then return; end |
| 56 body = body:get_text(); | 59 body = body:get_text(); |
| 57 | 60 |
| 58 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); | 61 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); |
| 59 | 62 |
| 60 if body and #body > length_threshold then | 63 if body and ((#body > length_threshold) or (body:find(trigger_string, 1, true) == 1)) then |
| 64 body = body:gsub("^" .. trigger_string, "", 1); | |
| 61 local url = pastebin_text(body); | 65 local url = pastebin_text(body); |
| 62 module:log("debug", "Pasted message as %s", url); | 66 module:log("debug", "Pasted message as %s", url); |
| 63 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | 67 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); |
| 64 stanza[bodyindex][1] = url; | 68 stanza[bodyindex][1] = url; |
| 65 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | 69 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); |
