add ban-enforce-max config option
This commit is contained in:
parent
35ce974a0a
commit
84aa7d1bd5
1 changed files with 8 additions and 0 deletions
|
@ -4,6 +4,8 @@ REASON = "User is banned from this channel"
|
|||
|
||||
@utils.export("channelset", utils.BoolSetting("ban-enforce",
|
||||
"Whether or not to parse new bans and kick who they affect"))
|
||||
@utils.export("channelset", utils.IntSetting("ban-enforce-max",
|
||||
"Do not enforce ban if the ban effects more than this many users. Default is half of total channel users."))
|
||||
class Module(ModuleManager.BaseModule):
|
||||
@utils.hook("received.mode.channel")
|
||||
def on_mode(self, event):
|
||||
|
@ -15,13 +17,19 @@ class Module(ModuleManager.BaseModule):
|
|||
bans.append(arg)
|
||||
|
||||
if bans:
|
||||
affected = 0
|
||||
umasks = {u.hostmask(): u for u in event["channel"].users}
|
||||
defaultmax = len(event["channel"].users) // 2
|
||||
realmax = event["channel"].get_setting("ban-enforce-max", defaultmax)
|
||||
for ban in bans:
|
||||
mask = utils.irc.hostmask_parse(ban)
|
||||
matches = list(utils.irc.hostmask_match_many(
|
||||
umasks.keys(), mask))
|
||||
for match in matches:
|
||||
affected = affected + 1
|
||||
kicks.add(umasks[match])
|
||||
if kicks:
|
||||
if affected > realmax:
|
||||
return
|
||||
nicks = [u.nickname for u in kicks]
|
||||
event["channel"].send_kicks(sorted(nicks), REASON)
|
||||
|
|
Loading…
Reference in a new issue