mirror of
https://github.com/ncoevoet/ChanTracker.git
synced 2025-04-25 20:41:19 -05:00
Account for over-expiration, set server address as needed.
This commit is contained in:
parent
789e01a28a
commit
4f320388dd
61
plugin.py
61
plugin.py
@ -396,16 +396,21 @@ class Ircd(object):
|
|||||||
if begin_at == end_at:
|
if begin_at == end_at:
|
||||||
results.append([channel, 'is set forever'])
|
results.append([channel, 'is set forever'])
|
||||||
else:
|
else:
|
||||||
s = 'set for %s' % utils.timeElapsed(end_at-begin_at)
|
s = 'set for %s, ' % utils.timeElapsed(end_at-begin_at)
|
||||||
s = s + ' with %s more' % utils.timeElapsed(end_at-current)
|
remaining = end_at - current
|
||||||
s = s + ' and ends at [%s]' % floatToGMT(end_at)
|
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])
|
results.append([channel, s])
|
||||||
else:
|
else:
|
||||||
s = 'was active %s and ended on [%s]' % (
|
s = 'was active %s and ended on [%s]' % (
|
||||||
utils.timeElapsed(removed_at-begin_at), floatToGMT(removed_at))
|
utils.timeElapsed(removed_at-begin_at), floatToGMT(removed_at))
|
||||||
if end_at != begin_at:
|
if end_at != begin_at:
|
||||||
s = s + ', initially for %s' % utils.timeElapsed(end_at-begin_at)
|
s += ', initially for %s' % utils.timeElapsed(end_at-begin_at)
|
||||||
s = s + ', removed by %s' % removed_by
|
s += ', removed by %s' % removed_by
|
||||||
results.append([channel,s])
|
results.append([channel,s])
|
||||||
c.execute("""SELECT oper,comment FROM comments WHERE ban_id=?""", (uid,))
|
c.execute("""SELECT oper,comment FROM comments WHERE ban_id=?""", (uid,))
|
||||||
L = c.fetchall()
|
L = c.fetchall()
|
||||||
@ -902,7 +907,7 @@ class Ircd(object):
|
|||||||
message = 'edited by %s: %s' % (prefix.split('!')[0], expires)
|
message = 'edited by %s: %s' % (prefix.split('!')[0], expires)
|
||||||
elif ct.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
elif ct.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
message = '[%s] [#%s %s %s] edited by %s: %s' % (
|
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.bold(ircutils.mircColor('+%s' % kind, 'red')),
|
||||||
ircutils.mircColor(mask, 'light blue'), prefix.split('!')[0], expires)
|
ircutils.mircColor(mask, 'light blue'), prefix.split('!')[0], expires)
|
||||||
else:
|
else:
|
||||||
@ -3450,7 +3455,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
n.setPrefix(msg.prefix)
|
n.setPrefix(msg.prefix)
|
||||||
reason = ''
|
reason = ''
|
||||||
if len(msg.args) == 2:
|
if len(msg.args) == 2:
|
||||||
reason = msg.args[1].lstrip().rstrip()
|
reason = msg.args[1].strip()
|
||||||
canRemove = True
|
canRemove = True
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
if isBot and channel in i.channels:
|
if isBot and channel in i.channels:
|
||||||
@ -4310,7 +4315,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
(mode, value) = change
|
(mode, value) = change
|
||||||
m = mode[1]
|
m = mode[1]
|
||||||
if value:
|
if value:
|
||||||
value = str(value).lstrip().rstrip()
|
value = str(value).strip()
|
||||||
item = None
|
item = None
|
||||||
if mode[0] == '+':
|
if mode[0] == '+':
|
||||||
if m in self.registryValue('modesToAsk', channel=channel, network=irc.network) \
|
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 m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s]' % (
|
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.bold(ircutils.mircColor(mode, 'red')),
|
||||||
ircutils.mircColor(value, 'light blue')))
|
ircutils.mircColor(value, 'light blue')))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s]' % (
|
msgs.append('[#%s %s %s]' % (
|
||||||
str(item.uid), mode, value))
|
item.uid, mode, value))
|
||||||
elif len(item.affects) > 1:
|
elif len(item.affects) > 1:
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s - %s users]' % (
|
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.bold(ircutils.mircColor(mode, 'red')),
|
||||||
ircutils.mircColor(value, 'light blue'),
|
ircutils.mircColor(value, 'light blue'),
|
||||||
str(len(item.affects))))
|
len(item.affects)))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s - %s users]' % (
|
msgs.append('[#%s %s %s - %s users]' % (
|
||||||
str(item.uid), mode, value, str(len(item.affects))))
|
item.uid, mode, value, len(item.affects)))
|
||||||
else:
|
else:
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s - %s]' % (
|
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.bold(ircutils.mircColor(mode, 'red')),
|
||||||
ircutils.mircColor(value, 'light blue'), item.affects[0]))
|
ircutils.mircColor(value, 'light blue'), item.affects[0]))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s - %s]' % (
|
msgs.append('[#%s %s %s - %s]' % (
|
||||||
str(item.uid), mode, value, item.affects[0]))
|
item.uid, mode, value, item.affects[0]))
|
||||||
else:
|
else:
|
||||||
if not len(item.affects):
|
if not len(item.affects):
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s - %s]' % (
|
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.bold(ircutils.mircColor(mode, 'green')),
|
||||||
ircutils.mircColor(value, 'light blue'),
|
ircutils.mircColor(value, 'light blue'),
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s - %s]' % (
|
msgs.append('[#%s %s %s - %s]' % (
|
||||||
str(item.uid), mode, value,
|
item.uid, mode, value,
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
elif len(item.affects) > 1:
|
elif len(item.affects) > 1:
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s - %s users, %s]' % (
|
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.bold(ircutils.mircColor(mode, 'green')),
|
||||||
ircutils.mircColor(value, 'light blue'), str(len(item.affects)),
|
ircutils.mircColor(value, 'light blue'), len(item.affects),
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s - %s users, %s]' % (
|
msgs.append('[#%s %s %s - %s users, %s]' % (
|
||||||
str(item.uid), mode, value, str(len(item.affects)),
|
item.uid, mode, value, len(item.affects),
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
else:
|
else:
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
msgs.append('[#%s %s %s - %s, %s]' % (
|
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.bold(ircutils.mircColor(mode, 'green')),
|
||||||
ircutils.mircColor(value, 'light blue'), item.affects[0],
|
ircutils.mircColor(value, 'light blue'), item.affects[0],
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
else:
|
else:
|
||||||
msgs.append('[#%s %s %s - %s, %s]' % (
|
msgs.append('[#%s %s %s - %s, %s]' % (
|
||||||
str(item.uid), mode, value, item.affects[0],
|
item.uid, mode, value, item.affects[0],
|
||||||
str(utils.timeElapsed(item.removed_at-item.when))))
|
utils.timeElapsed(item.removed_at-item.when)))
|
||||||
else:
|
else:
|
||||||
if m in announces:
|
if m in announces:
|
||||||
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
if self.registryValue('useColorForAnnounces', channel=channel, network=irc.network):
|
||||||
|
63
server.py
63
server.py
@ -11,6 +11,12 @@ password = 'password'
|
|||||||
filename = '/home/botaccount/data/networkname/ChanTracker.db'
|
filename = '/home/botaccount/data/networkname/ChanTracker.db'
|
||||||
channels = [] # empty to allow view of all channels recorded, otherwise restrict the views to channels
|
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
|
# usage python server.py
|
||||||
auth = '%s:%s' % (username,password)
|
auth = '%s:%s' % (username,password)
|
||||||
base64string = base64.b64encode(auth.encode('utf-8')).decode('utf-8')
|
base64string = base64.b64encode(auth.encode('utf-8')).decode('utf-8')
|
||||||
@ -24,54 +30,11 @@ def weblink():
|
|||||||
weblink += '/?hash=%s' % base64string
|
weblink += '/?hash=%s' % base64string
|
||||||
return weblink
|
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):
|
def htmlEscape(text):
|
||||||
return text.replace('&','&').replace('<','<').replace('>','>').replace('"','"')
|
return text.replace('&','&').replace('<','<').replace('>','>').replace('"','"')
|
||||||
|
|
||||||
|
|
||||||
class MyHandler(http.server.BaseHTTPRequestHandler):
|
class BanTracker(http.server.BaseHTTPRequestHandler):
|
||||||
if not standalone:
|
if not standalone:
|
||||||
def log_request(self, *args):
|
def log_request(self, *args):
|
||||||
pass # disable logging
|
pass # disable logging
|
||||||
@ -174,13 +137,17 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
if was:
|
if was:
|
||||||
was = 'forever'
|
was = 'forever'
|
||||||
else:
|
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)
|
body.append('<p>Original duration: %s</p>' % was)
|
||||||
if not removed_at:
|
if not removed_at:
|
||||||
if was != 'forever':
|
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:
|
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))),
|
'on %s' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))),
|
||||||
'by <a href="%s%s&%s">%s</a></p>' % (h,q,utils.web.urlencode({'removed_by':removed_by}),removed_by)])
|
'by <a href="%s%s&%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,))
|
c.execute("""SELECT full,log FROM nicks WHERE ban_id=?""",(bid,))
|
||||||
@ -391,7 +358,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
return db
|
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 = http.server.HTTPServer(server_address, handler_class)
|
||||||
srvr.serve_forever()
|
srvr.serve_forever()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user