From 83114e5fbd4568ad4efab2065f5c823a59603929 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 5 Dec 2019 21:11:01 +0100 Subject: [PATCH] src/callbacks.py: use network-specific values. Closes GH-1393 --- plugins/Conditional/plugin.py | 6 +++-- plugins/MessageParser/plugin.py | 3 ++- plugins/Scheduler/plugin.py | 3 ++- plugins/Utilities/plugin.py | 6 +++-- plugins/__init__.py | 3 ++- src/callbacks.py | 42 ++++++++++++++++++++++----------- src/conf.py | 8 ++----- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/plugins/Conditional/plugin.py b/plugins/Conditional/plugin.py index dc58ed4bc..4561282bb 100644 --- a/plugins/Conditional/plugin.py +++ b/plugins/Conditional/plugin.py @@ -63,7 +63,8 @@ class Conditional(callbacks.Plugin): def _runCommandFunction(self, irc, msg, command): """Run a command from message, as if command was sent over IRC.""" - tokens = callbacks.tokenize(command) + tokens = callbacks.tokenize(command, + channel=msg.channel, network=irc.network) try: self.Proxy(irc.irc, msg, tokens) except Exception as e: @@ -303,7 +304,8 @@ class Conditional(callbacks.Plugin): Runs and returns true if it raises an error; false otherwise. """ - tokens = callbacks.tokenize(testcommand) + tokens = callbacks.tokenize(testcommand, + channel=msg.channel, network=irc.network) InvalidCommand = collections.namedtuple('InvalidCommand', 'command') replies = [] diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index a14933576..0f210345f 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -129,7 +129,8 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): def _runCommandFunction(self, irc, msg, command): """Run a command from message, as if command was sent over IRC.""" - tokens = callbacks.tokenize(command) + tokens = callbacks.tokenize(command, + channel=msg.channel, network=irc.network) try: self.Proxy(irc.irc, msg, tokens) except Exception as e: diff --git a/plugins/Scheduler/plugin.py b/plugins/Scheduler/plugin.py index 19c929ab1..e8c279036 100644 --- a/plugins/Scheduler/plugin.py +++ b/plugins/Scheduler/plugin.py @@ -112,7 +112,8 @@ class Scheduler(callbacks.Plugin): def _makeCommandFunction(self, irc, msg, command, remove=True): """Makes a function suitable for scheduling from command.""" - tokens = callbacks.tokenize(command) + tokens = callbacks.tokenize(command, + channel=msg.channel, network=irc.network) def f(): if remove: del self.events[str(f.eventId)] diff --git a/plugins/Utilities/plugin.py b/plugins/Utilities/plugin.py index 4bcbf6a58..3bb673014 100644 --- a/plugins/Utilities/plugin.py +++ b/plugins/Utilities/plugin.py @@ -146,7 +146,8 @@ class Utilities(callbacks.Plugin): text = ' '.join(args) commands = command.split() commands = list(map(callbacks.canonicalName, commands)) - tokens = callbacks.tokenize(text) + tokens = callbacks.tokenize(text, + channel=msg.channel, network=irc.network) allTokens = commands + tokens self.Proxy(irc, msg, allTokens) apply = wrap(apply, ['something', many('something')]) @@ -167,7 +168,8 @@ class Utilities(callbacks.Plugin): if fake_msg.reply_env is None: fake_msg.reply_env = {} fake_msg.reply_env[var_name] = value - tokens = callbacks.tokenize(command) + tokens = callbacks.tokenize(command, + channel=msg.channel, network=irc.network) self.Proxy(irc, fake_msg, tokens) let = wrap(let, [ diff --git a/plugins/__init__.py b/plugins/__init__.py index 62b7f2362..0a331b24c 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -350,7 +350,8 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): user = ircdb.users.getUser(prefix) return user.id except KeyError: - if conf.get(conf.supybot.databases.plugins.requireRegistration, channel): + if conf.get(conf.supybot.databases.plugins.requireRegistration, + channel=channel, network=irc.network): irc.errorNotRegistered(Raise=True) return diff --git a/src/callbacks.py b/src/callbacks.py index 8a41dee67..bde7536de 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -178,14 +178,19 @@ def _makeReply(irc, msg, s, else: channel = None if notice is None: - notice = conf.get(conf.supybot.reply.withNotice, channel) + notice = conf.get(conf.supybot.reply.withNotice, + channel=channel, network=irc.network) if private is None: - private = conf.get(conf.supybot.reply.inPrivate, channel) + private = conf.get(conf.supybot.reply.inPrivate, + channel=channel, network=irc.network) if prefixNick is None: - prefixNick = conf.get(conf.supybot.reply.withNickPrefix, channel) + prefixNick = conf.get(conf.supybot.reply.withNickPrefix, + channel=channel, network=irc.network) if error: - notice =conf.get(conf.supybot.reply.error.withNotice, channel) or notice - private=conf.get(conf.supybot.reply.error.inPrivate, channel) or private + notice =conf.get(conf.supybot.reply.error.withNotice, + channel=channel, network=irc.network) or notice + private=conf.get(conf.supybot.reply.error.inPrivate, + channel=channel, network=irc.network) or private s = _('Error: ') + s if private: prefixNick = False @@ -383,7 +388,8 @@ def tokenize(s, channel=None, network=None): nested = conf.supybot.commands.nested if nested(): brackets = nested.brackets.getSpecific(network, channel)() - if conf.get(nested.pipeSyntax, channel): # No nesting, no pipe. + if conf.get(nested.pipeSyntax, + channel=channel, network=network): # No nesting, no pipe. pipe = True quotes = conf.supybot.commands.quotes.getSpecific(network, channel)() try: @@ -439,7 +445,8 @@ class RichReplyMethods(object): return ircutils.standardSubstitute(self, self.msg, s) def _getConfig(self, wrapper): - return conf.get(wrapper, self.msg.channel) + return conf.get(wrapper, + channel=self.msg.channel, network=self.irc.network) def replySuccess(self, s='', **kwargs): v = self._getConfig(conf.supybot.replies.success) @@ -484,7 +491,8 @@ class RichReplyMethods(object): to = self._getTarget(kwargs.get('to')) if oneToOne is None: # Can be True, False, or None if self.irc.isChannel(to): - oneToOne = conf.get(conf.supybot.reply.oneToOne, to) + oneToOne = conf.get(conf.supybot.reply.oneToOne, + channel=to, network=self.irc.network) else: oneToOne = conf.supybot.reply.oneToOne() if oneToOne: @@ -680,7 +688,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): self.noLengthCheck = None if self.msg.channel: self.prefixNick = conf.get(conf.supybot.reply.withNickPrefix, - self.msg.channel) + channel=self.msg.channel, network=self.irc.network) else: self.prefixNick = conf.supybot.reply.withNickPrefix() @@ -918,7 +926,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): else: s = ircutils.safeArgument(s) allowedLength = conf.get(conf.supybot.reply.mores.length, - target) + channel=target, network=self.irc.network) if not allowedLength: # 0 indicates this. allowedLength = (512 - len(':') - len(self.irc.prefix) @@ -930,7 +938,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): if self.prefixNick: allowedLength -= len(msg.nick) + len(': ') maximumMores = conf.get(conf.supybot.reply.mores.maximum, - target) + channel=target, network=self.irc.network) maximumLength = allowedLength * maximumMores if len(s) > maximumLength: log.warning('Truncating to %s bytes from %s bytes.', @@ -938,7 +946,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): s = s[:maximumLength] s_size = len(s.encode()) if minisix.PY3 else len(s) if s_size <= allowedLength or \ - not conf.get(conf.supybot.reply.mores, target): + not conf.get(conf.supybot.reply.mores, + channel=target, network=self.irc.network): # There's no need for action=self.action here because # action implies noLengthCheck, which has already been # handled. Let's stick an assert in here just in case. @@ -955,7 +964,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): allowedLength -= len(_('(XX more messages)')) + 1 # bold msgs = ircutils.wrap(s, allowedLength) msgs.reverse() - instant = conf.get(conf.supybot.reply.mores.instant,target) + instant = conf.get(conf.supybot.reply.mores.instant, + channel=target, network=self.irc.network) while instant > 1 and msgs: instant -= 1 response = msgs.pop() @@ -1358,10 +1368,14 @@ class Commands(BasePlugin, SynchronizedAndFirewalled): method = self.getCommandMethod(command) help = getHelp chan = None + net = None if dynamic.msg is not None: chan = dynamic.msg.channel + if dynamic.irc is not None: + net = dynamic.irc.network if simpleSyntax is None: - simpleSyntax = conf.get(conf.supybot.reply.showSimpleSyntax, chan) + simpleSyntax = conf.get(conf.supybot.reply.showSimpleSyntax, + channel=chan, network=net) if simpleSyntax: help = getSyntax if hasattr(method, '__doc__'): diff --git a/src/conf.py b/src/conf.py index 720725f9b..9f54c6b7c 100644 --- a/src/conf.py +++ b/src/conf.py @@ -136,12 +136,8 @@ def registerPlugin(name, currentValue=None, public=True): registerGroup(users.plugins, name) return group -def get(group, channel=None): - if group.channelValue and \ - channel is not None and ircutils.isChannel(channel): - return group.get(channel)() - else: - return group() +def get(group, channel=None, network=None): + return group.getSpecific(channel=channel, network=network)() ### # The user info registry.