From 354a714362a3c9b503d04156b5e131d215c82744 Mon Sep 17 00:00:00 2001 From: Reyas Mohammed Ismail Date: Wed, 15 Nov 2017 08:18:46 +0530 Subject: [PATCH 1/5] Added blacklist option --- lua/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config.lua b/lua/config.lua index aad14ff1c..705c7869d 100644 --- a/lua/config.lua +++ b/lua/config.lua @@ -221,7 +221,7 @@ local _M = }, chat_hashes = {'extra', 'info', 'links', 'warns', 'mediawarn', 'spamwarns', 'blocked', 'report', 'defpermissions', 'defpermduration'}, - chat_sets = {'whitelist'},--, 'mods'}, + chat_sets = {'whitelist', 'blacklist'},--, 'mods'}, bot_keys = { d3 = {'bot:general', 'bot:usernames', 'bot:chat:latsmsg'}, d2 = {'bot:groupsid', 'bot:groupsid:removed', 'tempbanned', 'bot:blocked', 'remolden_chats'} --remolden_chats: chat removed with $remold command From 1a623e4c0ec84b515af2f14e23cea6294dada3ea Mon Sep 17 00:00:00 2001 From: Reyas Mohammed Ismail Date: Wed, 15 Nov 2017 08:47:26 +0530 Subject: [PATCH 2/5] blacklist added --- lua/plugins/onmessage.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/plugins/onmessage.lua b/lua/plugins/onmessage.lua index ccdcbe72b..ee6893f0e 100644 --- a/lua/plugins/onmessage.lua +++ b/lua/plugins/onmessage.lua @@ -67,6 +67,18 @@ local function is_whitelisted(chat_id, text) end end +local function is_blacklisted(chat_id, text) + local set = ('chat:%d:blacklist'):format(chat_id) + local links = db:smembers(set) + if links and next(links) then + for i=1, #links do + if text:match(links[i]:gsub('%-', '%%-')) then + return true + end + end + end +end + function plugin.onEveryMessage(msg) if not msg.inline then @@ -120,7 +132,14 @@ function plugin.onEveryMessage(msg) local media = msg.media_type local hash = 'chat:'..msg.chat.id..':media' local media_status = (db:hget(hash, media)) or config.chat_settings.media[media] - if media_status ~= 'ok' then + local blacklisted + if media == 'link' then + blacklisted = is_blacklisted(msg.chat.id, msg.text) + end + + if blacklisted then + api.deleteMessage(msg.chat.id, msg.message_id) + elseif media_status ~= 'ok' then local whitelisted if media == 'link' then whitelisted = is_whitelisted(msg.chat.id, msg.text) From 328e724d1a7c88c713eed8eb45fcef0964fe9b5d Mon Sep 17 00:00:00 2001 From: Reyas Mohammed Ismail Date: Wed, 15 Nov 2017 08:57:41 +0530 Subject: [PATCH 3/5] Added blacklist --- lua/plugins/antispam.lua | 76 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/lua/plugins/antispam.lua b/lua/plugins/antispam.lua index 7bfbb30e4..57fa69783 100644 --- a/lua/plugins/antispam.lua +++ b/lua/plugins/antispam.lua @@ -372,6 +372,73 @@ function plugin.onTextMessage(msg, blocks) db:srem(('chat:%d:whitelist'):format(msg.chat.id), blocks[2]) api.sendReply(msg, 'Done') end + + if (blocks[1] == 'bl' or blocks[1] == 'blacklist') and blocks[2] then + if blocks[2] == '-' then + local set = ('chat:%d:blacklist'):format(msg.chat.id) + local n = db:scard(set) or 0 + local text + if n == 0 then + text = i18n("_The blacklist was already empty_") + else + db:del(set) + text = i18n("*Blacklist cleaned*\n%d links have been removed"):format(n) + end + api.sendReply(msg, text, true) + else + local text + if msg.entities then + local links = urls_table(msg.entities, msg.text) + if not next(links) then + text = i18n("_I can't find any url in this message_") + else + local new = db:sadd(('chat:%d:blacklist'):format(msg.chat.id), table.unpack(links)) + text = i18n("%d link(s) will be blacklisted"):format(#links - (#links - new)) + if new ~= #links then + text = text..i18n("\n%d links were already in the list"):format(#links - new) + end + end + else + text = i18n("_I can't find any url in this message_") + end + api.sendReply(msg, text, true) + end + end + if (blocks[1] == 'bl' or blocks[1] == 'blacklist') and not blocks[2] then + local links = db:smembers(('chat:%d:blacklist'):format(msg.chat.id)) + if not next(links) then + api.sendReply(msg, i18n("_The blacklist is empty_.\nUse `/bl [links]` to add some links to the blacklist"), true) + else + local text = i18n("Blacklisted links:\n\n") + for i=1, #links do + text = text..'• '..links[i]..'\n' + end + api.sendReply(msg, text) + end + end + if blocks[1] == 'unbl' or blocks[1] == 'unblacklist' then + local text + if msg.entities then + local links = urls_table(msg.entities, msg.text) + if not next(links) then + text = i18n("_I can't find any url in this message_") + else + local removed = db:srem(('chat:%d:blacklist'):format(msg.chat.id), table.unpack(links)) + text = i18n("%d link(s) removed from the blacklist"):format(removed) + if removed ~= #links then + text = text.._("\n%d links were already in the list"):format(#links - removed) + end + end + else + text = i18n("_I can't find any url in this message_") + end + api.sendReply(msg, text, true) + end + if blocks[1] == 'funbl' then --force the unblacklist of a link + db:srem(('chat:%d:blacklist'):format(msg.chat.id), blocks[2]) + api.sendReply(msg, 'Done') + end + if blocks[1] == 'wlchan' and not blocks[2] then local channels = db:smembers(('chat:%d:chanwhitelist'):format(msg.chat.id)) if not next(channels) then @@ -433,7 +500,14 @@ plugin.triggers = { config.cmd..'(wl)$', config.cmd..'(whitelist)$', --config.cmd..'(wlchan)$', - config.cmd..'(funwl) (.+)' + config.cmd..'(funwl) (.+)', + config.cmd..'(bl) (.+)$', + config.cmd..'(blacklist) (.+)$', + config.cmd..'(bl)$', + config.cmd..'(blacklist)$', + config.cmd..'(unbl) (.+)$', + config.cmd..'(unblacklist) (.+)$', + config.cmd..'(funbl) (.+)' } } From fcd4fecad4edd93a2167b4bcfa0c22e03718bf5e Mon Sep 17 00:00:00 2001 From: Reyas Mohammed Ismail Date: Wed, 15 Nov 2017 09:00:56 +0530 Subject: [PATCH 4/5] Added blacklist --- lua/plugins/help.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lua/plugins/help.lua b/lua/plugins/help.lua index 657569f82..6ed7ac09f 100644 --- a/lua/plugins/help.lua +++ b/lua/plugins/help.lua @@ -157,6 +157,19 @@ If an user sends a whitelisted link, he won't be warned or kicked. When the group link is saved with `/setlink`, it gets automatically added to the whitelist. +*Why links are saved without* _https://_ *and* _www_*?* +The bot auto-removes _https://, http:// and www_ from every link to reduce the possibility of having the same link saved twice. +]]) + elseif key == 'blacklist' then + return _([[*Blacklist settings* + +If an user sends a blacklisted link, it will be deleted. + +`/blacklist [link(s)]` or `/bl [link(s)]`: add one or more links to the blacklist. +`/unblacklist [link(s)]` or `/unbl [link(s)]`: remove one or more links from the blacklist. +`/blacklist` or `/bl`: get the blacklist. +`/blacklistl -` or `/bl -`: empty the blacklist. + *Why links are saved without* _https://_ *and* _www_*?* The bot auto-removes _https://, http:// and www_ from every link to reduce the possibility of having the same link saved twice. ]]) @@ -303,9 +316,12 @@ local function dk_admins() [i18n("Extra commands")] = 'extra', [i18n("Warns")] = 'warns' }, - { - [i18n("Welcome settings")] = 'welcome', + { [i18n("Links whitelist")] = 'whitelist', + [i18n("Links blacklist")] = 'blacklist', + }, + { + [i18n("Welcome settings")] = 'welcome', } } From a13d4166a060c22de5d880742e96db3a39607577 Mon Sep 17 00:00:00 2001 From: Reyas Mohammed Ismail Date: Wed, 20 Mar 2019 04:17:23 +0530 Subject: [PATCH 5/5] Update antispam.lua --- lua/plugins/antispam.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/plugins/antispam.lua b/lua/plugins/antispam.lua index 57fa69783..ddf82d54e 100644 --- a/lua/plugins/antispam.lua +++ b/lua/plugins/antispam.lua @@ -392,7 +392,7 @@ function plugin.onTextMessage(msg, blocks) if not next(links) then text = i18n("_I can't find any url in this message_") else - local new = db:sadd(('chat:%d:blacklist'):format(msg.chat.id), table.unpack(links)) + local new = db:sadd(('chat:%d:blacklist'):format(msg.chat.id), unpack(links)) text = i18n("%d link(s) will be blacklisted"):format(#links - (#links - new)) if new ~= #links then text = text..i18n("\n%d links were already in the list"):format(#links - new) @@ -423,10 +423,10 @@ function plugin.onTextMessage(msg, blocks) if not next(links) then text = i18n("_I can't find any url in this message_") else - local removed = db:srem(('chat:%d:blacklist'):format(msg.chat.id), table.unpack(links)) + local removed = db:srem(('chat:%d:blacklist'):format(msg.chat.id), unpack(links)) text = i18n("%d link(s) removed from the blacklist"):format(removed) if removed ~= #links then - text = text.._("\n%d links were already in the list"):format(#links - removed) + text = text..i18n("\n%d links were already in the list"):format(#links - removed) end end else @@ -437,7 +437,7 @@ function plugin.onTextMessage(msg, blocks) if blocks[1] == 'funbl' then --force the unblacklist of a link db:srem(('chat:%d:blacklist'):format(msg.chat.id), blocks[2]) api.sendReply(msg, 'Done') - end + end if blocks[1] == 'wlchan' and not blocks[2] then local channels = db:smembers(('chat:%d:chanwhitelist'):format(msg.chat.id))