Added operator nick in /kick /remove, supports for accountability if quietMessage and banMessage are filled

This commit is contained in:
Nicolas Coevoet 2021-07-01 12:07:24 +02:00
parent 3347a755bd
commit 0b24db1311
2 changed files with 45 additions and 5 deletions

View File

@ -184,10 +184,10 @@ conf.registerChannelValue(ChanTracker, 'keepOp',
conf.registerChannelValue(ChanTracker, 'kickMode',
registry.CommaSeparatedListOfStrings(['b'], """bot will kick affected users when mode is triggered,
use with caution, if an op bans *!*@*, bot will kick everyone on the channel"""))
use with caution, if an op bans *!*@*, bot will kick everyone on the channel - see kickMax"""))
conf.registerChannelValue(ChanTracker, 'kickOnMode',
registry.Boolean(False, """bot will kick affected users when kickMode is triggered, use with caution"""))
registry.Boolean(False, """if the bot isn't the kickMode issuer it will still kick. use with caution"""))
conf.registerChannelValue(ChanTracker, 'kickMax',
registry.Integer(-1, """if > 0, disable kick if affected users > kickMax, avoid to clean up entire channel with ban like *!*@*"""))
@ -197,11 +197,18 @@ conf.registerChannelValue(ChanTracker, 'kickMessage',
conf.registerChannelValue(ChanTracker, 'quietMessage',
registry.String("", """leave empty if you don't want the bot to tell something to the user when they have been quieted (by/via the bot);
in any case, if channel is under attack, bot will not send message"""))
in any case, if channel is under attack, bot will not send message, if filled, the operator nick will be given for accountability"""))
conf.registerChannelValue(ChanTracker, 'quietNotice',
registry.Boolean(False, """if False, private message is used, if quietMessage is not empty"""))
conf.registerChannelValue(ChanTracker, 'banMessage',
registry.String("", """leave empty if you don't want the bot to tell something to the user when they have been banned (by/via the bot);
in any case, if channel is under attack, bot will not send message, if filled, the operator nick will be given for accountability"""))
conf.registerChannelValue(ChanTracker, 'banNotice',
registry.Boolean(False, """if False, private message is used, if banMessage is not empty"""))
conf.registerChannelValue(ChanTracker, 'trackAffected',
registry.Boolean(True, """bot tracks affected users by mode change; if you encounter too much lag or cpu usage, you could disable this feature,
but bot will never kick again affected users or remove voice/op/exempt etc of affected users"""))

View File

@ -1969,6 +1969,8 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
chan = self.getChan(irc, channel)
if not reason:
reason = msg.nick
else:
reason = reason + ' (by ' + msg.nick + ')'
chan.action.enqueue(ircmsgs.IrcMsg('REMOVE %s %s :%s' % (channel, nick, reason)))
self.forceTickle = True
self._tickle(irc)
@ -1981,6 +1983,8 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
chan = self.getChan(irc, channel)
if not reason:
reason = msg.nick
else:
reason = reason + ' (by ' + msg.nick + ')'
chan.action.enqueue(ircmsgs.kick(channel, nick, reason))
self.forceTickle = True
self._tickle(irc)
@ -4254,10 +4258,33 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
or len(item.affects) < self.registryValue(
'kickMax', channel=channel):
if nick in irc.state.channels[channel].users and nick != irc.nick:
chan.action.enqueue(ircmsgs.kick(channel, nick, random.choice(
self.registryValue('kickMessage', channel=channel))))
kickMessage = random.choice(self.registryValue('kickMessage', channel=channel))
if msg.nick == irc.nick or msg.nick == 'ChanServ':
if len(self.registryValue('banMessage', channel=channel)):
hk = '%s%s' % (m,value)
if hk in chan.update:
if len(chan.update[hk]) == 4:
if ircutils.isUserHostmask(chan.update[hk][3]):
(nn, ii, hh) = ircutils.splitHostmask(chan.update[hk][3])
kickMessage = kickMessage + ' (by ' + nn + ')'
chan.action.enqueue(ircmsgs.kick(channel, nick, kickMessage))
self.forceTickle = True
kicked = True
elif m == 'b' and not kicked:
if msg.nick == irc.nick or msg.nick == 'ChanServ':
if len(self.registryValue('banMessage', channel=channel)):
bm = self.registryValue('banMessage', channel=channel)
hk = '%s%s' % (m,value)
if hk in chan.update:
if len(chan.update[hk]) == 4:
if ircutils.isUserHostmask(chan.update[hk][3]):
(nn, ii, hh) = ircutils.splitHostmask(chan.update[hk][3])
bm = bm + ' (by ' + nn + ')'
log.info('[%s] warned %s by pm' % (channel, nick))
if self.registryValue('banNotice', channel=channel):
irc.queueMsg(ircmsgs.notice(nick, bm))
else:
irc.queueMsg(ircmsgs.privmsg(nick, bm))
if not kicked and m in self.registryValue('modesToAsk', channel=channel) \
and self.registryValue('doActionAgainstAffected', channel=channel):
if msg.nick == irc.nick:
@ -4271,6 +4298,12 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if m == 'q' and not (chan.attacked or value == '$~a'):
qm = self.registryValue('quietMessage', channel=channel)
if len(qm):
hk = '%s%s' % (m,value)
if hk in chan.update:
if len(chan.update[hk]) == 4:
if ircutils.isUserHostmask(chan.update[hk][3]):
(nn, ii, hh) = ircutils.splitHostmask(chan.update[hk][3])
qm = qm + ' (by ' + nn + ')'
log.info('[%s] warned %s by pm' % (channel, nick))
if self.registryValue('quietNotice', channel=channel):
irc.queueMsg(ircmsgs.notice(nick, qm))