changeset 167:0d37d18ea073

mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
author Matthew Wild <mwild1@gmail.com>
date Thu, 10 Jun 2010 00:46:46 +0100
parents 75a85eac3c27
children cd8492748985
files mod_pastebin/mod_pastebin.lua
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua	Thu Jun 10 04:35:06 2010 +0500
+++ b/mod_pastebin/mod_pastebin.lua	Thu Jun 10 00:46:46 2010 +0100
@@ -7,6 +7,7 @@
 local add_task = require "util.timer".add_task;
 
 local length_threshold = config.get(module.host, "core", "pastebin_threshold") or 500;
+local line_threshold = config.get(module.host, "core", "pastebin_line_threshold") or 4;
 
 local base_url = config.get(module.host, "core", "pastebin_url");
 
@@ -14,7 +15,7 @@
 local expire_after = math.floor((config.get(module.host, "core", "pastebin_expire_after") or 24) * 3600);
 
 local trigger_string = config.get(module.host, "core", "pastebin_trigger");
-trigger_string = (trigger_string and trigger_string .. " ") or "";
+trigger_string = (trigger_string and trigger_string .. " ");
 
 local pastes = {};
 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" };
@@ -60,8 +61,14 @@
 	
 	--module:log("debug", "Body(%s) length: %d", type(body), #(body or ""));
 	
-	if body and ((#body > length_threshold) or (body:find(trigger_string, 1, true) == 1)) then
-		body = body:gsub("^" .. trigger_string, "", 1);
+	if body and (
+		(#body > length_threshold) or 
+		(trigger_string and body:find(trigger_string, 1, true) == 1) or
+		(select(2, body:gsub("\n", "%0")) >= line_threshold)
+	) then
+		if trigger_string then
+			body = body:gsub("^" .. trigger_string, "", 1);
+		end
 		local url = pastebin_text(body);
 		module:log("debug", "Pasted message as %s", url);		
 		--module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex]));