From 789e01a28a0959e71aab2bff03d382315e43688b Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Wed, 2 Mar 2022 02:17:04 +0100 Subject: [PATCH] Add 'weblink' function to provide link to web UI. --- __init__.py | 8 ++++++-- plugin.py | 20 +++++++++++++++++++- server.py | 8 ++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 0a9ec5d..83729eb 100644 --- a/__init__.py +++ b/__init__.py @@ -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! diff --git a/plugin.py b/plugin.py index 3c053d9..3a4ab3f 100644 --- a/plugin.py +++ b/plugin.py @@ -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): """[] @@ -2166,7 +2184,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler): copy elements in on ; <-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([]) diff --git a/server.py b/server.py index f5124a0..0127427 100644 --- a/server.py +++ b/server.py @@ -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):