modified a bit quiet/unquiet vs chanserv, added new announce configuration about voice and op modes

This commit is contained in:
Nicolas Coevoet 2013-11-27 19:58:41 +01:00
parent db6993ad63
commit c7cfdd6f9d
2 changed files with 49 additions and 42 deletions

View File

@ -83,6 +83,9 @@ messages from user flagged as bad, or when channel is under attack will not be f
conf.registerChannelValue(ChanTracker, 'announceMode', conf.registerChannelValue(ChanTracker, 'announceMode',
registry.Boolean(True,"""announce mode changes to logChannel""")) registry.Boolean(True,"""announce mode changes to logChannel"""))
conf.registerChannelValue(ChanTracker, 'announceVoiceAndOpMode',
registry.Boolean(True,"""announce mode changes to logChannel"""))
conf.registerChannelValue(ChanTracker, 'announceModeSync', conf.registerChannelValue(ChanTracker, 'announceModeSync',
registry.Boolean(False,"""announce mode sync to logChannel""")) registry.Boolean(False,"""announce mode sync to logChannel"""))

View File

@ -444,7 +444,7 @@ class Ircd (object):
if len(L): if len(L):
for com in L: for com in L:
(oper,comment,at) = com (oper,comment,at) = com
results.append('"%s" by %s on %s' % (comment,oper,at)) results.append('"%s" by %s on %s' % (comment,oper,floatToGMT(at)))
c.execute("""SELECT full,log FROM nicks WHERE ban_id=?""",(uid,)) c.execute("""SELECT full,log FROM nicks WHERE ban_id=?""",(uid,))
L = c.fetchall() L = c.fetchall()
if len(L): if len(L):
@ -646,7 +646,7 @@ class Ircd (object):
return True return True
return False return False
def add (self,irc,channel,mode,value,seconds,prefix,db,useService=False): def add (self,irc,channel,mode,value,seconds,prefix,db):
# add new eIqb item # add new eIqb item
if not ircdb.checkCapability(prefix,'%s,op' % channel): if not ircdb.checkCapability(prefix,'%s,op' % channel):
if prefix != irc.prefix: if prefix != irc.prefix:
@ -668,10 +668,7 @@ class Ircd (object):
# prepare item update after being set ( we don't have id yet ) # prepare item update after being set ( we don't have id yet )
chan.update[hash] = [mode,value,seconds,prefix] chan.update[hash] = [mode,value,seconds,prefix]
# enqueue mode changes # enqueue mode changes
if useService: chan.queue.enqueue(('+%s' % mode,value))
chan.service.enqueue((mode,value))
else:
chan.queue.enqueue(('+%s' % mode,value))
return True return True
return False return False
@ -763,8 +760,6 @@ class Chan (object):
self.mark = {} self.mark = {}
# contains IrcMsg ( mostly kick / fpart ) # contains IrcMsg ( mostly kick / fpart )
self.action = utils.structures.smallqueue() self.action = utils.structures.smallqueue()
# chanservs quiet/unquiet
self.service = utils.structures.smallqueue()
# looking for eqIb list ends # looking for eqIb list ends
self.dones = [] self.dones = []
self.syn = False self.syn = False
@ -826,22 +821,21 @@ class Chan (object):
for nick in self.ircd.irc.state.channels[self.name].users: for nick in self.ircd.irc.state.channels[self.name].users:
L.append(nick) L.append(nick)
for nick in L: for nick in L:
if nick in self.ircd.nicks: n = self.ircd.getNick(self.ircd.irc,nick)
n = self.ircd.getNick(self.ircd.irc,nick) m = match(value,n)
m = match(value,n) if m:
if m: i.affects.append(n.prefix)
i.affects.append(n.prefix) # insert logs
# insert logs index = 0
index = 0 logs = []
logs = [] logs.append('%s matched by %s' % (n,m))
logs.append('%s matched by %s' % (n,m)) for line in n.logs:
for line in n.logs: (ts,target,message) = n.logs[index]
(ts,target,message) = n.logs[index] index += 1
index += 1 if target == self.name or target == 'ALL':
if target == self.name or target == 'ALL': logs.append('[%s] %s' % (floatToGMT(ts),message))
logs.append('[%s] %s' % (floatToGMT(ts),message)) c.execute("""INSERT INTO nicks VALUES (?, ?, ?, ?)""",(uid,value,n.prefix,'\n'.join(logs)))
c.execute("""INSERT INTO nicks VALUES (?, ?, ?, ?)""",(uid,value,n.prefix,'\n'.join(logs))) ns.append([n,m])
ns.append([n,m])
if len(ns): if len(ns):
db.commit() db.commit()
c.close() c.close()
@ -947,7 +941,16 @@ class Nick (object):
return self return self
def __repr__(self): def __repr__(self):
return '%s ip:%s $a:%s $r:%s' % (self.prefix,self.ip,self.account,self.realname) ip = self.ip
if ip == None:
ip = ''
account = self.account
if account == None:
account = ''
realname = self.realname
if realname == None:
realname = ''
return '%s ip:%s $a:%s $r:%s' % (self.prefix,ip,account,realname)
# Taken from plugins.Time.seconds # Taken from plugins.Time.seconds
def getTs (irc, msg, args, state): def getTs (irc, msg, args, state):
@ -1167,10 +1170,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
"""[<channel>] <nick|hostmask>[,<nick|hostmask>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1s> or empty means forever] <reason> """[<channel>] <nick|hostmask>[,<nick|hostmask>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1s> or empty means forever] <reason>
+q targets for duration reason is mandatory""" +q targets for duration reason is mandatory"""
useService = False b = self._adds(irc,msg,args,channel,'q',items,getDuration(seconds),reason)
if len(items) == 1 and not irc.nick in irc.state.channels[channel].ops and self.registryValue('useChanServForQuiets',channel=channel):
useService = True
b = self._adds(irc,msg,args,channel,'q',items,getDuration(seconds),reason,useService)
if not msg.nick == irc.nick: if not msg.nick == irc.nick:
if b: if b:
irc.replySuccess() irc.replySuccess()
@ -1342,7 +1342,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
#irc.error('nick not found') #irc.error('nick not found')
#isbad = wrap(isbad,['op','nick']) #isbad = wrap(isbad,['op','nick'])
def _adds (self,irc,msg,args,channel,mode,items,duration,reason,useService=False): def _adds (self,irc,msg,args,channel,mode,items,duration,reason):
i = self.getIrc(irc) i = self.getIrc(irc)
targets = [] targets = []
if mode in self.registryValue('modesToAsk') or mode in self.registryValue('modesToAskWhenOpped'): if mode in self.registryValue('modesToAsk') or mode in self.registryValue('modesToAskWhenOpped'):
@ -1357,7 +1357,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
targets.append(patterns[0]) targets.append(patterns[0])
n = 0 n = 0
for item in targets: for item in targets:
if i.add(irc,channel,mode,item,duration,msg.prefix,self.getDb(irc.network),useService): if i.add(irc,channel,mode,item,duration,msg.prefix,self.getDb(irc.network)):
if reason: if reason:
f = None f = None
if self.registryValue('announceInTimeEditAndMark',channel=channel): if self.registryValue('announceInTimeEditAndMark',channel=channel):
@ -1530,7 +1530,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
for value in list(chan._lists[mode].keys()): for value in list(chan._lists[mode].keys()):
item = chan._lists[mode][value] item = chan._lists[mode][value]
if item.expire != None and item.expire != item.when and not item.asked and item.expire <= t: if item.expire != None and item.expire != item.when and not item.asked and item.expire <= t:
if mode == 'q' and self.registryValue('useChanServForQuiets',channel=channel) and not irc.nick in irc.state.channels[channel].ops: if mode == 'q' and item.value.find('$') == -1 and self.registryValue('useChanServForQuiets',channel=channel) and not irc.nick in irc.state.channels[channel].ops:
s = self.registryValue('unquietCommand') s = self.registryValue('unquietCommand')
s = s.replace('$channel',channel) s = s.replace('$channel',channel)
s = s.replace('$hostmask',item.value) s = s.replace('$hostmask',item.value)
@ -1543,14 +1543,17 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
# dequeue pending actions # dequeue pending actions
# log.debug('[%s] isOpped : %s, opAsked : %s, deopAsked %s, deopPending %s' % (channel,irc.nick in irc.state.channels[channel].ops,chan.opAsked,chan.deopAsked,chan.deopPending)) # log.debug('[%s] isOpped : %s, opAsked : %s, deopAsked %s, deopPending %s' % (channel,irc.nick in irc.state.channels[channel].ops,chan.opAsked,chan.deopAsked,chan.deopPending))
if chan.syn: if chan.syn:
if len(chan.service): if len(chan.queue):
while len(chan.service): index = 0
(mode,value) = chan.service.pop() for item in list(chan.queue):
if mode == 'q': (mode,value) = item
if mode == '+q' and value.find('$') == -1 and self.registryValue('useChanServForQuiets',channel=channel) and not irc.nick in irc.state.channels[channel].ops:
s = self.registryValue('quietCommand') s = self.registryValue('quietCommand')
s = s.replace('$channel',channel) s = s.replace('$channel',channel)
s = s.replace('$hostmask',value) s = s.replace('$hostmask',value)
i.queue.enqueue(ircmsgs.IrcMsg(s)) i.queue.enqueue(ircmsgs.IrcMsg(s))
chan.queue.pop(index)
index = index + 1
if not irc.nick in irc.state.channels[channel].ops: if not irc.nick in irc.state.channels[channel].ops:
chan.deopAsked = False chan.deopAsked = False
chan.deopPending = False chan.deopPending = False
@ -2459,7 +2462,11 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
if self.registryValue('announceMode',channel=channel): if self.registryValue('announceMode',channel=channel):
msgs.append('[#%s %s %s - %s, %s]' % (str(item.uid),mode,value,item.affects[0],str(utils.timeElapsed(item.removed_at-item.when)))) msgs.append('[#%s %s %s - %s, %s]' % (str(item.uid),mode,value,item.affects[0],str(utils.timeElapsed(item.removed_at-item.when))))
else: else:
msgs.append('[%s %s]' % (mode,value)) if mode.find ('o') != -1 or mode.find ('v') != -1:
if self.registryValue('announceVoiceAndOpMode',channel=channel):
msgs.append('[%s %s]' % (mode,value))
else:
msgs.append('[%s %s]' % (mode,value))
else: else:
if n: if n:
n.addLog(channel,'sets %s' % mode) n.addLog(channel,'sets %s' % mode)
@ -2469,7 +2476,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
c.close() c.close()
if irc.nick in irc.state.channels[channel].ops and not self.registryValue('keepOp',channel=channel): if irc.nick in irc.state.channels[channel].ops and not self.registryValue('keepOp',channel=channel):
self.forceTickle = True self.forceTickle = True
if self.registryValue('announceMode',channel=channel): if self.registryValue('announceMode',channel=channel) and len(msgs):
self._logChan(irc,channel,'[%s] %s sets %s' % (channel,msg.prefix,' '.join(msgs))) self._logChan(irc,channel,'[%s] %s sets %s' % (channel,msg.prefix,' '.join(msgs)))
self._tickle(irc) self._tickle(irc)
@ -2495,10 +2502,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
def _act (self,irc,channel,mode,mask,duration,reason): def _act (self,irc,channel,mode,mask,duration,reason):
if mode in self.registryValue('modesToAsk') or mode in self.registryValue('modesToAskWhenOpped'): if mode in self.registryValue('modesToAsk') or mode in self.registryValue('modesToAskWhenOpped'):
i = self.getIrc(irc) i = self.getIrc(irc)
useService = False if i.add(irc,channel,mode,mask,duration,irc.prefix,self.getDb(irc.network)):
if mode == 'q' and self.registryValue('useChanServForQuiets',channel=channel) and not irc.nick in irc.state.channels[channel].ops:
useService = True
if i.add(irc,channel,mode,mask,duration,irc.prefix,self.getDb(irc.network),useService):
if reason and len(reason): if reason and len(reason):
f = None f = None
if self.registryValue('announceInTimeEditAndMark',channel=channel): if self.registryValue('announceInTimeEditAndMark',channel=channel):