Mercurial > prosody-modules
comparison mod_pastebin/mod_pastebin.lua @ 75:3c7189e26848
mod_pastebin: Rename pastebin_message() to pastebin_text() and make it global so it can be called by other plugins
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 01 Nov 2009 01:10:02 +0000 |
| parents | 3c18c2d03bc2 |
| children | 1fc4e8dc66a6 |
comparison
equal
deleted
inserted
replaced
| 74:d70813f7d90a | 75:3c7189e26848 |
|---|---|
| 16 local pastes = {}; | 16 local pastes = {}; |
| 17 | 17 |
| 18 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; | 18 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; |
| 19 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; | 19 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; |
| 20 | 20 |
| 21 local function pastebin_message(text) | 21 function pastebin_text(text) |
| 22 local uuid = uuid_new(); | 22 local uuid = uuid_new(); |
| 23 pastes[uuid] = { text = text, time = os_time() }; | 23 pastes[uuid] = { text = text, time = os_time() }; |
| 24 pastes[#pastes+1] = uuid; | 24 pastes[#pastes+1] = uuid; |
| 25 if not pastes[2] then -- No other pastes, give the timer a kick | 25 if not pastes[2] then -- No other pastes, give the timer a kick |
| 26 add_task(expire_after, expire_pastes); | 26 add_task(expire_after, expire_pastes); |
| 55 body = body:get_text(); | 55 body = body:get_text(); |
| 56 | 56 |
| 57 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); | 57 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); |
| 58 | 58 |
| 59 if body and #body > length_threshold then | 59 if body and #body > length_threshold then |
| 60 local url = pastebin_message(body); | 60 local url = pastebin_text(body); |
| 61 module:log("debug", "Pasted message as %s", url); | 61 module:log("debug", "Pasted message as %s", url); |
| 62 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | 62 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); |
| 63 stanza[bodyindex][1] = url; | 63 stanza[bodyindex][1] = url; |
| 64 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | 64 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); |
| 65 html:tag("p"):text(body:sub(1,150)):up(); | 65 html:tag("p"):text(body:sub(1,150)):up(); |
