diff mod_pastebin/mod_pastebin.lua @ 156:b51741b7e86d

mod_pastebin: Optionally bin if message starts with a configurable trigger string
author Florian Zeitz <florob@babelmonkeys.de>
date Sun, 23 May 2010 17:24:09 +0200
parents 1fc4e8dc66a6
children 0d37d18ea073
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua	Fri May 21 19:24:57 2010 +0200
+++ b/mod_pastebin/mod_pastebin.lua	Sun May 23 17:24:09 2010 +0200
@@ -13,6 +13,9 @@
 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours
 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 "";
+
 local pastes = {};
 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" };
 
@@ -57,7 +60,8 @@
 	
 	--module:log("debug", "Body(%s) length: %d", type(body), #(body or ""));
 	
-	if body and #body > length_threshold then
+	if body and ((#body > length_threshold) or (body:find(trigger_string, 1, true) == 1)) then
+		body = body:gsub("^" .. trigger_string, "", 1);
 		local url = pastebin_text(body);
 		module:log("debug", "Pasted message as %s", url);		
 		--module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex]));