mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 21:19:31 +01:00
antispam: allow individual punishments to fail gracefully when not supported
This commit is contained in:
parent
186b73c72d
commit
b120e2d701
@ -14,10 +14,15 @@ EXEMPT_OPTIONS = ['voice', 'halfop', 'op']
|
|||||||
DEFAULT_EXEMPT_OPTION = 'halfop'
|
DEFAULT_EXEMPT_OPTION = 'halfop'
|
||||||
def _punish(irc, target, channel, punishment, reason):
|
def _punish(irc, target, channel, punishment, reason):
|
||||||
"""Punishes the target user. This function returns True if the user was successfully punished."""
|
"""Punishes the target user. This function returns True if the user was successfully punished."""
|
||||||
if irc.is_oper(target, allowAuthed=False):
|
if target not in irc.users:
|
||||||
|
log.warning("(%s) antispam: got target %r that isn't a user?", irc.name, target)
|
||||||
|
return False
|
||||||
|
elif irc.is_oper(target, allowAuthed=False):
|
||||||
log.debug("(%s) antispam: refusing to punish oper %s/%s", irc.name, target, irc.get_friendly_name(target))
|
log.debug("(%s) antispam: refusing to punish oper %s/%s", irc.name, target, irc.get_friendly_name(target))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
target_nick = irc.get_friendly_name(target)
|
||||||
|
|
||||||
exempt_level = irc.get_service_option('antispam', 'exempt_level', DEFAULT_EXEMPT_OPTION).lower()
|
exempt_level = irc.get_service_option('antispam', 'exempt_level', DEFAULT_EXEMPT_OPTION).lower()
|
||||||
c = irc.channels[channel]
|
c = irc.channels[channel]
|
||||||
|
|
||||||
@ -65,6 +70,7 @@ def _punish(irc, target, channel, punishment, reason):
|
|||||||
'userdata': userdata, 'parse_as': 'KILL'}])
|
'userdata': userdata, 'parse_as': 'KILL'}])
|
||||||
|
|
||||||
kill = False
|
kill = False
|
||||||
|
successful_punishments = 0
|
||||||
for action in set(punishment.split('+')):
|
for action in set(punishment.split('+')):
|
||||||
if action not in PUNISH_OPTIONS:
|
if action not in PUNISH_OPTIONS:
|
||||||
log.error('(%s) Antispam punishment %r is not a valid setting; '
|
log.error('(%s) Antispam punishment %r is not a valid setting; '
|
||||||
@ -74,20 +80,46 @@ def _punish(irc, target, channel, punishment, reason):
|
|||||||
return
|
return
|
||||||
elif action == 'kill':
|
elif action == 'kill':
|
||||||
kill = True # Delay kills so that the user data doesn't disappear.
|
kill = True # Delay kills so that the user data doesn't disappear.
|
||||||
|
# XXX factorize these blocks
|
||||||
elif action == 'kick':
|
elif action == 'kick':
|
||||||
|
try:
|
||||||
_kick()
|
_kick()
|
||||||
|
except NotImplementedError:
|
||||||
|
log.warning("(%s) antispam: Kicks are not supported on this network, skipping; "
|
||||||
|
"target was %s/%s", irc.name, target_nick, channel)
|
||||||
|
else:
|
||||||
|
successful_punishments += 1
|
||||||
elif action == 'ban':
|
elif action == 'ban':
|
||||||
|
try:
|
||||||
_ban()
|
_ban()
|
||||||
|
except (ValueError, NotImplementedError):
|
||||||
|
log.warning("(%s) antispam: Bans are not supported on this network, skipping; "
|
||||||
|
"target was %s/%s", irc.name, target_nick, channel)
|
||||||
|
else:
|
||||||
|
successful_punishments += 1
|
||||||
elif action == 'quiet':
|
elif action == 'quiet':
|
||||||
|
try:
|
||||||
_quiet()
|
_quiet()
|
||||||
|
except (ValueError, NotImplementedError):
|
||||||
|
log.warning("(%s) antispam: Quiet is not supported on this network, skipping; "
|
||||||
|
"target was %s/%s", irc.name, target_nick, channel)
|
||||||
|
else:
|
||||||
|
successful_punishments += 1
|
||||||
|
|
||||||
if bans: # Set all bans at once to prevent spam
|
if bans: # Set all bans at once to prevent spam
|
||||||
irc.mode(my_uid, channel, bans)
|
irc.mode(my_uid, channel, bans)
|
||||||
irc.call_hooks([my_uid, 'ANTISPAM_BAN',
|
irc.call_hooks([my_uid, 'ANTISPAM_BAN',
|
||||||
{'target': channel, 'modes': bans, 'parse_as': 'MODE'}])
|
{'target': channel, 'modes': bans, 'parse_as': 'MODE'}])
|
||||||
if kill:
|
if kill:
|
||||||
|
try:
|
||||||
_kill()
|
_kill()
|
||||||
return True
|
except NotImplementedError:
|
||||||
|
log.warning("(%s) antispam: Kills are not supported on this network, skipping; "
|
||||||
|
"target was %s/%s", irc.name, target_nick, channel)
|
||||||
|
else:
|
||||||
|
successful_punishments += 1
|
||||||
|
|
||||||
|
return bool(successful_punishments)
|
||||||
|
|
||||||
MASSHIGHLIGHT_DEFAULTS = {
|
MASSHIGHLIGHT_DEFAULTS = {
|
||||||
'min_length': 50,
|
'min_length': 50,
|
||||||
|
Loading…
Reference in New Issue
Block a user