mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Let's try to respect some channel values, shall we?
This commit is contained in:
parent
5ec79236a3
commit
8a4e79e007
@ -124,13 +124,26 @@ def canonicalName(command):
|
|||||||
return command.translate(string.ascii, special).lower() + reAppend
|
return command.translate(string.ascii, special).lower() + reAppend
|
||||||
|
|
||||||
def reply(msg, s, prefixName=True, private=None,
|
def reply(msg, s, prefixName=True, private=None,
|
||||||
notice=None, to=None, action=None):
|
notice=None, to=None, action=None, error=False):
|
||||||
# Ok, let's make the target:
|
# Ok, let's make the target:
|
||||||
target = ircutils.replyTo(msg)
|
target = ircutils.replyTo(msg)
|
||||||
|
def getConfig(wrapper):
|
||||||
|
if ircutils.isChannel(target):
|
||||||
|
return wrapper.get(target)()
|
||||||
|
else:
|
||||||
|
return wrapper()
|
||||||
|
if ircutils.isChannel(target):
|
||||||
|
channel = target
|
||||||
|
else:
|
||||||
|
channel = None
|
||||||
if notice is None:
|
if notice is None:
|
||||||
notice = conf.supybot.reply.withNotice()
|
notice = getConfig(conf.supybot.reply.withNotice)
|
||||||
if private is None:
|
if private is None:
|
||||||
private = conf.supybot.reply.inPrivate()
|
private = getConfig(conf.supybot.reply.inPrivate)
|
||||||
|
if error:
|
||||||
|
notice = getConfig(conf.supybot.reply.errorWithNotice) or notice
|
||||||
|
private = getConfig(conf.supybot.reply.errorInPrivate) or private
|
||||||
|
s = 'Error: ' + s
|
||||||
if private:
|
if private:
|
||||||
prefixName = False
|
prefixName = False
|
||||||
if to is None:
|
if to is None:
|
||||||
@ -158,13 +171,10 @@ def reply(msg, s, prefixName=True, private=None,
|
|||||||
# Finally, we'll return the actual message.
|
# Finally, we'll return the actual message.
|
||||||
return msgmaker(target, s)
|
return msgmaker(target, s)
|
||||||
|
|
||||||
def error(msg, s, private=None, notice=None, **kwargs):
|
def error(msg, s, **kwargs):
|
||||||
"""Makes an error reply to msg with the appropriate error payload."""
|
"""Makes an error reply to msg with the appropriate error payload."""
|
||||||
if notice is None:
|
kwargs['error'] = True
|
||||||
notice = conf.supybot.reply.errorWithNotice()
|
return reply(msg, s, **kwargs)
|
||||||
if private is None:
|
|
||||||
private = conf.supybot.reply.errorInPrivate()
|
|
||||||
return reply(msg, 'Error: ' + s, private=private, notice=notice, **kwargs)
|
|
||||||
|
|
||||||
def getHelp(method, name=None):
|
def getHelp(method, name=None):
|
||||||
if name is None:
|
if name is None:
|
||||||
@ -693,10 +703,11 @@ class IrcObjectProxy(RichReplyMethods):
|
|||||||
else:
|
else:
|
||||||
self.irc.queueMsg(error(self.msg, s, **kwargs))
|
self.irc.queueMsg(error(self.msg, s, **kwargs))
|
||||||
else:
|
else:
|
||||||
# No argument, let's raise ArgumentError.
|
|
||||||
if self.commandMethod is not None:
|
if self.commandMethod is not None:
|
||||||
# We can recurse here because it only gets called once.
|
# We can recurse here because it only gets called once.
|
||||||
self.error(formatArgumentError(self.commandMethod), **kwargs)
|
self.error(formatArgumentError(self.commandMethod), **kwargs)
|
||||||
|
else:
|
||||||
|
raise ArgumentError # We shouldn't get here, but just in case.
|
||||||
self.finished = True
|
self.finished = True
|
||||||
|
|
||||||
def getRealIrc(self):
|
def getRealIrc(self):
|
||||||
|
18
src/conf.py
18
src/conf.py
@ -89,10 +89,12 @@ def registerGroup(Group, name, group=None):
|
|||||||
return Group.register(name, group)
|
return Group.register(name, group)
|
||||||
|
|
||||||
def registerGlobalValue(group, name, value):
|
def registerGlobalValue(group, name, value):
|
||||||
|
value.channelValue = False
|
||||||
return group.register(name, value)
|
return group.register(name, value)
|
||||||
|
|
||||||
def registerChannelValue(group, name, value):
|
def registerChannelValue(group, name, value):
|
||||||
value.supplyDefault = True
|
value.supplyDefault = True
|
||||||
|
value.channelValue = True
|
||||||
return group.register(name, value)
|
return group.register(name, value)
|
||||||
|
|
||||||
def registerPlugin(name, currentValue=None, public=True):
|
def registerPlugin(name, currentValue=None, public=True):
|
||||||
@ -246,7 +248,10 @@ registerChannelValue(supybot, 'prefixChars',
|
|||||||
|
|
||||||
class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
|
class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
|
||||||
List = ircutils.IrcSet
|
List = ircutils.IrcSet
|
||||||
def setValue(self, v):
|
# We use a keyword argument trick here to prevent eval'ing of code that
|
||||||
|
# changes allowDefaultOwner from affecting this. It's not perfect, but
|
||||||
|
# it's still an improvement, raising the bar for potential crackers.
|
||||||
|
def setValue(self, v, allowDefaultOwner=allowDefaultOwner):
|
||||||
registry.SpaceSeparatedListOfStrings.setValue(self, v)
|
registry.SpaceSeparatedListOfStrings.setValue(self, v)
|
||||||
if '-owner' not in self.value and not allowDefaultOwner:
|
if '-owner' not in self.value and not allowDefaultOwner:
|
||||||
print '*** You must run supybot with the --allow-default-owner'
|
print '*** You must run supybot with the --allow-default-owner'
|
||||||
@ -348,11 +353,14 @@ registerChannelValue(supybot.reply, 'noCapabilityError',
|
|||||||
users to understand the underlying security system preventing them from
|
users to understand the underlying security system preventing them from
|
||||||
running certain commands."""))
|
running certain commands."""))
|
||||||
|
|
||||||
registerChannelValue(supybot.reply, 'withPrivateNotice',
|
registerChannelValue(supybot.reply, 'inPrivate',
|
||||||
|
registry.Boolean(False, """Determines whether the bot will reply privately
|
||||||
|
when replying in a channel, rather than replying to the whole channel."""))
|
||||||
|
|
||||||
|
registerChannelValue(supybot.reply, 'withNotice',
|
||||||
registry.Boolean(False, """Determines whether the bot will reply with a
|
registry.Boolean(False, """Determines whether the bot will reply with a
|
||||||
private notice to users rather than sending a message to a channel.
|
notice when replying in a channel, rather than replying with a privmsg as
|
||||||
Private notices are particularly nice because they don't generally cause
|
normal."""))
|
||||||
IRC clients to open a new query window."""))
|
|
||||||
|
|
||||||
# XXX: User value.
|
# XXX: User value.
|
||||||
registerGlobalValue(supybot.reply, 'withNoticeWhenPrivate',
|
registerGlobalValue(supybot.reply, 'withNoticeWhenPrivate',
|
||||||
|
@ -256,7 +256,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
|||||||
def testErrorPrivateKwarg(self):
|
def testErrorPrivateKwarg(self):
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.reply.errorInPrivate()
|
original = conf.supybot.reply.errorInPrivate()
|
||||||
conf.supybot.reply.errorInPrivate.set('False')
|
conf.supybot.reply.errorInPrivate.setValue(False)
|
||||||
m = self.getMsg("eval irc.error('foo', private=True)")
|
m = self.getMsg("eval irc.error('foo', private=True)")
|
||||||
self.failIf(ircutils.isChannel(m.args[0]))
|
self.failIf(ircutils.isChannel(m.args[0]))
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user