-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Included Blacklist option #252
Open
reyasmohammed
wants to merge
6
commits into
group-butler:develop
Choose a base branch
from
reyasmohammed:master
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
354a714
Added blacklist option
reyasmohammed 1a623e4
blacklist added
reyasmohammed 328e724
Added blacklist
reyasmohammed fcd4fec
Added blacklist
reyasmohammed 62b6440
Merge remote-tracking branch 'upstream/master'
reyasmohammed a13d416
Update antispam.lua
reyasmohammed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use msg:send_reply() instead. |
||
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) (.+)' | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,18 @@ local function is_whitelisted(chat_id, text) | |
end | ||
end | ||
|
||
local function is_blacklisted(chat_id, text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could've generalized the whitelist function and share some code between the two. |
||
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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this.