Closed bug 715763, 'Several JOIN commands don't allow specification of a key'

This commit is contained in:
Jeremy Fincher 2003-04-10 07:56:41 +00:00
parent 227f6e1e53
commit 67cbd8327d
3 changed files with 57 additions and 9 deletions

View File

@ -47,10 +47,21 @@ class AdminCommands(privmsgs.CapabilityCheckingPrivmsg):
"""<channel> [<channel> ...] """<channel> [<channel> ...]
Tell the bot to join the whitespace-separated list of channels Tell the bot to join the whitespace-separated list of channels
you give it. you give it. If a channel requires a key, attach it behind the
channel name via a comma. I.e., if you need to join both #a and #b,
and #a requires a key of 'aRocks', then you'd call 'join #a,aRocks #b'
""" """
irc.queueMsg(ircmsgs.joins(args)) keys = []
for channel in args: channels = []
for s in args:
if ',' in s:
(channel, key) = s.split(',', 1)
channels.insert(0, channel)
keys.insert(0, key)
else:
channels.append(channel)
irc.queueMsg(ircmsgs.joins(channels, keys))
for channel in channels:
irc.queueMsg(ircmsgs.who(channel)) irc.queueMsg(ircmsgs.who(channel))
def nick(self, irc, msg, args): def nick(self, irc, msg, args):

View File

@ -43,7 +43,8 @@ import ircutils
class IrcMsg(object): class IrcMsg(object):
"""Class to represent an IRC message. """Class to represent an IRC message.
""" """
__slots__ = ('_args', '_command', '_host', '_nick', '_prefix', '_user') __slots__ = ('_args', '_command', '_host', '_nick',
'_prefix', '_user', '_hash')
def __init__(self, s='', command='', args=None, prefix='', msg=None): def __init__(self, s='', command='', args=None, prefix='', msg=None):
if not s and not command and not msg: if not s and not command and not msg:
raise ValueError, 'IRC messages require a command.' raise ValueError, 'IRC messages require a command.'
@ -128,7 +129,13 @@ class IrcMsg(object):
return not (self == other) return not (self == other)
def __hash__(self): def __hash__(self):
return hash(self.command) & hash(self.prefix) & hash(self.args) try:
return self._hash
except AttributeError:
self._hash = hash(self.command) & \
hash(self.prefix) & \
hash(self.args)
return self._hash
def __repr__(self): def __repr__(self):
return '%s(prefix=%r, command=%r, args=%r)' % \ return '%s(prefix=%r, command=%r, args=%r)' % \
@ -339,15 +346,28 @@ def notice(recipient, msg, prefix=''):
assert (isChannel(recipient) or isNick(recipient)) and msg assert (isChannel(recipient) or isNick(recipient)) and msg
return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, msg)) return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, msg))
def join(channel, prefix=''): def join(channel, key=None, prefix=''):
"""Returns a JOIN to a channel""" """Returns a JOIN to a channel"""
assert isChannel(channel) assert isChannel(channel)
return IrcMsg(prefix=prefix, command='JOIN', args=(channel,)) if key is None:
return IrcMsg(prefix=prefix, command='JOIN', args=(channel,))
else:
return IrcMsg(prefix=prefix, command='JOIN', args=(channel, key))
def joins(channels, prefix=''): def joins(channels, keys=None, prefix=''):
"""Returns a JOIN to each of channels.""" """Returns a JOIN to each of channels."""
assert filter(isChannel, channels) == channels assert filter(isChannel, channels) == channels
return IrcMsg(prefix=prefix, command='JOIN', args=(','.join(channels),)) if keys is None:
keys = []
assert len(keys) <= len(channels)
if not keys:
return IrcMsg(prefix=prefix,
command='JOIN',
args=(','.join(channels),))
else:
return IrcMsg(prefix=prefix,
command='JOIN',
args=(','.join(channels), ','.join(keys)))
def part(channel, msg='', prefix=''): def part(channel, msg='', prefix=''):
"""Returns a PART from channel with the message msg.""" """Returns a PART from channel with the message msg."""

View File

@ -137,3 +137,20 @@ class FunctionsTestCase(unittest.TestCase):
self.assertEqual(ircutils.separateModes(withExceptions.args[1:]), self.assertEqual(ircutils.separateModes(withExceptions.args[1:]),
[('+b', bans[0]), ('+b', bans[1]), [('+b', bans[0]), ('+b', bans[1]),
('+e', exceptions[0])]) ('+e', exceptions[0])])
def testJoin(self):
channel = '#osu'
key = 'michiganSucks'
self.assertEqual(ircmsgs.join(channel).args, ('#osu',))
self.assertEqual(ircmsgs.join(channel, key).args,
('#osu', 'michiganSucks'))
def testJoins(self):
channels = ['#osu', '#umich']
keys = ['michiganSucks', 'osuSucks']
self.assertEqual(ircmsgs.joins(channels).args, ('#osu,#umich',))
self.assertEqual(ircmsgs.joins(channels, keys).args,
('#osu,#umich', 'michiganSucks,osuSucks'))
keys.pop()
self.assertEqual(ircmsgs.joins(channels, keys).args,
('#osu,#umich', 'michiganSucks'))