mirror of
https://github.com/ncoevoet/ChanTracker.git
synced 2025-04-26 13:01:06 -05:00
added more filtering options for pending and query, some api changes
This commit is contained in:
parent
3bc6ffc12d
commit
d9af5e965b
102
plugin.py
102
plugin.py
@ -374,8 +374,9 @@ class Ircd (object):
|
|||||||
c.close()
|
c.close()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def pending(self,irc,channel,mode,prefix,pattern,db,notExpiredOnly=False):
|
def pending(self,irc,channel,mode,prefix,pattern,db,never):
|
||||||
# returns active items for a channel mode
|
# returns active items for a channel mode
|
||||||
|
log.debug('%s never' % never)
|
||||||
if not channel or not mode or not prefix:
|
if not channel or not mode or not prefix:
|
||||||
return []
|
return []
|
||||||
if not ircdb.checkCapability(prefix, '%s,op' % channel):
|
if not ircdb.checkCapability(prefix, '%s,op' % channel):
|
||||||
@ -389,7 +390,7 @@ class Ircd (object):
|
|||||||
if len(items):
|
if len(items):
|
||||||
for item in items:
|
for item in items:
|
||||||
item = items[item]
|
item = items[item]
|
||||||
if notExpiredOnly:
|
if never:
|
||||||
if item.when == item.expire or not item.expire:
|
if item.when == item.expire or not item.expire:
|
||||||
r.append([item.uid,item.mode,item.value,item.by,item.when,item.expire])
|
r.append([item.uid,item.mode,item.value,item.by,item.when,item.expire])
|
||||||
else:
|
else:
|
||||||
@ -482,8 +483,8 @@ class Ircd (object):
|
|||||||
results.append('no log found')
|
results.append('no log found')
|
||||||
c.close()
|
c.close()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def search (self,irc,pattern,prefix,db):
|
def search (self,irc,pattern,prefix,db,deep,active,never,channel):
|
||||||
# deep search inside database,
|
# deep search inside database,
|
||||||
# results filtered depending prefix capability
|
# results filtered depending prefix capability
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
@ -525,7 +526,10 @@ class Ircd (object):
|
|||||||
(uid,full) = item
|
(uid,full) = item
|
||||||
if ircutils.hostmaskPatternEqual(pattern,full):
|
if ircutils.hostmaskPatternEqual(pattern,full):
|
||||||
bans[uid] = uid
|
bans[uid] = uid
|
||||||
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(glob,like,glob,like))
|
if deep:
|
||||||
|
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(glob,like,glob,like))
|
||||||
|
else:
|
||||||
|
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? ORDER BY ban_id DESC""",(glob,like))
|
||||||
items = c.fetchall()
|
items = c.fetchall()
|
||||||
if len(items):
|
if len(items):
|
||||||
for item in items:
|
for item in items:
|
||||||
@ -545,21 +549,35 @@ class Ircd (object):
|
|||||||
bans[uid] = uid
|
bans[uid] = uid
|
||||||
if len(bans):
|
if len(bans):
|
||||||
for uid in bans:
|
for uid in bans:
|
||||||
c.execute("""SELECT id, mask, kind, channel FROM bans WHERE id=? ORDER BY id DESC LIMIT 1""",(uid,))
|
c.execute("""SELECT id, mask, kind, channel, begin_at, end_at, removed_at FROM bans WHERE id=? ORDER BY id DESC LIMIT 1""",(uid,))
|
||||||
items = c.fetchall()
|
items = c.fetchall()
|
||||||
for item in items:
|
for item in items:
|
||||||
(uid,mask,kind,channel) = item
|
(uid,mask,kind,chan,begin_at,end_at,removed_at) = item
|
||||||
if isOwner or ircdb.checkCapability(prefix, '%s,op' % channel):
|
if isOwner or ircdb.checkCapability(prefix, '%s,op' % chan):
|
||||||
results.append([uid,mask,kind,channel])
|
if never or active:
|
||||||
|
if removed_at:
|
||||||
|
continue
|
||||||
|
if never:
|
||||||
|
if begin_at != end_at:
|
||||||
|
continue
|
||||||
|
if channel and len(channel):
|
||||||
|
if chan != channel:
|
||||||
|
continue
|
||||||
|
results.append([uid,mask,kind,chan])
|
||||||
if len(results):
|
if len(results):
|
||||||
results.sort(reverse=True)
|
results.sort(reverse=True)
|
||||||
i = 0
|
i = 0
|
||||||
msgs = []
|
msgs = []
|
||||||
while i < len(results):
|
while i < len(results):
|
||||||
(uid,mask,kind,channel) = results[i]
|
(uid,mask,kind,chan) = results[i]
|
||||||
msgs.append('[#%s +%s %s in %s]' % (uid,kind,mask,channel))
|
if channel and len(channel):
|
||||||
|
msgs.append('[#%s +%s %s]' % (uid,kind,mask))
|
||||||
|
else:
|
||||||
|
msgs.append('[#%s +%s %s in %s]' % (uid,kind,mask,chan))
|
||||||
i = i+1
|
i = i+1
|
||||||
|
c.close()
|
||||||
return msgs
|
return msgs
|
||||||
|
c.close()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def affect (self,irc,uid,prefix,db):
|
def affect (self,irc,uid,prefix,db):
|
||||||
@ -1049,7 +1067,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
|
|||||||
def editandmark (self,irc,msg,args,user,ids,seconds,reason):
|
def editandmark (self,irc,msg,args,user,ids,seconds,reason):
|
||||||
"""<id>[,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1> or empty means forever, <0s> means remove] <reason>
|
"""<id>[,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1> or empty means forever, <0s> means remove] <reason>
|
||||||
|
|
||||||
change expiration and mark an active mode change"""
|
change expiration and mark of an active mode change, if you got this message while the bot prompted you, your changes were not saved"""
|
||||||
i = self.getIrc(irc)
|
i = self.getIrc(irc)
|
||||||
b = True
|
b = True
|
||||||
for id in ids:
|
for id in ids:
|
||||||
@ -1134,7 +1152,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
|
|||||||
else:
|
else:
|
||||||
irc.reply('item not found or not enough rights to see detail')
|
irc.reply('item not found or not enough rights to see detail')
|
||||||
self._tickle(irc)
|
self._tickle(irc)
|
||||||
detail = wrap(detail,['private','user','int'])
|
detail = wrap(detail,['user','int'])
|
||||||
|
|
||||||
def affect (self,irc,msg,args,user,uid):
|
def affect (self,irc,msg,args,user,uid):
|
||||||
"""<id>
|
"""<id>
|
||||||
@ -1147,7 +1165,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
|
|||||||
else:
|
else:
|
||||||
irc.reply('item not found or not enough rights to see affected users')
|
irc.reply('item not found or not enough rights to see affected users')
|
||||||
self._tickle(irc)
|
self._tickle(irc)
|
||||||
affect = wrap(affect, ['private','user','int'])
|
affect = wrap(affect, ['user','int'])
|
||||||
|
|
||||||
def mark(self,irc,msg,args,user,ids,message):
|
def mark(self,irc,msg,args,user,ids,message):
|
||||||
"""<id> [,<id>] <message>
|
"""<id> [,<id>] <message>
|
||||||
@ -1175,36 +1193,60 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
|
|||||||
self._tickle(irc)
|
self._tickle(irc)
|
||||||
mark = wrap(mark,['user',commalist('int'),'text'])
|
mark = wrap(mark,['user',commalist('int'),'text'])
|
||||||
|
|
||||||
def query (self,irc,msg,args,user,text):
|
def query (self,irc,msg,args,user,optlist,text):
|
||||||
"""<pattern|hostmask>
|
"""[--deep] [--never] [--active] [--channel=<channel>] <pattern|hostmask|comment>
|
||||||
|
|
||||||
returns known mode changes with deep search, channel's ops can only see items for their channels"""
|
search inside ban database, --deep to search on log, --never returns items setted forever and active,
|
||||||
|
--active returns only active modes, --channel reduces results to a specific channel"""
|
||||||
i = self.getIrc(irc)
|
i = self.getIrc(irc)
|
||||||
results = i.search(irc,text,msg.prefix,self.getDb(irc.network))
|
deep = False
|
||||||
|
never = False
|
||||||
|
active = False
|
||||||
|
channel = None
|
||||||
|
for (option, arg) in optlist:
|
||||||
|
if option == 'deep':
|
||||||
|
deep = True
|
||||||
|
elif option == 'never':
|
||||||
|
never = True
|
||||||
|
elif option == 'active':
|
||||||
|
active = True
|
||||||
|
elif option == 'channel':
|
||||||
|
channel = arg
|
||||||
|
if never:
|
||||||
|
active = True
|
||||||
|
results = i.search(irc,text,msg.prefix,self.getDb(irc.network),deep,active,never,channel)
|
||||||
if len(results):
|
if len(results):
|
||||||
irc.replies(results,None,None,False,None,True)
|
irc.replies(results,None,None,False,None,True)
|
||||||
else:
|
else:
|
||||||
irc.reply('nothing found')
|
irc.reply('nothing found')
|
||||||
query = wrap(query,['private','user','text'])
|
query = wrap(query,['user',getopts({'deep': '', 'never': '', 'active' : '','channel':'channel'}),'text'])
|
||||||
|
|
||||||
def pending (self, irc, msg, args, channel, mode, pattern, notExpired):
|
def pending (self, irc, msg, args, channel, optlist):
|
||||||
"""[<channel>] [<mode>] [<nick|hostmask>] [boolean, never expire items only]
|
"""[--mode=<e|b|q|l>] [--oper=<nick|hostmask>] [--never] [<channel>]
|
||||||
|
|
||||||
returns active items for mode if given otherwise all modes are returned, if hostmask given, filtered by oper"""
|
returns active items for mode if given otherwise all modes are returned, if hostmask given, filtered by oper"""
|
||||||
|
mode = None
|
||||||
|
oper = None
|
||||||
|
never = False
|
||||||
|
for (option, arg) in optlist:
|
||||||
|
if option == 'mode':
|
||||||
|
mode = arg
|
||||||
|
elif option == 'oper':
|
||||||
|
oper = arg
|
||||||
|
elif option == 'never':
|
||||||
|
never = True
|
||||||
i = self.getIrc(irc)
|
i = self.getIrc(irc)
|
||||||
if pattern in i.nicks:
|
if oper in i.nicks:
|
||||||
pattern = self.getNick(pattern).prefix
|
oper = self.getNick(irc,oper).prefix
|
||||||
results = []
|
results = []
|
||||||
if not mode:
|
if not mode:
|
||||||
modes = self.registryValue('modesToAskWhenOpped',channel=channel) + self.registryValue('modesToAsk',channel=channel)
|
mode = self.registryValue('modesToAskWhenOpped',channel=channel) + self.registryValue('modesToAsk',channel=channel)
|
||||||
results = i.pending(irc,channel,modes,msg.prefix,pattern,self.getDb(irc.network),False)
|
results = i.pending(irc,channel,mode,msg.prefix,oper,self.getDb(irc.network),never)
|
||||||
else:
|
|
||||||
results = i.pending(irc,channel,mode,msg.prefix,pattern,self.getDb(irc.network),notExpired)
|
|
||||||
if len(results):
|
if len(results):
|
||||||
irc.reply(' '.join(results), private=True)
|
irc.reply(', '.join(results), private=True)
|
||||||
else:
|
else:
|
||||||
irc.reply('no results')
|
irc.reply('no results')
|
||||||
pending = wrap(pending,['op',additional('letter'),optional('hostmask'),optional('boolean')])
|
pending = wrap(pending,['op',getopts({'mode': 'letter', 'never': '', 'oper' : 'somethingWithoutSpaces'}),])
|
||||||
|
|
||||||
def _modes (self,numModes,chan,modes,f):
|
def _modes (self,numModes,chan,modes,f):
|
||||||
for i in range(0, len(modes), numModes):
|
for i in range(0, len(modes), numModes):
|
||||||
@ -1404,7 +1446,7 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
|
|||||||
irc.reply(' '.join(getBestPattern(n,irc)))
|
irc.reply(' '.join(getBestPattern(n,irc)))
|
||||||
return
|
return
|
||||||
irc.reply('nick not found or wrong hostmask given')
|
irc.reply('nick not found or wrong hostmask given')
|
||||||
getmask = wrap(getmask,['owner','text'])
|
getmask = wrap(getmask,['op','text'])
|
||||||
|
|
||||||
def isvip (self,irc,msg,args,channel,nick):
|
def isvip (self,irc,msg,args,channel,nick):
|
||||||
"""[<channel>] <nick>
|
"""[<channel>] <nick>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user