mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Closed bug 715763, 'Several JOIN commands don't allow specification of a key'
This commit is contained in:
parent
227f6e1e53
commit
67cbd8327d
@ -47,10 +47,21 @@ class AdminCommands(privmsgs.CapabilityCheckingPrivmsg):
|
||||
"""<channel> [<channel> ...]
|
||||
|
||||
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))
|
||||
for channel in args:
|
||||
keys = []
|
||||
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))
|
||||
|
||||
def nick(self, irc, msg, args):
|
||||
|
@ -43,7 +43,8 @@ import ircutils
|
||||
class IrcMsg(object):
|
||||
"""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):
|
||||
if not s and not command and not msg:
|
||||
raise ValueError, 'IRC messages require a command.'
|
||||
@ -128,7 +129,13 @@ class IrcMsg(object):
|
||||
return not (self == other)
|
||||
|
||||
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):
|
||||
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
|
||||
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"""
|
||||
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."""
|
||||
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=''):
|
||||
"""Returns a PART from channel with the message msg."""
|
||||
|
@ -137,3 +137,20 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.assertEqual(ircutils.separateModes(withExceptions.args[1:]),
|
||||
[('+b', bans[0]), ('+b', bans[1]),
|
||||
('+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'))
|
||||
|
Loading…
Reference in New Issue
Block a user