mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 19:14:09 +01:00
src/callbacks.py: use network-specific values.
Closes GH-1393
This commit is contained in:
parent
1ed47f802f
commit
83114e5fbd
@ -63,7 +63,8 @@ class Conditional(callbacks.Plugin):
|
|||||||
|
|
||||||
def _runCommandFunction(self, irc, msg, command):
|
def _runCommandFunction(self, irc, msg, command):
|
||||||
"""Run a command from message, as if command was sent over IRC."""
|
"""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:
|
try:
|
||||||
self.Proxy(irc.irc, msg, tokens)
|
self.Proxy(irc.irc, msg, tokens)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -303,7 +304,8 @@ class Conditional(callbacks.Plugin):
|
|||||||
Runs <testcommand> and returns true if it raises an error;
|
Runs <testcommand> and returns true if it raises an error;
|
||||||
false otherwise.
|
false otherwise.
|
||||||
"""
|
"""
|
||||||
tokens = callbacks.tokenize(testcommand)
|
tokens = callbacks.tokenize(testcommand,
|
||||||
|
channel=msg.channel, network=irc.network)
|
||||||
InvalidCommand = collections.namedtuple('InvalidCommand',
|
InvalidCommand = collections.namedtuple('InvalidCommand',
|
||||||
'command')
|
'command')
|
||||||
replies = []
|
replies = []
|
||||||
|
@ -129,7 +129,8 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
|
|
||||||
def _runCommandFunction(self, irc, msg, command):
|
def _runCommandFunction(self, irc, msg, command):
|
||||||
"""Run a command from message, as if command was sent over IRC."""
|
"""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:
|
try:
|
||||||
self.Proxy(irc.irc, msg, tokens)
|
self.Proxy(irc.irc, msg, tokens)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -112,7 +112,8 @@ class Scheduler(callbacks.Plugin):
|
|||||||
|
|
||||||
def _makeCommandFunction(self, irc, msg, command, remove=True):
|
def _makeCommandFunction(self, irc, msg, command, remove=True):
|
||||||
"""Makes a function suitable for scheduling from command."""
|
"""Makes a function suitable for scheduling from command."""
|
||||||
tokens = callbacks.tokenize(command)
|
tokens = callbacks.tokenize(command,
|
||||||
|
channel=msg.channel, network=irc.network)
|
||||||
def f():
|
def f():
|
||||||
if remove:
|
if remove:
|
||||||
del self.events[str(f.eventId)]
|
del self.events[str(f.eventId)]
|
||||||
|
@ -146,7 +146,8 @@ class Utilities(callbacks.Plugin):
|
|||||||
text = ' '.join(args)
|
text = ' '.join(args)
|
||||||
commands = command.split()
|
commands = command.split()
|
||||||
commands = list(map(callbacks.canonicalName, commands))
|
commands = list(map(callbacks.canonicalName, commands))
|
||||||
tokens = callbacks.tokenize(text)
|
tokens = callbacks.tokenize(text,
|
||||||
|
channel=msg.channel, network=irc.network)
|
||||||
allTokens = commands + tokens
|
allTokens = commands + tokens
|
||||||
self.Proxy(irc, msg, allTokens)
|
self.Proxy(irc, msg, allTokens)
|
||||||
apply = wrap(apply, ['something', many('something')])
|
apply = wrap(apply, ['something', many('something')])
|
||||||
@ -167,7 +168,8 @@ class Utilities(callbacks.Plugin):
|
|||||||
if fake_msg.reply_env is None:
|
if fake_msg.reply_env is None:
|
||||||
fake_msg.reply_env = {}
|
fake_msg.reply_env = {}
|
||||||
fake_msg.reply_env[var_name] = value
|
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)
|
self.Proxy(irc, fake_msg, tokens)
|
||||||
|
|
||||||
let = wrap(let, [
|
let = wrap(let, [
|
||||||
|
@ -350,7 +350,8 @@ class ChannelIdDatabasePlugin(callbacks.Plugin):
|
|||||||
user = ircdb.users.getUser(prefix)
|
user = ircdb.users.getUser(prefix)
|
||||||
return user.id
|
return user.id
|
||||||
except KeyError:
|
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)
|
irc.errorNotRegistered(Raise=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -178,14 +178,19 @@ def _makeReply(irc, msg, s,
|
|||||||
else:
|
else:
|
||||||
channel = None
|
channel = None
|
||||||
if notice is 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:
|
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:
|
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:
|
if error:
|
||||||
notice =conf.get(conf.supybot.reply.error.withNotice, channel) or notice
|
notice =conf.get(conf.supybot.reply.error.withNotice,
|
||||||
private=conf.get(conf.supybot.reply.error.inPrivate, channel) or private
|
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
|
s = _('Error: ') + s
|
||||||
if private:
|
if private:
|
||||||
prefixNick = False
|
prefixNick = False
|
||||||
@ -383,7 +388,8 @@ def tokenize(s, channel=None, network=None):
|
|||||||
nested = conf.supybot.commands.nested
|
nested = conf.supybot.commands.nested
|
||||||
if nested():
|
if nested():
|
||||||
brackets = nested.brackets.getSpecific(network, channel)()
|
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
|
pipe = True
|
||||||
quotes = conf.supybot.commands.quotes.getSpecific(network, channel)()
|
quotes = conf.supybot.commands.quotes.getSpecific(network, channel)()
|
||||||
try:
|
try:
|
||||||
@ -439,7 +445,8 @@ class RichReplyMethods(object):
|
|||||||
return ircutils.standardSubstitute(self, self.msg, s)
|
return ircutils.standardSubstitute(self, self.msg, s)
|
||||||
|
|
||||||
def _getConfig(self, wrapper):
|
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):
|
def replySuccess(self, s='', **kwargs):
|
||||||
v = self._getConfig(conf.supybot.replies.success)
|
v = self._getConfig(conf.supybot.replies.success)
|
||||||
@ -484,7 +491,8 @@ class RichReplyMethods(object):
|
|||||||
to = self._getTarget(kwargs.get('to'))
|
to = self._getTarget(kwargs.get('to'))
|
||||||
if oneToOne is None: # Can be True, False, or None
|
if oneToOne is None: # Can be True, False, or None
|
||||||
if self.irc.isChannel(to):
|
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:
|
else:
|
||||||
oneToOne = conf.supybot.reply.oneToOne()
|
oneToOne = conf.supybot.reply.oneToOne()
|
||||||
if oneToOne:
|
if oneToOne:
|
||||||
@ -680,7 +688,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
self.noLengthCheck = None
|
self.noLengthCheck = None
|
||||||
if self.msg.channel:
|
if self.msg.channel:
|
||||||
self.prefixNick = conf.get(conf.supybot.reply.withNickPrefix,
|
self.prefixNick = conf.get(conf.supybot.reply.withNickPrefix,
|
||||||
self.msg.channel)
|
channel=self.msg.channel, network=self.irc.network)
|
||||||
else:
|
else:
|
||||||
self.prefixNick = conf.supybot.reply.withNickPrefix()
|
self.prefixNick = conf.supybot.reply.withNickPrefix()
|
||||||
|
|
||||||
@ -918,7 +926,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
else:
|
else:
|
||||||
s = ircutils.safeArgument(s)
|
s = ircutils.safeArgument(s)
|
||||||
allowedLength = conf.get(conf.supybot.reply.mores.length,
|
allowedLength = conf.get(conf.supybot.reply.mores.length,
|
||||||
target)
|
channel=target, network=self.irc.network)
|
||||||
if not allowedLength: # 0 indicates this.
|
if not allowedLength: # 0 indicates this.
|
||||||
allowedLength = (512
|
allowedLength = (512
|
||||||
- len(':') - len(self.irc.prefix)
|
- len(':') - len(self.irc.prefix)
|
||||||
@ -930,7 +938,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
if self.prefixNick:
|
if self.prefixNick:
|
||||||
allowedLength -= len(msg.nick) + len(': ')
|
allowedLength -= len(msg.nick) + len(': ')
|
||||||
maximumMores = conf.get(conf.supybot.reply.mores.maximum,
|
maximumMores = conf.get(conf.supybot.reply.mores.maximum,
|
||||||
target)
|
channel=target, network=self.irc.network)
|
||||||
maximumLength = allowedLength * maximumMores
|
maximumLength = allowedLength * maximumMores
|
||||||
if len(s) > maximumLength:
|
if len(s) > maximumLength:
|
||||||
log.warning('Truncating to %s bytes from %s bytes.',
|
log.warning('Truncating to %s bytes from %s bytes.',
|
||||||
@ -938,7 +946,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
s = s[:maximumLength]
|
s = s[:maximumLength]
|
||||||
s_size = len(s.encode()) if minisix.PY3 else len(s)
|
s_size = len(s.encode()) if minisix.PY3 else len(s)
|
||||||
if s_size <= allowedLength or \
|
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
|
# There's no need for action=self.action here because
|
||||||
# action implies noLengthCheck, which has already been
|
# action implies noLengthCheck, which has already been
|
||||||
# handled. Let's stick an assert in here just in case.
|
# 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
|
allowedLength -= len(_('(XX more messages)')) + 1 # bold
|
||||||
msgs = ircutils.wrap(s, allowedLength)
|
msgs = ircutils.wrap(s, allowedLength)
|
||||||
msgs.reverse()
|
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:
|
while instant > 1 and msgs:
|
||||||
instant -= 1
|
instant -= 1
|
||||||
response = msgs.pop()
|
response = msgs.pop()
|
||||||
@ -1358,10 +1368,14 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
method = self.getCommandMethod(command)
|
method = self.getCommandMethod(command)
|
||||||
help = getHelp
|
help = getHelp
|
||||||
chan = None
|
chan = None
|
||||||
|
net = None
|
||||||
if dynamic.msg is not None:
|
if dynamic.msg is not None:
|
||||||
chan = dynamic.msg.channel
|
chan = dynamic.msg.channel
|
||||||
|
if dynamic.irc is not None:
|
||||||
|
net = dynamic.irc.network
|
||||||
if simpleSyntax is None:
|
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:
|
if simpleSyntax:
|
||||||
help = getSyntax
|
help = getSyntax
|
||||||
if hasattr(method, '__doc__'):
|
if hasattr(method, '__doc__'):
|
||||||
|
@ -136,12 +136,8 @@ def registerPlugin(name, currentValue=None, public=True):
|
|||||||
registerGroup(users.plugins, name)
|
registerGroup(users.plugins, name)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def get(group, channel=None):
|
def get(group, channel=None, network=None):
|
||||||
if group.channelValue and \
|
return group.getSpecific(channel=channel, network=network)()
|
||||||
channel is not None and ircutils.isChannel(channel):
|
|
||||||
return group.get(channel)()
|
|
||||||
else:
|
|
||||||
return group()
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# The user info registry.
|
# The user info registry.
|
||||||
|
Loading…
Reference in New Issue
Block a user