comparison mod_muc_inject_mentions/mod_muc_inject_mentions.lua @ 4142:6906562af2ee

mod_muc_inject_mentions: Allow preffixes to be used after a new line
author Seve Ferrer <seve@delape.net>
date Sun, 20 Sep 2020 14:45:58 +0200
parents aef6f5b9f6fd
children b2080f76e0aa
comparison
equal deleted inserted replaced
4141:aef6f5b9f6fd 4142:6906562af2ee
41 if first == 1 then return true end 41 if first == 1 then return true end
42 42
43 -- There are no configured prefixes 43 -- There are no configured prefixes
44 if not prefixes or #prefixes < 1 then return false end 44 if not prefixes or #prefixes < 1 then return false end
45 45
46 -- Preffix must have a space before it 46 -- Preffix must have a space before it,
47 -- or be the first character of the body 47 -- be the first character of the body
48 -- or be the first character after a new line
48 if body:sub(first - 2, first - 2) ~= "" and 49 if body:sub(first - 2, first - 2) ~= "" and
49 body:sub(first - 2, first - 2) ~= " " 50 body:sub(first - 2, first - 2) ~= " " and
51 body:sub(first - 2, first - 2) ~= "\n"
50 then 52 then
51 return false 53 return false
52 end 54 end
53 55
54 local preffix = body:sub(first - 1, first - 1) 56 local preffix = body:sub(first - 1, first - 1)
129 if has_preffix and has_suffix then 131 if has_preffix and has_suffix then
130 table.insert(mentions, {bare_jid=bare_jid, first=first, last=last}) 132 table.insert(mentions, {bare_jid=bare_jid, first=first, last=last})
131 133
132 -- @nickname ... 134 -- @nickname ...
133 elseif has_preffix and not has_suffix then 135 elseif has_preffix and not has_suffix then
134 if body:sub(last + 1, last + 1) == " " then 136 if body:sub(last + 1, last + 1) == " " or
137 body:sub(last + 1, last + 1) == "\n"
138 then
135 table.insert(mentions, {bare_jid=bare_jid, first=first, last=last}) 139 table.insert(mentions, {bare_jid=bare_jid, first=first, last=last})
136 end 140 end
137 141
138 -- nickname: ... 142 -- nickname: ...
139 elseif not has_preffix and has_suffix then 143 elseif not has_preffix and has_suffix then