From a29be4fd73b5cd5ae2835fcb05a116af50ec7936 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Tue, 2 Feb 2016 16:13:07 +0100 Subject: [PATCH] User wird nicht mehr benachrichtigt, wenn Username Teil von @-Mention ist --- plugins/notifyme.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/notifyme.lua b/plugins/notifyme.lua index ad86b12..709c0ec 100644 --- a/plugins/notifyme.lua +++ b/plugins/notifyme.lua @@ -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. -- 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 notify_users = redis:smembers('notify:ls') @@ -12,7 +20,7 @@ local function pre_process(msg) if msg.to.type == 'chat' then if msg.text then 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 id = redis:hget('notify:'..user, 'id') -- 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 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 from = string.gsub(msg.from.print_name, "%_", " ") local chat_name = string.gsub(msg.to.print_name, "%_", " ")