Mercurial > prosody-modules
changeset 501:e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Dec 2011 22:01:54 +0000 (2011-12-08) |
parents | bd08727378be |
children | aad0b2df9e6b |
files | mod_pastebin/mod_pastebin.lua |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua Thu Dec 08 08:17:36 2011 +0000 +++ b/mod_pastebin/mod_pastebin.lua Thu Dec 08 22:01:54 2011 +0000 @@ -19,6 +19,11 @@ return seq; end +local function utf8_length(str) + local _, count = string.gsub(str, "[^\128-\193]", ""); + return count; +end + local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); local length_threshold = module:get_option_number("pastebin_threshold", 500); local line_threshold = module:get_option_number("pastebin_line_threshold", 4); @@ -78,7 +83,8 @@ --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); if body and ( - (#body > length_threshold) or + ((#body > length_threshold) + and (length_utf8(body) > length_threshold)) or (trigger_string and body:find(trigger_string, 1, true) == 1) or (select(2, body:gsub("\n", "%0")) >= line_threshold) ) then