From bfa65ed8c3eb3a4592b346c1774eba11a85544fe Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Mon, 10 Oct 2022 23:56:04 +0200 Subject: [PATCH] Encyclopedia, PackageInfo: Add '!more' command. So unprivileged users can page through multi-message outputs. Also make PackageInfo stop processing requests twice in case of privileged users PM'ing the bot with unprefixed commands, and make it possible to address the bot with prefixed commands for unprivileged use. --- Encyclopedia/__init__.py | 2 +- Encyclopedia/config.py | 2 +- Encyclopedia/plugin.py | 18 +++++++++++++----- PackageInfo/__init__.py | 2 +- PackageInfo/plugin.py | 19 ++++++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Encyclopedia/__init__.py b/Encyclopedia/__init__.py index ef77e56..6320295 100644 --- a/Encyclopedia/__init__.py +++ b/Encyclopedia/__init__.py @@ -24,7 +24,7 @@ import supybot import supybot.world as world from importlib import reload -__version__ = "4.2.0" +__version__ = "4.3.0" __author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com") __contributors__ = { supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'], diff --git a/Encyclopedia/config.py b/Encyclopedia/config.py index de8acb4..53a2c54 100644 --- a/Encyclopedia/config.py +++ b/Encyclopedia/config.py @@ -205,7 +205,7 @@ conf.registerChannelValue(Encyclopedia, 'remotedb', registry.String('https://ubottu.com/ubuntu.db', 'Remote location of the master database', private=True)) conf.registerChannelValue(Encyclopedia, 'ignores', - registry.SpaceSeparatedListOfStrings(['info', 'depends', 'find'], 'Factoid names to ignore', private=True)) + registry.SpaceSeparatedListOfStrings(['info', 'depends', 'find', 'more'], 'Factoid names to ignore', private=True)) conf.registerChannelValue(Encyclopedia, 'repeatdelay', registry.Integer(60, "Number of seconds to wait between repeated factoid calls")) diff --git a/Encyclopedia/plugin.py b/Encyclopedia/plugin.py index 1d49626..68e852c 100644 --- a/Encyclopedia/plugin.py +++ b/Encyclopedia/plugin.py @@ -432,17 +432,21 @@ class Encyclopedia(callbacks.Plugin): if not channel: args = text.lower().split(None, 2) - for c in irc.callbacks: - if (args[0] == c.name().lower() and len(args) > 1 - and c.isCommandMethod(args[1])) \ - or c.isCommandMethod(args[0]): - return + if args[0] != "more": + for c in irc.callbacks: + if (args[0] == c.name().lower() and len(args) > 1 + and c.isCommandMethod(args[1])) \ + or c.isCommandMethod(args[0]): + return prefixchar = self.registryValue('prefixchar', channel) + prefixed = False if text[0] == prefixchar: text = text[1:].strip() + prefixed = True elif re.match(r'^%s[\W\s]\s*%s' % (re.escape(irc.nick), re.escape(prefixchar)), text, re.I): text = re.sub(r'^%s[\W\s]\s*%s\s*' % (re.escape(irc.nick), re.escape(prefixchar)), '', text, flags=re.I) + prefixed = True elif channel: return if not text: @@ -479,6 +483,10 @@ class Encyclopedia(callbacks.Plugin): ret = "Search factoids for term: !search " target = term[1] retmsg = term[2] + elif lower_term == "more": + if prefixed or defaultIgnored(msg.prefix): + callbacks.NestedCommandsIrcProxy(irc, msg, ["Misc", "more"]) + return elif re.match(r"^seen\b", lower_term): # Some people expect a '!seen ' command ret = "I have no seen command" retmsg = "%s: " % msg.nick if term[2] else '' # Redirect back at the caller, rather than the target diff --git a/PackageInfo/__init__.py b/PackageInfo/__init__.py index 45c8112..956c5d9 100644 --- a/PackageInfo/__init__.py +++ b/PackageInfo/__init__.py @@ -22,7 +22,7 @@ import supybot import supybot.world as world from importlib import reload -__version__ = "2.6.0" +__version__ = "2.7.0" __author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com") __contributors__ = { supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Concept'], diff --git a/PackageInfo/plugin.py b/PackageInfo/plugin.py index 9131be2..7859ac6 100644 --- a/PackageInfo/plugin.py +++ b/PackageInfo/plugin.py @@ -221,20 +221,29 @@ class PackageInfo(callbacks.Plugin): if not text: return channel = msg.channel - if text[0] == self.registryValue("prefixchar", channel, irc.network): + prefixchar = self.registryValue("prefixchar", channel, irc.network) + prefixed = False + if text[0] == prefixchar: text = text[1:].strip() + prefixed = True + elif re.match(r'^%s[\W\s]\s*%s' % (re.escape(irc.nick), re.escape(prefixchar)), text, re.I): + text = re.sub(r'^%s[\W\s]\s*%s\s*' % (re.escape(irc.nick), re.escape(prefixchar)), '', text, flags=re.I) + prefixed = True elif channel or text[0] in conf.supybot.reply.whenAddressedBy.chars(): return + if not (prefixed or defaultIgnored(msg.prefix)): + return if not text: return (cmd, rest) = (text.split(None, 1) + [None])[:2] if not cmd: return cmd = cmd.lower() - if not (cmd in ("info", "depends", "find") and rest): - return - (package, release) = (rest.split(None, 1) + [''])[:2] - callbacks.NestedCommandsIrcProxy(irc, msg, ["PackageInfo", cmd, package, release]) + if cmd in ("info", "depends", "find") and rest: + (package, release) = (rest.split(None, 1) + [''])[:2] + callbacks.NestedCommandsIrcProxy(irc, msg, ["PackageInfo", cmd, package, release]) + elif cmd == "more": + callbacks.NestedCommandsIrcProxy(irc, msg, ["Misc", "more"]) def inFilter(self, irc, msg): if not (msg.prefix and msg.args):