mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 14:59:34 +01:00
Fixed the wacky addressed problems.
This commit is contained in:
parent
a764359d3d
commit
b4f977e2dd
@ -65,21 +65,29 @@ import plugins
|
|||||||
import ircmsgs
|
import ircmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
|
|
||||||
def addressed(nick, msg):
|
def addressed(nick, msg, prefixChars=None, whenAddressedByNick=None):
|
||||||
"""If msg is addressed to 'name', returns the portion after the address.
|
"""If msg is addressed to 'name', returns the portion after the address.
|
||||||
Otherwise returns the empty string.
|
Otherwise returns the empty string.
|
||||||
"""
|
"""
|
||||||
|
assert msg.command == 'PRIVMSG'
|
||||||
|
if prefixChars is None:
|
||||||
|
prefixChars = conf.supybot.prefixChars()
|
||||||
|
if whenAddressedByNick is None:
|
||||||
|
whenAddressedByNick = conf.supybot.reply.whenAddressedByNick()
|
||||||
nick = ircutils.toLower(nick)
|
nick = ircutils.toLower(nick)
|
||||||
if ircutils.nickEqual(msg.args[0], nick):
|
(target, payload) = msg.args
|
||||||
if msg.args[1][0] in conf.supybot.prefixChars():
|
# Ok, let's see if it's a private message.
|
||||||
return msg.args[1][1:].strip()
|
if ircutils.nickEqual(target, nick):
|
||||||
|
if payload[0] in prefixChars:
|
||||||
|
return payload[1:].strip()
|
||||||
else:
|
else:
|
||||||
return msg.args[1].strip()
|
return payload.strip()
|
||||||
elif conf.supybot.reply.whenAddressedByNick() and \
|
# Ok, not private. Does it start with our nick?
|
||||||
ircutils.toLower(msg.args[1]).startswith(nick):
|
elif whenAddressedByNick and \
|
||||||
|
ircutils.toLower(payload).startswith(nick):
|
||||||
try:
|
try:
|
||||||
(maybeNick, rest) = msg.args[1].split(None, 1)
|
(maybeNick, rest) = payload.split(None, 1)
|
||||||
while not ircutils.isNick(maybeNick):
|
while not ircutils.isNick(maybeNick, strictRfc=True):
|
||||||
if maybeNick[-1].isalnum():
|
if maybeNick[-1].isalnum():
|
||||||
return ''
|
return ''
|
||||||
maybeNick = maybeNick[:-1]
|
maybeNick = maybeNick[:-1]
|
||||||
@ -89,10 +97,10 @@ def addressed(nick, msg):
|
|||||||
return ''
|
return ''
|
||||||
except ValueError: # split didn't work.
|
except ValueError: # split didn't work.
|
||||||
return ''
|
return ''
|
||||||
elif msg.args[1] and msg.args[1][0] in conf.supybot.prefixChars():
|
elif payload and payload[0] in prefixChars:
|
||||||
return msg.args[1][1:].strip()
|
return payload[1:].strip()
|
||||||
elif conf.supybot.reply.whenNotAddressed():
|
elif conf.supybot.reply.whenNotAddressed():
|
||||||
return msg.args[1]
|
return payload
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@ -824,7 +832,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
return group.get(id)()
|
return group.get(id)()
|
||||||
|
|
||||||
def setUserValue(self, prefixOrName, name, value,
|
def setUserValue(self, prefixOrName, name, value,
|
||||||
ignoreNoUser=False, setValue=False):
|
ignoreNoUser=True, setValue=False):
|
||||||
try:
|
try:
|
||||||
id = str(ircdb.users.getUserId(prefixOrName))
|
id = str(ircdb.users.getUserId(prefixOrName))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
28
src/conf.py
28
src/conf.py
@ -494,28 +494,20 @@ registerGlobalValue(supybot.databases.channels, 'filename',
|
|||||||
###
|
###
|
||||||
# Protocol information.
|
# Protocol information.
|
||||||
###
|
###
|
||||||
class StrictRfc(registry.Boolean):
|
originalIsNick = ircutils.isNick
|
||||||
def __init__(self, *args, **kwargs):
|
def isNick(s, strictRfc=None):
|
||||||
self.originalIsNick = ircutils.isNick
|
if strictRfc is None:
|
||||||
registry.Boolean.__init__(self, *args, **kwargs)
|
strictRfc = supybot.protocols.irc.strictRfc()
|
||||||
|
return originalIsNick(s, strictRfc=strictRfc)
|
||||||
def setValue(self, v):
|
ircutils.isNick = isNick
|
||||||
registry.Boolean.setValue(self, v)
|
|
||||||
# Now let's replace ircutils.isNick.
|
|
||||||
if self.value:
|
|
||||||
ircutils.isNick = self.originalIsNick
|
|
||||||
else:
|
|
||||||
def unstrictIsNick(s):
|
|
||||||
return not ircutils.isChannel(s)
|
|
||||||
ircutils.isNick = unstrictIsNick
|
|
||||||
|
|
||||||
registerGroup(supybot, 'protocols')
|
registerGroup(supybot, 'protocols')
|
||||||
registerGroup(supybot.protocols, 'irc')
|
registerGroup(supybot.protocols, 'irc')
|
||||||
registerGlobalValue(supybot.protocols.irc, 'strictRfc',
|
registerGlobalValue(supybot.protocols.irc, 'strictRfc',
|
||||||
StrictRfc(False, """Determines whether the bot will strictly follow the
|
registry.Boolean(False, """Determines whether the bot will strictly follow
|
||||||
RFC; currently this only affects what strings are considered to be nicks.
|
the RFC; currently this only affects what strings are considered to be
|
||||||
If you're using a server or a network that requires you to message a nick
|
nicks. If you're using a server or a network that requires you to message
|
||||||
such as services@this.network.server then you you should set this to
|
a nick such as services@this.network.server then you you should set this to
|
||||||
False."""))
|
False."""))
|
||||||
|
|
||||||
registerGlobalValue(supybot.protocols.irc, 'maxHistoryLength',
|
registerGlobalValue(supybot.protocols.irc, 'maxHistoryLength',
|
||||||
|
@ -110,9 +110,12 @@ _nickchars = r'_[]\`^{}|-'
|
|||||||
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
|
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
|
||||||
% (re.escape(_nickchars), re.escape(_nickchars)))
|
% (re.escape(_nickchars), re.escape(_nickchars)))
|
||||||
|
|
||||||
def isNick(s):
|
def isNick(s, strictRfc=True):
|
||||||
"""Returns True if s is a valid IRC nick."""
|
"""Returns True if s is a valid IRC nick."""
|
||||||
return bool(nickRe.match(s))
|
if strictRfc:
|
||||||
|
return bool(nickRe.match(s))
|
||||||
|
else:
|
||||||
|
return not isChannel(s)
|
||||||
|
|
||||||
def isChannel(s):
|
def isChannel(s):
|
||||||
"""Returns True if s is a valid IRC channel name."""
|
"""Returns True if s is a valid IRC channel name."""
|
||||||
|
Loading…
Reference in New Issue
Block a user