Mercurial > prosody-modules
comparison mod_pastebin/mod_pastebin.lua @ 3027:ce34cbc10b5b
mod_pastebin: Move result of host detection into a variable to improve readabily
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 20 May 2018 17:47:39 +0200 |
parents | 26fe44c68791 |
children | ded630a87563 |
comparison
equal
deleted
inserted
replaced
3026:b2c9b832612b | 3027:ce34cbc10b5b |
---|---|
5 local os_time = os.time; | 5 local os_time = os.time; |
6 local t_insert, t_remove = table.insert, table.remove; | 6 local t_insert, t_remove = table.insert, table.remove; |
7 local add_task = require "util.timer".add_task; | 7 local add_task = require "util.timer".add_task; |
8 local jid_bare = require "util.jid".bare; | 8 local jid_bare = require "util.jid".bare; |
9 local muc_rooms; | 9 local muc_rooms; |
10 if module:get_host_type() == "component" then | 10 local is_component = module:get_host_type() == "component"; |
11 if is_component then | |
11 muc_rooms = module:depends "muc".rooms; | 12 muc_rooms = module:depends "muc".rooms; |
12 end | 13 end |
13 | 14 |
14 local utf8_pattern = "[\194-\244][\128-\191]*$"; | 15 local utf8_pattern = "[\194-\244][\128-\191]*$"; |
15 local function drop_invalid_utf8(seq) | 16 local function drop_invalid_utf8(seq) |
27 local function utf8_length(str) | 28 local function utf8_length(str) |
28 local _, count = string.gsub(str, "[^\128-\193]", ""); | 29 local _, count = string.gsub(str, "[^\128-\193]", ""); |
29 return count; | 30 return count; |
30 end | 31 end |
31 | 32 |
32 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); | 33 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", not is_component); |
33 local length_threshold = module:get_option_number("pastebin_threshold", 500); | 34 local length_threshold = module:get_option_number("pastebin_threshold", 500); |
34 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); | 35 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); |
35 local max_summary_length = module:get_option_number("pastebin_summary_length", 150); | 36 local max_summary_length = module:get_option_number("pastebin_summary_length", 150); |
36 local html_preview = module:get_option_boolean("pastebin_html_preview", true); | 37 local html_preview = module:get_option_boolean("pastebin_html_preview", true); |
37 | 38 |
72 | 73 |
73 function check_message(data) | 74 function check_message(data) |
74 local origin, stanza = data.origin, data.stanza; | 75 local origin, stanza = data.origin, data.stanza; |
75 | 76 |
76 -- Only check for MUC presence when loaded on a component. | 77 -- Only check for MUC presence when loaded on a component. |
77 if module:get_host_type() == "component" then | 78 if is_component then |
78 local room = muc_rooms[jid_bare(stanza.attr.to)]; | 79 local room = muc_rooms[jid_bare(stanza.attr.to)]; |
79 if not room then return; end | 80 if not room then return; end |
80 | 81 |
81 local nick = room._jid_nick[stanza.attr.from]; | 82 local nick = room._jid_nick[stanza.attr.from]; |
82 if not nick then return; end | 83 if not nick then return; end |