Software /
code /
prosody-modules
Comparison
mod_pastebin/mod_pastebin.lua @ 446:56f1c29ee7f1
mod_pastebin: Some experimental summary changes
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 23 Sep 2011 21:15:24 +0100 |
parent | 445:66ca5e4d9f7b |
child | 454:3f101f7a26d0 |
comparison
equal
deleted
inserted
replaced
445:66ca5e4d9f7b | 446:56f1c29ee7f1 |
---|---|
18 end | 18 end |
19 return seq; | 19 return seq; |
20 end | 20 end |
21 | 21 |
22 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); | 22 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); |
23 local max_summary_length = module:get_option_number("pastebin_summary_length", 150); | |
24 local length_threshold = module:get_option_number("pastebin_threshold", 500); | 23 local length_threshold = module:get_option_number("pastebin_threshold", 500); |
25 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); | 24 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); |
25 local max_summary_length = module:get_option_number("pastebin_summary_length", 150); | |
26 local html_preview = module:get_option_boolean("pastebin_html_preview", true); | |
26 | 27 |
27 local base_url = module:get_option_string("pastebin_url"); | 28 local base_url = module:get_option_string("pastebin_url"); |
28 | 29 |
29 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours | 30 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours |
30 local expire_after = math.floor(module:get_option_number("pastebin_expire_after", 24) * 3600); | 31 local expire_after = math.floor(module:get_option_number("pastebin_expire_after", 24) * 3600); |
85 body = body:gsub("^" .. trigger_string, "", 1); | 86 body = body:gsub("^" .. trigger_string, "", 1); |
86 end | 87 end |
87 local url = pastebin_text(body); | 88 local url = pastebin_text(body); |
88 module:log("debug", "Pasted message as %s", url); | 89 module:log("debug", "Pasted message as %s", url); |
89 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | 90 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); |
90 local summary = body:sub(1, max_summary_length):gsub(utf8_pattern, drop_invalid_utf8) or ""; | 91 local summary = (body:sub(1, max_summary_length):gsub(utf8_pattern, drop_invalid_utf8) or ""):match("[^\n]+") or ""; |
91 stanza[bodyindex][1] = summary:match("^([^\n:]*:?)").." "..url; | 92 summary = summary:match("^%s*(.-)%s*$"); |
92 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | 93 local summary_prefixed = summary:match("[,:]$"); |
93 html:tag("p"):text(summary):up(); | 94 stanza[bodyindex][1] = (summary_prefixed and (summary.." ") or "")..url; |
94 html:tag("a", { href = url }):text("[...]"):up(); | 95 |
95 stanza[htmlindex or #stanza+1] = html; | 96 if html_preview then |
97 local line_count = select(2, body:gsub("\n", "%0")); | |
98 local link_text = ("[view %spaste (%d line%s)]"):format(summary_prefixed and "" or "rest of ", line_count, line_count == 1 and "" or "s"); | |
99 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); | |
100 html:tag("p"):text(summary.." "):up(); | |
101 html:tag("a", { href = url }):text(link_text):up(); | |
102 stanza[htmlindex or #stanza+1] = html; | |
103 end | |
96 end | 104 end |
97 end | 105 end |
98 | 106 |
99 module:hook("message/bare", check_message); | 107 module:hook("message/bare", check_message); |
100 if pastebin_private_messages then | 108 if pastebin_private_messages then |