3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-24 19:24:13 +01:00

antispam: add part / quit message filtering for plugins like Relay

Closes #617.
This commit is contained in:
James Lu 2019-06-27 13:06:20 -07:00
parent b6cf09ae52
commit 35b38dfb05
2 changed files with 63 additions and 0 deletions

View File

@ -1009,3 +1009,25 @@ stats:
#textfilter_globs:
# - "*very bad don't say this*"
# - "TWFkZSB5b3UgbG9vayE="
#partquit:
# This configures Antispam's part / quit message filter for plugins like Relay. It can also be
# overridden (as an entire block) per-network by copying its options to:
# servers::<server name>::antispam_partquit
# Determines whether part and quit messages matching any text spamfilters will be filtered.
# These default to true if not set.
#watch_parts: false
#watch_quits: false
# Sets the message to use when a part or quit message is filtered.
#part_filter_message: Reason filtered
#quit_filter_message: Reason filtered
# Configures a case-insensitive list of bad strings to block in part and quit messages.
# Globs are supported; use them to your advantage here.
# You can also define server specific lists of bad strings by defining
# servers::<server name>::antispam_partquit_globs
# the contents of which will be *merged* into the global list of bad strings specified below.
#partquit_globs:
# - "*some-spammy-site.xyz*"

View File

@ -366,3 +366,44 @@ def handle_textfilter(irc, source, command, args):
utils.add_hook(handle_textfilter, 'PRIVMSG', priority=999)
utils.add_hook(handle_textfilter, 'NOTICE', priority=999)
PARTQUIT_DEFAULTS = {
'watch_quits': True,
'watch_parts': True,
'part_filter_message': "Reason filtered",
'quit_filter_message': "Reason filtered",
}
def handle_partquit(irc, source, command, args):
"""Antispam part/quit message filter."""
text = args.get('text')
pq_settings = irc.get_service_option('antispam', 'partquit',
PARTQUIT_DEFAULTS)
if not text:
return # No text to match against
elif command == 'QUIT' and not pq_settings.get('watch_quits', True):
return # Not enabled
elif command == 'PART' and not pq_settings.get('watch_parts', True):
return
# Merge together global and local partquit filter lists.
pq_globs = set(conf.conf.get('antispam', {}).get('partquit_globs', [])) | \
set(irc.serverdata.get('antispam_partquit_globs', []))
if not pq_globs:
return
for filterglob in pq_globs:
if utils.match_text(filterglob, text):
# For parts, also log the affected channels
if command == 'PART':
filtered_message = pq_settings.get('part_filter_message', PARTQUIT_DEFAULTS['part_filter_message'])
log.info('(%s) antispam: filtered part message from %s on %s due to part/quit filter glob %s',
irc.name, irc.get_hostmask(source), ','.join(args['channels']), filterglob)
else:
filtered_message = pq_settings.get('quit_filter_message', PARTQUIT_DEFAULTS['quit_filter_message'])
log.info('(%s) antispam: filtered quit message from %s due to part/quit filter glob %s',
irc.name, irc.get_hostmask(source), filterglob)
args['text'] = filtered_message
break
utils.add_hook(handle_partquit, 'PART', priority=999)
utils.add_hook(handle_partquit, 'QUIT', priority=999)