User wird nicht mehr benachrichtigt, wenn Username Teil von @-Mention ist

This commit is contained in:
Akamaru 2016-02-02 16:13:07 +01:00
parent 3ef8077b94
commit a29be4fd73

View File

@ -4,6 +4,14 @@
-- INFO: Stats must be activated, so that it can collect all members of a group and save his/her id to redis. -- INFO: Stats must be activated, so that it can collect all members of a group and save his/her id to redis.
-- You can deactivate it afterwards. -- You can deactivate it afterwards.
-- See https://stackoverflow.com/a/32854917
function isWordFoundInString(word,input)
return select(2,input:gsub('^' .. word .. '%W+','')) +
select(2,input:gsub('%W+' .. word .. '$','')) +
select(2,input:gsub('^' .. word .. '$','')) +
select(2,input:gsub('%W+' .. word .. '%W+','')) > 0
end
local function pre_process(msg) local function pre_process(msg)
local notify_users = redis:smembers('notify:ls') local notify_users = redis:smembers('notify:ls')
@ -12,7 +20,7 @@ local function pre_process(msg)
if msg.to.type == 'chat' then if msg.to.type == 'chat' then
if msg.text then if msg.text then
for _,user in pairs(notify_users) do for _,user in pairs(notify_users) do
if string.match(string.lower(msg.text), '@'..user) then if isWordFoundInString('@'..user, string.lower(msg.text)) then
local chat_id = msg.to.id local chat_id = msg.to.id
local id = redis:hget('notify:'..user, 'id') local id = redis:hget('notify:'..user, 'id')
-- check, if user has sent at least one message to the group, -- check, if user has sent at least one message to the group,
@ -23,7 +31,7 @@ local function pre_process(msg)
-- ignore message, if it user is mentioning him/herself -- ignore message, if it user is mentioning him/herself
if id == tostring(msg.from.id) then break; end if id == tostring(msg.from.id) then break; end
local send_date = run_bash('date -d @'..msg.date..' +"%d.%m.%Y um %H:%M:%S Uhr"') local send_date = run_command('date -d @'..msg.date..' +"%d.%m.%Y um %H:%M:%S Uhr"')
local send_date = string.gsub(send_date, "\n", "") local send_date = string.gsub(send_date, "\n", "")
local from = string.gsub(msg.from.print_name, "%_", " ") local from = string.gsub(msg.from.print_name, "%_", " ")
local chat_name = string.gsub(msg.to.print_name, "%_", " ") local chat_name = string.gsub(msg.to.print_name, "%_", " ")