Account for over-expiration, set server address as needed.

This commit is contained in:
Krytarik Raido 2022-03-02 05:34:04 +01:00
parent 789e01a28a
commit 4f320388dd
2 changed files with 48 additions and 76 deletions

View File

@ -396,16 +396,21 @@ class Ircd(object):
if begin_at == end_at:
results.append([channel, 'is set forever'])
else:
s = 'set for %s' % utils.timeElapsed(end_at-begin_at)
s = s + ' with %s more' % utils.timeElapsed(end_at-current)
s = s + ' and ends at [%s]' % floatToGMT(end_at)
s = 'set for %s, ' % utils.timeElapsed(end_at-begin_at)
remaining = end_at - current
if remaining >= 0:
s += ' with %s more,' % utils.timeElapsed(remaining)
s += ' and ends at [%s]' % floatToGMT(end_at)
else:
s += ' expired %s,' % utils.timeElapsed(remaining)
s += ' and ended at [%s]' % floatToGMT(end_at)
results.append([channel, s])
else:
s = 'was active %s and ended on [%s]' % (
utils.timeElapsed(removed_at-begin_at), floatToGMT(removed_at))
if end_at != begin_at:
s = s + ', initially for %s' % utils.timeElapsed(end_at-begin_at)
s = s + ', removed by %s' % removed_by
s += ', initially for %s' % utils.timeElapsed(end_at-begin_at)
s += ', removed by %s' % removed_by
results.append([channel,s])
c.execute("""SELECT oper,comment FROM comments WHERE ban_id=?""", (uid,))
L = c.fetchall()
@ -902,7 +907,7 @@ class Ircd(object):
message = 'edited by %s: %s' % (prefix.split('!')[0], expires)
elif ct.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
message = '[%s] [#%s %s %s] edited by %s: %s' % (
ircutils.bold(channel), ircutils.mircColor(str(uid), 'yellow', 'black'),
ircutils.bold(channel), ircutils.mircColor(uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor('+%s' % kind, 'red')),
ircutils.mircColor(mask, 'light blue'), prefix.split('!')[0], expires)
else:
@ -3450,7 +3455,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
n.setPrefix(msg.prefix)
reason = ''
if len(msg.args) == 2:
reason = msg.args[1].lstrip().rstrip()
reason = msg.args[1].strip()
canRemove = True
for channel in channels:
if isBot and channel in i.channels:
@ -4310,7 +4315,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
(mode, value) = change
m = mode[1]
if value:
value = str(value).lstrip().rstrip()
value = str(value).strip()
item = None
if mode[0] == '+':
if m in self.registryValue('modesToAsk', channel=channel, network=irc.network) \
@ -4458,70 +4463,70 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'red')),
ircutils.mircColor(value, 'light blue')))
else:
msgs.append('[#%s %s %s]' % (
str(item.uid), mode, value))
item.uid, mode, value))
elif len(item.affects) > 1:
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s - %s users]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'red')),
ircutils.mircColor(value, 'light blue'),
str(len(item.affects))))
len(item.affects)))
else:
msgs.append('[#%s %s %s - %s users]' % (
str(item.uid), mode, value, str(len(item.affects))))
item.uid, mode, value, len(item.affects)))
else:
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s - %s]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'red')),
ircutils.mircColor(value, 'light blue'), item.affects[0]))
else:
msgs.append('[#%s %s %s - %s]' % (
str(item.uid), mode, value, item.affects[0]))
item.uid, mode, value, item.affects[0]))
else:
if not len(item.affects):
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s - %s]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'green')),
ircutils.mircColor(value, 'light blue'),
str(utils.timeElapsed(item.removed_at-item.when))))
utils.timeElapsed(item.removed_at-item.when)))
else:
msgs.append('[#%s %s %s - %s]' % (
str(item.uid), mode, value,
str(utils.timeElapsed(item.removed_at-item.when))))
item.uid, mode, value,
utils.timeElapsed(item.removed_at-item.when)))
elif len(item.affects) > 1:
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s - %s users, %s]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'green')),
ircutils.mircColor(value, 'light blue'), str(len(item.affects)),
str(utils.timeElapsed(item.removed_at-item.when))))
ircutils.mircColor(value, 'light blue'), len(item.affects),
utils.timeElapsed(item.removed_at-item.when)))
else:
msgs.append('[#%s %s %s - %s users, %s]' % (
str(item.uid), mode, value, str(len(item.affects)),
str(utils.timeElapsed(item.removed_at-item.when))))
item.uid, mode, value, len(item.affects),
utils.timeElapsed(item.removed_at-item.when)))
else:
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
msgs.append('[#%s %s %s - %s, %s]' % (
ircutils.mircColor(str(item.uid), 'yellow', 'black'),
ircutils.mircColor(item.uid, 'yellow', 'black'),
ircutils.bold(ircutils.mircColor(mode, 'green')),
ircutils.mircColor(value, 'light blue'), item.affects[0],
str(utils.timeElapsed(item.removed_at-item.when))))
utils.timeElapsed(item.removed_at-item.when)))
else:
msgs.append('[#%s %s %s - %s, %s]' % (
str(item.uid), mode, value, item.affects[0],
str(utils.timeElapsed(item.removed_at-item.when))))
item.uid, mode, value, item.affects[0],
utils.timeElapsed(item.removed_at-item.when)))
else:
if m in announces:
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):

