mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 19:14:09 +01:00
Strip CTCP characters from irc.reply by default.
This commit is contained in:
parent
52517c8ca6
commit
6ec0af2da3
@ -65,7 +65,7 @@ class String(callbacks.Plugin):
|
|||||||
Returns the character associated with the 8-bit value <number>
|
Returns the character associated with the 8-bit value <number>
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
irc.reply(chr(i))
|
irc.reply(chr(i), stripCtcp=False)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(_('That number doesn\'t map to an 8-bit character.'))
|
irc.error(_('That number doesn\'t map to an 8-bit character.'))
|
||||||
chr = wrap(chr, ['int'])
|
chr = wrap(chr, ['int'])
|
||||||
|
@ -57,6 +57,9 @@ class UtilitiesTestCase(PluginTestCase):
|
|||||||
def testEchoStandardSubstitute(self):
|
def testEchoStandardSubstitute(self):
|
||||||
self.assertNotRegexp('echo $nick', r'\$')
|
self.assertNotRegexp('echo $nick', r'\$')
|
||||||
|
|
||||||
|
def testEchoStripCtcp(self):
|
||||||
|
self.assertResponse('echo \x01ACTION foo\x01', "ACTION foo")
|
||||||
|
|
||||||
def testApply(self):
|
def testApply(self):
|
||||||
self.assertResponse('apply "utilities last" a', 'a')
|
self.assertResponse('apply "utilities last" a', 'a')
|
||||||
self.assertResponse('apply "utilities last" a b', 'b')
|
self.assertResponse('apply "utilities last" a b', 'b')
|
||||||
|
@ -157,7 +157,8 @@ def canonicalName(command, preserve_spaces=False):
|
|||||||
return ''.join([x for x in command if x not in special]).lower() + reAppend
|
return ''.join([x for x in command if x not in special]).lower() + reAppend
|
||||||
|
|
||||||
def reply(msg, s, prefixNick=None, private=None,
|
def reply(msg, s, prefixNick=None, private=None,
|
||||||
notice=None, to=None, action=None, error=False):
|
notice=None, to=None, action=None, error=False,
|
||||||
|
stripCtcp=True):
|
||||||
msg.tag('repliedTo')
|
msg.tag('repliedTo')
|
||||||
# Ok, let's make the target:
|
# Ok, let's make the target:
|
||||||
# XXX This isn't entirely right. Consider to=#foo, private=True.
|
# XXX This isn't entirely right. Consider to=#foo, private=True.
|
||||||
@ -188,6 +189,8 @@ def reply(msg, s, prefixNick=None, private=None,
|
|||||||
prefixNick = False
|
prefixNick = False
|
||||||
if to is None:
|
if to is None:
|
||||||
to = msg.nick
|
to = msg.nick
|
||||||
|
if stripCtcp:
|
||||||
|
s = s.strip('\x01')
|
||||||
# Ok, now let's make the payload:
|
# Ok, now let's make the payload:
|
||||||
s = ircutils.safeArgument(s)
|
s = ircutils.safeArgument(s)
|
||||||
if not s and not action:
|
if not s and not action:
|
||||||
@ -824,7 +827,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
cb._callCommand(command, self, self.msg, args)
|
cb._callCommand(command, self, self.msg, args)
|
||||||
|
|
||||||
def reply(self, s, noLengthCheck=False, prefixNick=None, action=None,
|
def reply(self, s, noLengthCheck=False, prefixNick=None, action=None,
|
||||||
private=None, notice=None, to=None, msg=None, sendImmediately=False):
|
private=None, notice=None, to=None, msg=None,
|
||||||
|
sendImmediately=False, stripCtcp=True):
|
||||||
"""
|
"""
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
|
|
||||||
@ -880,7 +884,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
action=self.action,
|
action=self.action,
|
||||||
private=self.private,
|
private=self.private,
|
||||||
prefixNick=self.prefixNick,
|
prefixNick=self.prefixNick,
|
||||||
noLengthCheck=self.noLengthCheck)
|
noLengthCheck=self.noLengthCheck,
|
||||||
|
stripCtcp=stripCtcp)
|
||||||
elif self.noLengthCheck:
|
elif self.noLengthCheck:
|
||||||
# noLengthCheck only matters to NestedCommandsIrcProxy, so
|
# noLengthCheck only matters to NestedCommandsIrcProxy, so
|
||||||
# it's not used here. Just in case you were wondering.
|
# it's not used here. Just in case you were wondering.
|
||||||
@ -888,7 +893,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
notice=self.notice,
|
notice=self.notice,
|
||||||
action=self.action,
|
action=self.action,
|
||||||
private=self.private,
|
private=self.private,
|
||||||
prefixNick=self.prefixNick)
|
prefixNick=self.prefixNick,
|
||||||
|
stripCtcp=stripCtcp)
|
||||||
sendMsg(m)
|
sendMsg(m)
|
||||||
return m
|
return m
|
||||||
else:
|
else:
|
||||||
@ -917,11 +923,11 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
# "(XX more messages)" trailer.
|
# "(XX more messages)" trailer.
|
||||||
if minisix.PY3:
|
if minisix.PY3:
|
||||||
appended = _('(XX more messages)').encode()
|
appended = _('(XX more messages)').encode()
|
||||||
s = s.encode()[:allowedLength+len(appended)]
|
s = s.encode()[:allowedLength-len(appended)]
|
||||||
s = s.decode('utf8', 'ignore')
|
s = s.decode('utf8', 'ignore')
|
||||||
else:
|
else:
|
||||||
appended = _('(XX more messages)')
|
appended = _('(XX more messages)')
|
||||||
s = s[:allowedLength+len(appended)]
|
s = s[:allowedLength-len(appended)]
|
||||||
# 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.
|
||||||
@ -929,7 +935,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
m = reply(msg, s, to=self.to,
|
m = reply(msg, s, to=self.to,
|
||||||
notice=self.notice,
|
notice=self.notice,
|
||||||
private=self.private,
|
private=self.private,
|
||||||
prefixNick=self.prefixNick)
|
prefixNick=self.prefixNick,
|
||||||
|
stripCtcp=stripCtcp)
|
||||||
sendMsg(m)
|
sendMsg(m)
|
||||||
return m
|
return m
|
||||||
msgs = ircutils.wrap(s, allowedLength,
|
msgs = ircutils.wrap(s, allowedLength,
|
||||||
@ -942,7 +949,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
m = reply(msg, response, to=self.to,
|
m = reply(msg, response, to=self.to,
|
||||||
notice=self.notice,
|
notice=self.notice,
|
||||||
private=self.private,
|
private=self.private,
|
||||||
prefixNick=self.prefixNick)
|
prefixNick=self.prefixNick,
|
||||||
|
stripCtcp=stripCtcp)
|
||||||
sendMsg(m)
|
sendMsg(m)
|
||||||
# XXX We should somehow allow these to be returned, but
|
# XXX We should somehow allow these to be returned, but
|
||||||
# until someone complains, we'll be fine :) We
|
# until someone complains, we'll be fine :) We
|
||||||
@ -975,7 +983,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
action=self.action,
|
action=self.action,
|
||||||
notice=self.notice,
|
notice=self.notice,
|
||||||
private=self.private,
|
private=self.private,
|
||||||
prefixNick=self.prefixNick)
|
prefixNick=self.prefixNick,
|
||||||
|
stripCtcp=stripCtcp)
|
||||||
sendMsg(m)
|
sendMsg(m)
|
||||||
return m
|
return m
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user