Software / code / prosody-modules
Comparison
mod_pastebin/mod_pastebin.lua @ 1343:7dbde05b48a9
all the things: Remove trailing whitespace
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Tue, 11 Mar 2014 18:44:01 +0100 |
| parent | 1017:28e3257d2ae5 |
| child | 2766:314cebb3071e |
comparison
equal
deleted
inserted
replaced
| 1342:0ae065453dc9 | 1343:7dbde05b48a9 |
|---|---|
| 57 function handle_request(event, pasteid) | 57 function handle_request(event, pasteid) |
| 58 if not pasteid or not pastes[pasteid] then | 58 if not pasteid or not pastes[pasteid] then |
| 59 event.response.headers = default_headers; | 59 event.response.headers = default_headers; |
| 60 return event.response:send("Invalid paste id, perhaps it expired?"); | 60 return event.response:send("Invalid paste id, perhaps it expired?"); |
| 61 end | 61 end |
| 62 | 62 |
| 63 --module:log("debug", "Received request, replying: %s", pastes[pasteid].text); | 63 --module:log("debug", "Received request, replying: %s", pastes[pasteid].text); |
| 64 | 64 |
| 65 return pastes[pasteid]; | 65 return pastes[pasteid]; |
| 66 end | 66 end |
| 67 | 67 |
| 68 function check_message(data) | 68 function check_message(data) |
| 69 local origin, stanza = data.origin, data.stanza; | 69 local origin, stanza = data.origin, data.stanza; |
| 70 | 70 |
| 71 local body, bodyindex, htmlindex; | 71 local body, bodyindex, htmlindex; |
| 72 for k,v in ipairs(stanza) do | 72 for k,v in ipairs(stanza) do |
| 73 if v.name == "body" then | 73 if v.name == "body" then |
| 74 body, bodyindex = v, k; | 74 body, bodyindex = v, k; |
| 75 elseif v.name == "html" and v.attr.xmlns == xmlns_xhtmlim then | 75 elseif v.name == "html" and v.attr.xmlns == xmlns_xhtmlim then |
| 76 htmlindex = k; | 76 htmlindex = k; |
| 77 end | 77 end |
| 78 end | 78 end |
| 79 | 79 |
| 80 if not body then return; end | 80 if not body then return; end |
| 81 body = body:get_text(); | 81 body = body:get_text(); |
| 82 | 82 |
| 83 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); | 83 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); |
| 84 | 84 |
| 85 if body and ( | 85 if body and ( |
| 86 ((#body > length_threshold) | 86 ((#body > length_threshold) |
| 87 and (utf8_length(body) > length_threshold)) or | 87 and (utf8_length(body) > length_threshold)) or |
| 88 (trigger_string and body:find(trigger_string, 1, true) == 1) or | 88 (trigger_string and body:find(trigger_string, 1, true) == 1) or |
| 89 (select(2, body:gsub("\n", "%0")) >= line_threshold) | 89 (select(2, body:gsub("\n", "%0")) >= line_threshold) |
| 90 ) then | 90 ) then |
| 91 if trigger_string then | 91 if trigger_string then |
| 92 body = body:gsub("^" .. trigger_string, "", 1); | 92 body = body:gsub("^" .. trigger_string, "", 1); |
| 93 end | 93 end |
| 94 local url = pastebin_text(body); | 94 local url = pastebin_text(body); |
| 95 module:log("debug", "Pasted message as %s", url); | 95 module:log("debug", "Pasted message as %s", url); |
| 96 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | 96 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); |
| 97 local summary = (body:sub(1, max_summary_length):gsub(utf8_pattern, drop_invalid_utf8) or ""):match("[^\n]+") or ""; | 97 local summary = (body:sub(1, max_summary_length):gsub(utf8_pattern, drop_invalid_utf8) or ""):match("[^\n]+") or ""; |
| 98 summary = summary:match("^%s*(.-)%s*$"); | 98 summary = summary:match("^%s*(.-)%s*$"); |
| 99 local summary_prefixed = summary:match("[,:]$"); | 99 local summary_prefixed = summary:match("[,:]$"); |
| 100 stanza[bodyindex][1] = (summary_prefixed and (summary.." ") or "")..url; | 100 stanza[bodyindex][1] = (summary_prefixed and (summary.." ") or "")..url; |
| 101 | 101 |
| 102 if html_preview then | 102 if html_preview then |
| 103 local line_count = select(2, body:gsub("\n", "%0")) + 1; | 103 local line_count = select(2, body:gsub("\n", "%0")) + 1; |
| 104 local link_text = ("[view %spaste (%d line%s)]"):format(summary_prefixed and "" or "rest of ", line_count, line_count == 1 and "" or "s"); | 104 local link_text = ("[view %spaste (%d line%s)]"):format(summary_prefixed and "" or "rest of ", line_count, line_count == 1 and "" or "s"); |
| 105 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | 105 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); |
| 106 html:tag("p"):text(summary.." "):up(); | 106 html:tag("p"):text(summary.." "):up(); |