View File

@ -11,6 +11,12 @@ password = 'password'
filename = '/home/botaccount/data/networkname/ChanTracker.db'
channels = [] # empty to allow view of all channels recorded, otherwise restrict the views to channels
# httpd server address
if not standalone:
servaddr = '127.0.0.1'
else:
servaddr = ''
# usage python server.py
auth = '%s:%s' % (username,password)
base64string = base64.b64encode(auth.encode('utf-8')).decode('utf-8')
@ -24,54 +30,11 @@ def weblink():
weblink += '/?hash=%s' % base64string
return weblink
def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
weeks=True, days=True, hours=True, minutes=True, seconds=True):
"""Given <elapsed> seconds, returns a string with an English description of
how much time as passed. leadingZeroes determines whether 0 days, 0 hours,
etc. will be printed; the others determine what larger time periods should
be used.
"""
ret = []
def Format(s, i):
if i or leadingZeroes or ret:
if short:
ret.append('%s%s' % (i, s[0]))
else:
ret.append(format('%n', (i, s)))
elapsed = int(elapsed)
assert years or weeks or days or \
hours or minutes or seconds, 'One flag must be True'
if years:
(yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000)
Format('year', yrs)
if weeks:
(wks, elapsed) = (elapsed // 604800, elapsed % 604800)
Format('week', wks)
if days:
(ds, elapsed) = (elapsed // 86400, elapsed % 86400)
Format('day', ds)
if hours:
(hrs, elapsed) = (elapsed // 3600, elapsed % 3600)
Format('hour', hrs)
if minutes or seconds:
(mins, secs) = (elapsed // 60, elapsed % 60)
if leadingZeroes or mins:
Format('minute', mins)
if seconds:
leadingZeroes = True
Format('second', secs)
if not ret:
raise ValueError('Time difference not great enough to be noted.')
if short:
return ' '.join(ret)
else:
return format('%L', ret)
def htmlEscape(text):
return text.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;')
class MyHandler(http.server.BaseHTTPRequestHandler):
class BanTracker(http.server.BaseHTTPRequestHandler):
if not standalone:
def log_request(self, *args):
pass # disable logging
@ -174,13 +137,17 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
if was:
was = 'forever'
else:
was = timeElapsed(float(end_at) - float(begin_at))
was = utils.timeElapsed(float(end_at) - float(begin_at))
body.append('<p>Original duration: %s</p>' % was)
if not removed_at:
if was != 'forever':
body.append('<p>It will expire in %s</p>' % timeElapsed(float(end_at) - time.time()))
remaining = float(end_at) - time.time()
if remaining >= 0:
body.append('<p>It will expire in %s</p>' % utils.timeElapsed(remaining))
else:
body.append('<p>It expired %s</p>' % utils.timeElapsed(remaining))
else:
body.extend(['<p>Removed after %s' % timeElapsed(float(removed_at)-float(begin_at)),
body.extend(['<p>Removed after %s' % utils.timeElapsed(float(removed_at)-float(begin_at)),
'on %s' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))),
'by <a href="%s%s&amp;%s">%s</a></p>' % (h,q,utils.web.urlencode({'removed_by':removed_by}),removed_by)])
c.execute("""SELECT full,log FROM nicks WHERE ban_id=?""",(bid,))
@ -391,7 +358,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
return db
def httpd(handler_class=MyHandler, server_address=('', port)):
def httpd(handler_class=BanTracker, server_address=(servaddr, port)):
srvr = http.server.HTTPServer(server_address, handler_class)
srvr.serve_forever()