Add 'weblink' function to provide link to web UI.

This commit is contained in:
Krytarik Raido 2022-03-02 02:17:04 +01:00
parent 2990b35f13
commit 789e01a28a
3 changed files with 33 additions and 3 deletions

View File

@ -50,8 +50,12 @@ __url__ = 'https://github.com/ncoevoet/ChanTracker'
from . import config
from . import plugin
from imp import reload
reload(plugin) # In case we're being reloaded.
from . import server
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)
reload(server)
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -40,6 +40,7 @@ from supybot.commands import *
from supybot import utils, ircutils, ircmsgs, ircdb, plugins, callbacks
from supybot import conf, registry, log, schedule, world
from . import server
# due to more kind of pattern checked, increase size
ircutils._hostmaskPatternEqualCache = utils.structures.CacheDict(10000)
@ -1539,6 +1540,23 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
schedule.addEvent(self.checkNag, time.time() +
self.registryValue('announceNagInterval'), 'ChanTracker')
def weblink(self, irc, msg, args, user):
"""takes no arguments
provides link to web interface"""
allowed = False
for capab in user.capabilities:
if capab in ('owner', 'admin') or capab.endswith(',op'):
allowed = True
break
if allowed:
irc.queueMsg(ircmsgs.privmsg(msg.nick, server.weblink()))
else:
irc.errorNoCapability('#channel,op')
self.forceTickle = True
self._tickle(irc)
weblink = wrap(weblink, ['user'])
def summary(self, irc, msg, args, channel):
"""[<channel>]
@ -2166,7 +2184,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
copy <channelSource> <channelMode> elements in <channelTarget> on <targetMode>; <-1> or empty means forever"""
op = ircdb.makeChannelCapability(target, 'protected')
if not ircdb.checkCapability(msg.prefix, op):
irc.replyError('you are missing %s,op capability' % target)
irc.errorNoCapability('%s,op' % target)
return
chan = self.getChan(irc, channel)
targets = set([])

View File

@ -15,6 +15,14 @@ channels = [] # empty to allow view of all channels recorded, otherwise restrict
auth = '%s:%s' % (username,password)
base64string = base64.b64encode(auth.encode('utf-8')).decode('utf-8')
def weblink():
weblink = host
if standalone:
weblink += ':%s' % port
else:
weblink += webpath
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):