mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 04:32:36 +01:00
Convert to wrap and simplify Admin.join (no longer accept multiple channels)
This commit is contained in:
parent
d57788b5d2
commit
12fa1096db
80
src/Admin.py
80
src/Admin.py
@ -48,8 +48,8 @@ import supybot.log as log
|
|||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
|
from supybot.commands import *
|
||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
from supybot.commands import additional, wrap
|
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
import supybot.privmsgs as privmsgs
|
||||||
import supybot.schedule as schedule
|
import supybot.schedule as schedule
|
||||||
@ -136,38 +136,23 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
irc.queueMsg(ircmsgs.join(channel))
|
irc.queueMsg(ircmsgs.join(channel))
|
||||||
conf.supybot.networks.get(irc.network).channels().add(channel)
|
conf.supybot.networks.get(irc.network).channels().add(channel)
|
||||||
|
|
||||||
def join(self, irc, msg, args):
|
def join(self, irc, msg, args, channel, key):
|
||||||
"""<channel>[,<key>] [<channel>[,<key>] ...]
|
"""<channel> [<key>]
|
||||||
|
|
||||||
Tell the bot to join the whitespace-separated list of channels
|
Tell the bot to join the given channel. If <key> is given, it is used
|
||||||
you give it. If a channel requires a key, attach it behind the
|
when attempting to join the channel.
|
||||||
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'
|
|
||||||
"""
|
"""
|
||||||
if not args:
|
if not irc.isChannel(channel):
|
||||||
raise callbacks.ArgumentError
|
irc.errorInvalid('channel', channel, Raise=True)
|
||||||
keys = []
|
conf.supybot.networks.get(irc.network).channels().add(channel)
|
||||||
channels = []
|
|
||||||
for channel in args:
|
|
||||||
original = channel
|
|
||||||
if ',' in channel:
|
|
||||||
(channel, key) = channel.split(',', 1)
|
|
||||||
channels.insert(0, channel)
|
|
||||||
keys.insert(0, key)
|
|
||||||
else:
|
|
||||||
channels.append(channel)
|
|
||||||
if not irc.isChannel(channel):
|
|
||||||
irc.errorInvalid('channel', channel)
|
|
||||||
return
|
|
||||||
conf.supybot.networks.get(irc.network).channels().add(original)
|
|
||||||
maxchannels = irc.state.supported.get('maxchannels', sys.maxint)
|
maxchannels = irc.state.supported.get('maxchannels', sys.maxint)
|
||||||
if len(irc.state.channels) + len(channels) > maxchannels:
|
if len(irc.state.channels) + 1 > maxchannels:
|
||||||
irc.error('I\'m already too close to maximum number of '
|
irc.error('I\'m already too close to maximum number of '
|
||||||
'channels for this network.', Raise=True)
|
'channels for this network.', Raise=True)
|
||||||
irc.queueMsg(ircmsgs.joins(channels, keys))
|
irc.queueMsg(ircmsgs.join(channel, key))
|
||||||
irc.noReply()
|
irc.noReply()
|
||||||
for channel in channels:
|
self.joins[channel] = (irc, msg)
|
||||||
self.joins[channel] = (irc, msg)
|
join = wrap(join, ['validChannel', additional('something')])
|
||||||
|
|
||||||
def channels(self, irc, msg, args):
|
def channels(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
@ -240,42 +225,25 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
irc.reply(irc.nick)
|
irc.reply(irc.nick)
|
||||||
nick = wrap(nick, [additional('nick')])
|
nick = wrap(nick, [additional('nick')])
|
||||||
|
|
||||||
def part(self, irc, msg, args):
|
def part(self, irc, msg, args, channels, reason):
|
||||||
"""<channel> [<channel> ...] [<reason>]
|
"""[<channel> ...] [<reason>]
|
||||||
|
|
||||||
Tells the bot to part the list of channels you give it. If <reason>
|
Tells the bot to part the list of channels you give it. <channel> is
|
||||||
is specified, use it as the part message.
|
only necessary if you want the bot to part a channel other than the
|
||||||
|
current channel. If <reason> is specified, use it as the part
|
||||||
|
message.
|
||||||
"""
|
"""
|
||||||
if not args:
|
|
||||||
args = [msg.args[0]]
|
|
||||||
channels = []
|
|
||||||
reason = ''
|
|
||||||
for (i, arg) in enumerate(args):
|
|
||||||
if irc.isChannel(arg):
|
|
||||||
channels.append(args[i])
|
|
||||||
args[i] = None
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
args = filter(None, args)
|
|
||||||
if not channels:
|
if not channels:
|
||||||
channels.append(msg.args[0])
|
channels.append(msg.args[0])
|
||||||
if args:
|
|
||||||
reason = ' '.join(args)
|
|
||||||
for chan in channels:
|
|
||||||
if chan not in irc.state.channels:
|
|
||||||
irc.error('I\'m not currently in %s.' % chan)
|
|
||||||
return
|
|
||||||
for chan in channels:
|
for chan in channels:
|
||||||
try:
|
try:
|
||||||
network = conf.supybot.networks.get(irc.network)
|
network = conf.supybot.networks.get(irc.network)
|
||||||
network.channels.removeChannel(chan)
|
network.channels.removeChannel(chan)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass # It might be in the network thingy.
|
pass # It might be in the network thingy.
|
||||||
try:
|
for chan in channels:
|
||||||
networkGroup = conf.supybot.networks.get(irc.network)
|
if chan not in irc.state.channels:
|
||||||
networkGroup.channels.removeChannel(chan)
|
irc.error('I\'m not in %s.' % chan, Raise=True)
|
||||||
except KeyError:
|
|
||||||
pass # It might be in the non-network thingy.
|
|
||||||
irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick))
|
irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick))
|
||||||
inAtLeastOneChannel = False
|
inAtLeastOneChannel = False
|
||||||
for chan in channels:
|
for chan in channels:
|
||||||
@ -285,6 +253,8 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
else:
|
else:
|
||||||
irc.noReply()
|
irc.noReply()
|
||||||
|
part = wrap(part, [any('validChannel', continueOnError=True),
|
||||||
|
additional('text','')])
|
||||||
|
|
||||||
def addcapability(self, irc, msg, args, user, capability):
|
def addcapability(self, irc, msg, args, user, capability):
|
||||||
"""<name|hostmask> <capability>
|
"""<name|hostmask> <capability>
|
||||||
@ -348,11 +318,9 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
3600. If no <expires> is given, the ignore will never automatically
|
3600. If no <expires> is given, the ignore will never automatically
|
||||||
expire.
|
expire.
|
||||||
"""
|
"""
|
||||||
if expires:
|
|
||||||
expires += time.time()
|
|
||||||
ircdb.ignores.add(hostmask, expires)
|
ircdb.ignores.add(hostmask, expires)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
ignore = wrap(ignore, ['hostmask', additional('int', 0)])
|
ignore = wrap(ignore, ['hostmask', additional('expiry', 0)])
|
||||||
|
|
||||||
def unignore(self, irc, msg, args, hostmask):
|
def unignore(self, irc, msg, args, hostmask):
|
||||||
"""<hostmask|nick>
|
"""<hostmask|nick>
|
||||||
|
@ -76,21 +76,10 @@ class AdminTestCase(PluginTestCase):
|
|||||||
m = self.getMsg('join #foo')
|
m = self.getMsg('join #foo')
|
||||||
self.assertEqual(m.command, 'JOIN')
|
self.assertEqual(m.command, 'JOIN')
|
||||||
self.assertEqual(m.args[0], '#foo')
|
self.assertEqual(m.args[0], '#foo')
|
||||||
m = self.getMsg('join #foo #bar')
|
m = self.getMsg('join #foo key')
|
||||||
self.assertEqual(m.command, 'JOIN')
|
|
||||||
self.assertEqual(m.args[0], '#foo,#bar')
|
|
||||||
m = self.getMsg('join #foo,key')
|
|
||||||
self.assertEqual(m.command, 'JOIN')
|
self.assertEqual(m.command, 'JOIN')
|
||||||
self.assertEqual(m.args[0], '#foo')
|
self.assertEqual(m.args[0], '#foo')
|
||||||
self.assertEqual(m.args[1], 'key')
|
self.assertEqual(m.args[1], 'key')
|
||||||
m = self.getMsg('join #bar #foo,key')
|
|
||||||
self.assertEqual(m.command, 'JOIN')
|
|
||||||
self.assertEqual(m.args[0], '#foo,#bar')
|
|
||||||
self.assertEqual(m.args[1], 'key')
|
|
||||||
m = self.getMsg('join #bar,key1 #foo,key2')
|
|
||||||
self.assertEqual(m.command, 'JOIN')
|
|
||||||
self.assertEqual(m.args[0], '#foo,#bar')
|
|
||||||
self.assertEqual(m.args[1], 'key2,key1')
|
|
||||||
|
|
||||||
def testPart(self):
|
def testPart(self):
|
||||||
def getAfterJoinMessages():
|
def getAfterJoinMessages():
|
||||||
@ -99,7 +88,7 @@ class AdminTestCase(PluginTestCase):
|
|||||||
m = self.irc.takeMsg()
|
m = self.irc.takeMsg()
|
||||||
self.assertEqual(m.command, 'WHO')
|
self.assertEqual(m.command, 'WHO')
|
||||||
self.assertError('part #foo')
|
self.assertError('part #foo')
|
||||||
self.assertRegexp('part #foo', 'currently')
|
self.assertRegexp('part #foo', 'not in')
|
||||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix=self.prefix))
|
self.irc.feedMsg(ircmsgs.join('#foo', prefix=self.prefix))
|
||||||
getAfterJoinMessages()
|
getAfterJoinMessages()
|
||||||
self.assertError('part #foo #bar')
|
self.assertError('part #foo #bar')
|
||||||
@ -113,6 +102,14 @@ class AdminTestCase(PluginTestCase):
|
|||||||
m = self.getMsg('part #foo #bar')
|
m = self.getMsg('part #foo #bar')
|
||||||
self.assertEqual(m.command, 'PART')
|
self.assertEqual(m.command, 'PART')
|
||||||
self.assertEqual(m.args[0], '#foo,#bar')
|
self.assertEqual(m.args[0], '#foo,#bar')
|
||||||
|
self.irc.feedMsg(ircmsgs.join('#foo', prefix=self.prefix))
|
||||||
|
getAfterJoinMessages()
|
||||||
|
self.irc.feedMsg(ircmsgs.join('#bar', prefix=self.prefix))
|
||||||
|
getAfterJoinMessages()
|
||||||
|
m = self.getMsg('part #foo #bar reason')
|
||||||
|
self.assertEqual(m.command, 'PART')
|
||||||
|
self.assertEqual(m.args[0], '#foo,#bar')
|
||||||
|
self.assertEqual(m.args[1], 'reason')
|
||||||
|
|
||||||
def testNick(self):
|
def testNick(self):
|
||||||
original = conf.supybot.nick()
|
original = conf.supybot.nick()
|
||||||
@ -127,6 +124,5 @@ class AdminTestCase(PluginTestCase):
|
|||||||
self.assertError('admin addcapability %s owner' % self.nick)
|
self.assertError('admin addcapability %s owner' % self.nick)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user