Various minor fixes and improvements.

This commit is contained in:
Krytarik Raido 2022-04-30 01:34:04 +02:00
parent 67b334a431
commit 3931b790d5

100
plugin.py
View File

@ -475,7 +475,7 @@ class Ircd(object):
if len(r): if len(r):
for item in r: for item in r:
(uid, mode, value, by, when, expire) = item (uid, mode, value, by, when, expire) = item
if pattern is not None and not ircutils.hostmaskPatternEqual(pattern, by): if not (pattern is None or ircutils.hostmaskPatternEqual(pattern, by)):
continue continue
c.execute("""SELECT oper,comment FROM comments WHERE ban_id=? c.execute("""SELECT oper,comment FROM comments WHERE ban_id=?
ORDER BY at DESC LIMIT 1""", (uid,)) ORDER BY at DESC LIMIT 1""", (uid,))
@ -554,13 +554,12 @@ class Ircd(object):
if not (uid and prefix): if not (uid and prefix):
return [] return []
c = db.cursor() c = db.cursor()
c.execute("""SELECT channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by c.execute("""SELECT channel FROM bans WHERE id=?""", (uid,))
FROM bans WHERE id=?""", (uid,))
L = c.fetchall() L = c.fetchall()
if not len(L): if not len(L):
c.close() c.close()
return [] return []
(channel, oper, kind, mask, begin_at, end_at, removed_at, removed_by) = L[0] (channel,) = L[0]
if not ircdb.checkCapability(prefix, '%s,op' % channel): if not ircdb.checkCapability(prefix, '%s,op' % channel):
c.close() c.close()
return [] return []
@ -589,7 +588,7 @@ class Ircd(object):
# deep search inside database, # deep search inside database,
# results filtered depending prefix capability # results filtered depending prefix capability
c = db.cursor() c = db.cursor()
bans = {} bans = set([])
results = [] results = []
isOwner = ircdb.checkCapability(prefix, 'owner') or prefix == irc.prefix isOwner = ircdb.checkCapability(prefix, 'owner') or prefix == irc.prefix
glob = '*%s*' % pattern glob = '*%s*' % pattern
@ -619,14 +618,14 @@ class Ircd(object):
for item in items: for item in items:
(uid, mask) = item (uid, mask) = item
if ircutils.hostmaskPatternEqual(pattern, mask): if ircutils.hostmaskPatternEqual(pattern, mask):
bans[uid] = uid bans.add(uid)
c.execute("""SELECT ban_id,full FROM nicks ORDER BY ban_id DESC""") c.execute("""SELECT ban_id,full FROM nicks ORDER BY ban_id DESC""")
items = c.fetchall() items = c.fetchall()
if len(items): if len(items):
for item in items: for item in items:
(uid, full) = item (uid, full) = item
if ircutils.hostmaskPatternEqual(pattern, full): if ircutils.hostmaskPatternEqual(pattern, full):
bans[uid] = uid bans.add(uid)
if deep: if deep:
c.execute("""SELECT ban_id,full FROM nicks WHERE full GLOB ? OR full LIKE ? 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)) OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""", (glob, like, glob, like))
@ -637,21 +636,21 @@ class Ircd(object):
if len(items): if len(items):
for item in items: for item in items:
(uid, full) = item (uid, full) = item
bans[uid] = uid bans.add(uid)
c.execute("""SELECT id,mask FROM bans WHERE mask GLOB ? OR mask LIKE ? c.execute("""SELECT id,mask FROM bans WHERE mask GLOB ? OR mask LIKE ?
ORDER BY id DESC""", (glob, like)) ORDER BY id DESC""", (glob, like))
items = c.fetchall() items = c.fetchall()
if len(items): if len(items):
for item in items: for item in items:
(uid, full) = item (uid, mask) = item
bans[uid] = uid bans.add(uid)
c.execute("""SELECT ban_id,comment FROM comments WHERE comment GLOB ? OR comment LIKE ? c.execute("""SELECT ban_id,comment FROM comments WHERE comment GLOB ? OR comment LIKE ?
ORDER BY ban_id DESC""", (glob, 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:
(uid, full) = item (uid, comment) = item
bans[uid] = uid bans.add(uid)
if len(bans): if len(bans):
for uid in bans: for uid in bans:
c.execute("""SELECT id,mask,kind,channel,begin_at,end_at,removed_at c.execute("""SELECT id,mask,kind,channel,begin_at,end_at,removed_at
@ -661,11 +660,11 @@ class Ircd(object):
(uid, mask, kind, chan, begin_at, end_at, removed_at) = item (uid, mask, kind, chan, begin_at, end_at, removed_at) = item
if isOwner or ircdb.checkCapability(prefix, '%s,op' % chan): if isOwner or ircdb.checkCapability(prefix, '%s,op' % chan):
if (never or active) and removed_at: if (never or active) and removed_at:
continue continue
if never and begin_at != end_at: if never and begin_at != end_at:
continue continue
if channel and chan != channel: if channel and chan != channel:
continue continue
results.append([uid, mask, kind, chan]) results.append([uid, mask, kind, chan])
if len(results): if len(results):
results.sort(reverse=True) results.sort(reverse=True)
@ -690,13 +689,12 @@ class Ircd(object):
if not (uid and prefix): if not (uid and prefix):
return [] return []
c = db.cursor() c = db.cursor()
c.execute("""SELECT channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by c.execute("""SELECT channel FROM bans WHERE id=?""", (uid,))
FROM bans WHERE id=?""", (uid,))
L = c.fetchall() L = c.fetchall()
if not len(L): if not len(L):
c.close() c.close()
return [] return []
(channel, oper, kind, mask, begin_at, end_at, removed_at, removed_by) = L[0] (channel,) = L[0]
if not ircdb.checkCapability(prefix, '%s,op' % channel): if not ircdb.checkCapability(prefix, '%s,op' % channel):
c.close() c.close()
return [] return []
@ -727,10 +725,10 @@ class Ircd(object):
b = False b = False
if len(L): if len(L):
(uid, channel, kind, mask) = L[0] (uid, channel, kind, mask) = L[0]
if not ircdb.checkCapability(prefix, '%s,op' % channel): if not (ircdb.checkCapability(prefix, '%s,op' % channel)
if prefix != irc.prefix: or prefix == irc.prefix):
c.close() c.close()
return False return False
current = time.time() current = time.time()
c.execute("""INSERT INTO comments VALUES (?, ?, ?, ?)""", (uid, prefix, current, message)) c.execute("""INSERT INTO comments VALUES (?, ?, ?, ?)""", (uid, prefix, current, message))
db.commit() db.commit()
@ -761,10 +759,10 @@ class Ircd(object):
b = False b = False
if len(L): if len(L):
(uid, channel, kind, mask) = L[0] (uid, channel, kind, mask) = L[0]
if not ircdb.checkCapability(prefix, '%s,op' % channel): if not (ircdb.checkCapability(prefix, '%s,op' % channel)
if prefix != irc.prefix: or prefix == irc.prefix):
c.close() c.close()
return False return False
current = time.time() current = time.time()
c.execute("""INSERT INTO comments VALUES (?, ?, ?, ?)""", (uid, prefix, current, message)) c.execute("""INSERT INTO comments VALUES (?, ?, ?, ?)""", (uid, prefix, current, message))
db.commit() db.commit()
@ -859,9 +857,9 @@ class Ircd(object):
# edit eIqb duration # edit eIqb duration
if not (channel and mode and value and prefix): if not (channel and mode and value and prefix):
return False return False
if not ircdb.checkCapability(prefix, '%s,op' % channel): if not (ircdb.checkCapability(prefix, '%s,op' % channel)
if prefix != irc.prefix: or prefix == irc.prefix):
return False return False
c = db.cursor() c = db.cursor()
c.execute("""SELECT id,channel,kind,mask,begin_at,end_at FROM bans WHERE channel=? AND kind=? c.execute("""SELECT id,channel,kind,mask,begin_at,end_at FROM bans WHERE channel=? AND kind=?
AND mask=? AND removed_at is NULL ORDER BY id LIMIT 1""", (channel, mode, value)) AND mask=? AND removed_at is NULL ORDER BY id LIMIT 1""", (channel, mode, value))
@ -870,7 +868,7 @@ class Ircd(object):
if len(L): if len(L):
(uid, channel, kind, mask, begin_at, end_at) = L[0] (uid, channel, kind, mask, begin_at, end_at) = L[0]
chan = self.getChan(irc, channel) chan = self.getChan(irc, channel)
current = float(time.time()) current = time.time()
if begin_at == end_at and seconds < 0: if begin_at == end_at and seconds < 0:
c.close() c.close()
return True return True
@ -1100,7 +1098,7 @@ class Chan(object):
i.affects.append(full) i.affects.append(full)
else: else:
# if begin_at == end_at --> that means forever # if begin_at == end_at --> that means forever
c.execute("""INSERT INTO bans VALUES (NULL, ?, ?, ?, ?, ?, ?,NULL, NULL)""", c.execute("""INSERT INTO bans VALUES (NULL, ?, ?, ?, ?, ?, ?, NULL, NULL)""",
(self.name, by, mode, value, when, when)) (self.name, by, mode, value, when, when))
i.isNew = True i.isNew = True
uid = c.lastrowid uid = c.lastrowid
@ -1152,7 +1150,7 @@ class Chan(object):
def removeItem(self, mode, value, by, c): def removeItem(self, mode, value, by, c):
# flag item as removed in database, we use a cursor as argument # flag item as removed in database, we use a cursor as argument
# because otherwise database tends to be locked # because otherwise database tends to be locked
removed_at = float(time.time()) removed_at = time.time()
i = self.getItem(mode, value) i = self.getItem(mode, value)
created = False created = False
if not i: if not i:
@ -1178,9 +1176,9 @@ class Chan(object):
return i return i
def addpattern(self, prefix, limit, life, mode, duration, pattern, regexp, db): def addpattern(self, prefix, limit, life, mode, duration, pattern, regexp, db):
if not ircdb.checkCapability(prefix, '%s,op' % self.name): if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
if prefix != irc.prefix: or prefix == irc.prefix):
return False return False
c = db.cursor() c = db.cursor()
c.execute("""INSERT INTO patterns VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)""", c.execute("""INSERT INTO patterns VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)""",
(self.name, prefix, time.time(), pattern, regexp, limit, life, mode, duration)) (self.name, prefix, time.time(), pattern, regexp, limit, life, mode, duration))
@ -1194,9 +1192,9 @@ class Chan(object):
return '[#%s "%s"%s]' % (uid, pattern, r) return '[#%s "%s"%s]' % (uid, pattern, r)
def rmpattern(self, prefix, uid, db): def rmpattern(self, prefix, uid, db):
if not ircdb.checkCapability(prefix, '%s,op' % self.name): if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
if prefix != irc.prefix: or prefix == irc.prefix):
return False return False
c = db.cursor() c = db.cursor()
c.execute("""SELECT id,channel,pattern,regexp FROM patterns c.execute("""SELECT id,channel,pattern,regexp FROM patterns
WHERE id=? and channel=? LIMIT 1""", (uid, self.name)) WHERE id=? and channel=? LIMIT 1""", (uid, self.name))
@ -1206,7 +1204,7 @@ class Chan(object):
c.execute("""DELETE FROM patterns WHERE id=? and channel=? LIMIT 1""", (uid, self.name)) c.execute("""DELETE FROM patterns WHERE id=? and channel=? LIMIT 1""", (uid, self.name))
if uid in self.patterns: if uid in self.patterns:
del self.patterns[uid] del self.patterns[uid]
prop = 'Pattern%s' % id prop = 'Pattern%s' % rid
if prop in self.spam: if prop in self.spam:
del self.spam[prop] del self.spam[prop]
db.commit() db.commit()
@ -1228,9 +1226,9 @@ class Chan(object):
c.close() c.close()
def lspattern(self, prefix, pattern, db): def lspattern(self, prefix, pattern, db):
if not ircdb.checkCapability(prefix, '%s,op' % self.name): if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
if prefix != irc.prefix: or prefix != irc.prefix):
return [] return []
c = db.cursor() c = db.cursor()
results = [] results = []
items = [] items = []
@ -1678,7 +1676,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if not b: if not b:
break break
if not sf and getDuration(seconds) > 0: if not sf and getDuration(seconds) > 0:
self._schedule(irc, float(time.time())+getDuration(seconds), True) self._schedule(irc, time.time()+getDuration(seconds), True)
if not msg.nick == irc.nick: if not msg.nick == irc.nick:
if b: if b:
irc.replySuccess() irc.replySuccess()
@ -2791,7 +2789,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
targets.add(LL[pattern].value) targets.add(LL[pattern].value)
elif item == '*': elif item == '*':
massremove = True massremove = True
targets = [] targets = set([])
if channel in list(irc.state.channels.keys()): if channel in list(irc.state.channels.keys()):
L = chan.getItemsFor(self.getIrcdMode(irc, mode, '*!*@*')[0]) L = chan.getItemsFor(self.getIrcdMode(irc, mode, '*!*@*')[0])
for pattern in L: for pattern in L:
@ -3064,7 +3062,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
# remove duplicates (should not happen, but..) # remove duplicates (should not happen, but..)
S = set(L) S = set(L)
r = [] r = []
for item in L: for item in S:
r.append(item) r.append(item)
# if glitch, just comment this if... # if glitch, just comment this if...
if not (len(chan.action) or adding or chan.attacked): if not (len(chan.action) or adding or chan.attacked):
@ -3421,8 +3419,8 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
else: else:
chan.action.enqueue(ircmsgs.mode(channel, chan.action.enqueue(ircmsgs.mode(channel,
args=(self.registryValue('massJoinUnMode', channel=channel, network=irc.network),))) args=(self.registryValue('massJoinUnMode', channel=channel, network=irc.network),)))
schedule.addEvent(unAttack, float(time.time() schedule.addEvent(unAttack, time.time()
+ self.registryValue('massJoinDuration', channel=channel, network=irc.network))) + self.registryValue('massJoinDuration', channel=channel, network=irc.network))
self.forceTickle = True self.forceTickle = True
flag = ircdb.makeChannelCapability(channel, 'clone') flag = ircdb.makeChannelCapability(channel, 'clone')
if not banned and ircdb.checkCapability(msg.prefix, flag): if not banned and ircdb.checkCapability(msg.prefix, flag):
@ -4259,7 +4257,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
# reask for deop # reask for deop
self.unOp(irc, channel) self.unOp(irc, channel)
chan.deopPending = True chan.deopPending = True
schedule.addEvent(unOpBot, float(time.time()+10)) schedule.addEvent(unOpBot, time.time()+10)
def hasExtendedSharedBan(self, irc, fromChannel, target, mode): def hasExtendedSharedBan(self, irc, fromChannel, target, mode):
# TODO: add support for other ircds if possible, currently only freenode # TODO: add support for other ircds if possible, currently only freenode
@ -4748,8 +4746,8 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
chan.action.enqueue(ircmsgs.mode(channel, chan.action.enqueue(ircmsgs.mode(channel,
args=(self.registryValue('attackUnMode', channel=channel, network=irc.network),))) args=(self.registryValue('attackUnMode', channel=channel, network=irc.network),)))
chan.attacked = False chan.attacked = False
schedule.addEvent(unAttack, float(time.time() schedule.addEvent(unAttack, time.time()
+ self.registryValue('attackDuration', channel=channel, network=irc.network))) + self.registryValue('attackDuration', channel=channel, network=irc.network))
return b return b
def _isHilight(self, irc, channel, key, message): def _isHilight(self, irc, channel, key, message):