mod_pastebin/mod_pastebin.lua
changeset 5876 8aec430ba205
parent 4704 f821eeac0e50
equal deleted inserted replaced
5875:1c8197075d04 5876:8aec430ba205
    98 	if not once then
    98 	if not once then
    99 		s:add_child(replacement);
    99 		s:add_child(replacement);
   100 	end
   100 	end
   101 end
   101 end
   102 
   102 
   103 local line_count_pattern = string.rep("[^\n]*\n", line_threshold + 1):sub(1,-2);
       
   104 
       
   105 function check_message(data)
   103 function check_message(data)
   106 	local stanza = data.stanza;
   104 	local stanza = data.stanza;
   107 
   105 
   108 	-- Only check for MUC presence when loaded on a component.
   106 	-- Only check for MUC presence when loaded on a component.
   109 	if is_component then
   107 	if is_component then
   120 
   118 
   121 	--module:log("debug", "Body(%s) length: %d", type(body), #(body or ""));
   119 	--module:log("debug", "Body(%s) length: %d", type(body), #(body or ""));
   122 
   120 
   123 	if ( #body > length_threshold and utf8_length(body) > length_threshold ) or
   121 	if ( #body > length_threshold and utf8_length(body) > length_threshold ) or
   124 		(trigger_string and body:find(trigger_string, 1, true) == 1) or
   122 		(trigger_string and body:find(trigger_string, 1, true) == 1) or
   125 		body:find(line_count_pattern) then
   123 		(select(2, body:gsub("\n", "%0")) >= line_threshold)
       
   124 	then
   126 		if trigger_string and body:sub(1, #trigger_string) == trigger_string then
   125 		if trigger_string and body:sub(1, #trigger_string) == trigger_string then
   127 			body = body:sub(#trigger_string+1);
   126 			body = body:sub(#trigger_string+1);
   128 		end
   127 		end
   129 		local url = pastebin_text(body);
   128 		local url = pastebin_text(body);
   130 		module:log("debug", "Pasted message as %s", url);
   129 		module:log("debug", "Pasted message as %s", url);