Started using source-nested plugins.

This commit is contained in:
Jeremy Fincher 2005-02-24 12:49:25 +00:00
parent 574e9509b7
commit 65fbb08c7f
2 changed files with 257 additions and 244 deletions

View File

@ -63,8 +63,7 @@ class Channel(callbacks.Plugin):
itself. itself.
""" """
self._sendMsg(irc, ircmsgs.mode(channel, modes)) self._sendMsg(irc, ircmsgs.mode(channel, modes))
mode = wrap(mode, mode = wrap(mode, ['op', ('haveOp', 'change the mode'), many('something')])
['op', ('haveOp', 'change the mode'), many('something')])
def limit(self, irc, msg, args, channel, limit): def limit(self, irc, msg, args, channel, limit):
"""[<channel>] [<limit>] """[<channel>] [<limit>]
@ -425,25 +424,26 @@ class Channel(callbacks.Plugin):
if replyirc is not None: if replyirc is not None:
replyIrc.error(format('There is no %s on this server.', nick)) replyIrc.error(format('There is no %s on this server.', nick))
def lobotomize(self, irc, msg, args, channel): class lobotomy(callbacks.Commands):
def add(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
If you have the #channel,op capability, this will "lobotomize" the If you have the #channel,op capability, this will "lobotomize" the
bot, making it silent and unanswering to all requests made in the bot, making it silent and unanswering to all requests made in the
channel. <channel> is only necessary if the message isn't sent in the channel. <channel> is only necessary if the message isn't sent in
channel itself. the channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.lobotomized = True c.lobotomized = True
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
lobotomize = wrap(lobotomize, ['op']) add = wrap(add, ['op'])
def unlobotomize(self, irc, msg, args, channel): def remove(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
If you have the #channel,op capability, this will unlobotomize the bot, If you have the #channel,op capability, this will unlobotomize the
making it respond to requests made in the channel again. bot, making it respond to requests made in the channel again.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the channel
itself. itself.
""" """
@ -451,40 +451,65 @@ class Channel(callbacks.Plugin):
c.lobotomized = False c.lobotomized = False
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unlobotomize = wrap(unlobotomize, ['op']) remove = wrap(remove, ['op'])
def permban(self, irc, msg, args, channel, banmask, expires): def list(self, irc, msg, args):
"""takes no arguments
Returns the channels in which this bot is lobotomized.
"""
L = []
for (channel, c) in ircdb.channels.iteritems():
if c.lobotomized:
chancap = ircdb.makeChannelCapability(channel, 'op')
if ircdb.checkCapability(msg.prefix, 'admin') or \
ircdb.checkCapability(msg.prefix, chancap) or \
(channel in irc.state.channels and \
msg.nick in irc.state.channels[channel].users):
L.append(channel)
if L:
L.sort()
s = format('I\'m currently lobotomized in %L.', L)
irc.reply(s)
else:
irc.reply('I\'m not currently lobotomized in any channels '
'that you\'re in.')
list = wrap(list)
class ban(callbacks.Commands):
def add(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
If you have the #channel,op capability, this will effect a permanent If you have the #channel,op capability, this will effect a
(persistent) ban from interacting with the bot on the given <hostmask> persistent ban from interacting with the bot on the given
(or the current hostmask associated with <nick>. Other plugins may <hostmask> (or the current hostmask associated with <nick>. Other
enforce this ban by actually banning users with matching hostmasks when plugins may enforce this ban by actually banning users with
they join. <expires> is an optional argument specifying when (in matching hostmasks when they join. <expires> is an optional
"seconds from now") the ban should expire; if none is given, the ban argument specifying when (in "seconds from now") the ban should
will never automatically expire. <channel> is only necessary if the expire; if none is given, the ban will never automatically expire.
message isn't sent in the channel itself. <channel> is only necessary if the message isn't sent in the
channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.addBan(banmask, expires) c.addBan(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
permban = wrap(permban, ['op', 'hostmask', additional('expiry', 0)]) add = wrap(add, ['op', 'hostmask', additional('expiry', 0)])
def unpermban(self, irc, msg, args, channel, banmask): def remove(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
If you have the #channel,op capability, this will remove the permanent If you have the #channel,op capability, this will remove the
ban on <hostmask>. <channel> is only necessary if the message isn't persistent ban on <hostmask>. <channel> is only necessary if the
sent in the channel itself. message isn't sent in the channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.removeBan(banmask) c.removeBan(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unpermban = wrap(unpermban, ['op', 'hostmask']) remove = wrap(remove, ['op', 'hostmask'])
def permbans(self, irc, msg, args, channel): def list(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
If you have the #channel,op capability, this will show you the If you have the #channel,op capability, this will show you the
@ -495,44 +520,47 @@ class Channel(callbacks.Plugin):
if c.bans: if c.bans:
irc.reply(format('%L', map(utils.str.dqrepr, c.bans))) irc.reply(format('%L', map(utils.str.dqrepr, c.bans)))
else: else:
irc.reply('There are currently no permanent bans on %s' % channel) irc.reply(format('There are no persistent bans on %s.',
permbans = wrap(permbans, ['op']) channel))
list = wrap(list, ['op'])
def ignore(self, irc, msg, args, channel, banmask, expires): class ignore(callbacks.Commands):
def add(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
If you have the #channel,op capability, this will set a permanent If you have the #channel,op capability, this will set a persistent
(persistent) ignore on <hostmask> or the hostmask currently associated ignore on <hostmask> or the hostmask currently
with <nick>. <expires> is an optional argument specifying when (in associated with <nick>. <expires> is an optional argument
"seconds from now") the ignore will expire; if it isn't given, the specifying when (in "seconds from now") the ignore will expire; if
ignore will never automatically expire. <channel> is only necessary it isn't given, the ignore will never automatically expire.
if the message isn't sent in the channel itself. <channel> is only necessary if the message isn't sent in the
channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.addIgnore(banmask, expires) c.addIgnore(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
ignore = wrap(ignore, ['op', 'hostmask', additional('expiry', 0)]) add = wrap(add, ['op', 'hostmask', additional('expiry', 0)])
def unignore(self, irc, msg, args, channel, banmask): def remove(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
If you have the #channel,op capability, this will remove the permanent If you have the #channel,op capability, this will remove the
ignore on <hostmask> in the channel. <channel> is only necessary if the persistent ignore on <hostmask> in the channel. <channel> is only
message isn't sent in the channel itself. necessary if the message isn't sent in the channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.removeIgnore(banmask) c.removeIgnore(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unignore = wrap(unignore, ['op', 'hostmask']) remove = wrap(remove, ['op', 'hostmask'])
def ignores(self, irc, msg, args, channel): def list(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Lists the hostmasks that the bot is ignoring on the given channel. Lists the hostmasks that the bot is ignoring on the given channel.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the
itself. channel itself.
""" """
# XXX Add the expirations. # XXX Add the expirations.
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
@ -543,30 +571,31 @@ class Channel(callbacks.Plugin):
else: else:
L = sorted(c.ignores) L = sorted(c.ignores)
irc.reply(utils.str.commaAndify(map(repr, L))) irc.reply(utils.str.commaAndify(map(repr, L)))
ignores = wrap(ignores, ['op']) list = wrap(list, ['op'])
def addcapability(self, irc, msg, args, channel, user, capabilities): class capability(callbacks.Commands):
def add(self, irc, msg, args, channel, user, capabilities):
"""[<channel>] <nick|username> <capability> [<capability> ...] """[<channel>] <nick|username> <capability> [<capability> ...]
If you have the #channel,op capability, this will give the user If you have the #channel,op capability, this will give the user
<name> (or the user to whom <nick> maps) <name> (or the user to whom <nick> maps)
the capability <capability> in the channel. <channel> is only necessary the capability <capability> in the channel. <channel> is only
if the message isn't sent in the channel itself. necessary if the message isn't sent in the channel itself.
""" """
for c in capabilities.split(): for c in capabilities.split():
c = ircdb.makeChannelCapability(channel, c) c = ircdb.makeChannelCapability(channel, c)
user.addCapability(c) user.addCapability(c)
ircdb.users.setUser(user) ircdb.users.setUser(user)
irc.replySuccess() irc.replySuccess()
addcapability = wrap(addcapability, ['op', 'otherUser', 'capability']) add = wrap(add, ['op', 'otherUser', 'capability'])
def removecapability(self, irc, msg, args, channel, user, capabilities): def remove(self, irc, msg, args, channel, user, capabilities):
"""[<channel>] <name|hostmask> <capability> [<capability> ...] """[<channel>] <name|hostmask> <capability> [<capability> ...]
If you have the #channel,op capability, this will take from the user If you have the #channel,op capability, this will take from the
currently identified as <name> (or the user to whom <hostmask> maps) user currently identified as <name> (or the user to whom <hostmask>
the capability <capability> in the channel. <channel> is only necessary maps) the capability <capability> in the channel. <channel> is only
if the message isn't sent in the channel itself. necessary if the message isn't sent in the channel itself.
""" """
fail = [] fail = []
for c in capabilities.split(): for c in capabilities.split():
@ -583,17 +612,17 @@ class Channel(callbacks.Plugin):
irc.error(format('That user didn\'t have the %L %s.', fail, s), irc.error(format('That user didn\'t have the %L %s.', fail, s),
Raise=True) Raise=True)
irc.replySuccess() irc.replySuccess()
removecapability = wrap(removecapability,['op', 'otherUser', 'capability']) remove = wrap(remove, ['op', 'otherUser', 'capability'])
# XXX This needs to be fix0red to be like Owner.defaultcapability. Or # XXX This needs to be fix0red to be like Owner.defaultcapability. Or
# something else. This is a horrible interface. # something else. This is a horrible interface.
def setdefaultcapability(self, irc, msg, args, channel, v): def setdefault(self, irc, msg, args, channel, v):
"""[<channel>] {True|False} """[<channel>] {True|False}
If you have the #channel,op capability, this will set the default If you have the #channel,op capability, this will set the default
response to non-power-related (that is, not {op, halfop, voice} response to non-power-related (that is, not {op, halfop, voice}
capabilities to be the value you give. <channel> is only necessary if capabilities to be the value you give. <channel> is only necessary
the message isn't sent in the channel itself. if the message isn't sent in the channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
if v: if v:
@ -602,9 +631,9 @@ class Channel(callbacks.Plugin):
c.setDefaultCapability(False) c.setDefaultCapability(False)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
setdefaultcapability = wrap(setdefaultcapability, ['op', 'boolean']) setdefault = wrap(setdefault, ['op', 'boolean'])
def setcapability(self, irc, msg, args, channel, capabilities): def set(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
If you have the #channel,op capability, this will add the channel If you have the #channel,op capability, this will add the channel
@ -616,9 +645,9 @@ class Channel(callbacks.Plugin):
chan.addCapability(c) chan.addCapability(c)
ircdb.channels.setChannel(channel, chan) ircdb.channels.setChannel(channel, chan)
irc.replySuccess() irc.replySuccess()
setcapability = wrap(setcapability, ['op', many('capability')]) set = wrap(set, ['op', many('capability')])
def unsetcapability(self, irc, msg, args, channel, capabilities): def unset(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
If you have the #channel,op capability, this will unset the channel If you have the #channel,op capability, this will unset the channel
@ -641,18 +670,18 @@ class Channel(callbacks.Plugin):
irc.error(format('I do not know about the %L %s.', fail, s), irc.error(format('I do not know about the %L %s.', fail, s),
Raise=True) Raise=True)
irc.replySuccess() irc.replySuccess()
unsetcapability = wrap(unsetcapability, ['op', many('capability')]) unset = wrap(unset, ['op', many('capability')])
def capabilities(self, irc, msg, args, channel): def list(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Returns the capabilities present on the <channel>. <channel> is only Returns the capabilities present on the <channel>. <channel> is
necessary if the message isn't sent in the channel itself. only necessary if the message isn't sent in the channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
L = sorted(c.capabilities) L = sorted(c.capabilities)
irc.reply(' '.join(L)) irc.reply(' '.join(L))
capabilities = wrap(capabilities, ['channel']) list = wrap(list, ['channel'])
def disable(self, irc, msg, args, channel, plugin, command): def disable(self, irc, msg, args, channel, plugin, command):
"""[<channel>] [<plugin>] [<command>] """[<channel>] [<plugin>] [<command>]
@ -737,22 +766,6 @@ class Channel(callbacks.Plugin):
optional(('plugin', False)), optional(('plugin', False)),
additional('commandName')]) additional('commandName')])
def lobotomies(self, irc, msg, args):
"""takes no arguments
Returns the channels in which this bot is lobotomized.
"""
L = []
for (channel, c) in ircdb.channels.iteritems():
if c.lobotomized:
L.append(channel)
if L:
L.sort()
s = format('I\'m currently lobotomized in %L.', L)
irc.reply(s)
else:
irc.reply('I\'m not currently lobotomized in any channels.')
def nicks(self, irc, msg, args, channel): def nicks(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]

View File

@ -42,7 +42,7 @@ class ChannelTestCase(ChannelPluginTestCase):
self.irc.state.channels[self.channel].addUser('bar') self.irc.state.channels[self.channel].addUser('bar')
def testLobotomies(self): def testLobotomies(self):
self.assertRegexp('lobotomies', 'not.*any') self.assertRegexp('lobotomy list', 'not.*any')
## def testCapabilities(self): ## def testCapabilities(self):
## self.prefix = 'foo!bar@baz' ## self.prefix = 'foo!bar@baz'
@ -59,29 +59,29 @@ class ChannelTestCase(ChannelPluginTestCase):
## self.assertResponse('user capabilities foo', '[]') ## self.assertResponse('user capabilities foo', '[]')
def testCapabilities(self): def testCapabilities(self):
self.assertNotError('channel capabilities') self.assertNotError('channel capability list')
self.assertNotError('channel setcapability -foo') self.assertNotError('channel capability set -foo')
self.assertNotError('channel unsetcapability -foo') self.assertNotError('channel capability unset -foo')
self.assertError('channel unsetcapability -foo') self.assertError('channel capability unset -foo')
self.assertNotError('channel setcapability -foo bar baz') self.assertNotError('channel capability set -foo bar baz')
self.assertRegexp('channel capabilities', 'baz') self.assertRegexp('channel capability list', 'baz')
self.assertNotError('channel unsetcapability -foo baz') self.assertNotError('channel capability unset -foo baz')
self.assertError('channel unsetcapability baz') self.assertError('channel capability unset baz')
def testEnableDisable(self): def testEnableDisable(self):
self.assertNotRegexp('channel capabilities', '-Channel') self.assertNotRegexp('channel capability list', '-Channel')
self.assertError('channel enable channel') self.assertError('channel enable channel')
self.assertNotError('channel disable channel') self.assertNotError('channel disable channel')
self.assertRegexp('channel capabilities', '-Channel') self.assertRegexp('channel capability list', '-Channel')
self.assertNotError('channel enable channel') self.assertNotError('channel enable channel')
self.assertNotRegexp('channel capabilities', '-Channel') self.assertNotRegexp('channel capability list', '-Channel')
self.assertNotError('channel disable channel nicks') self.assertNotError('channel disable channel nicks')
self.assertRegexp('channel capabilities', '-Channel.nicks') self.assertRegexp('channel capability list', '-Channel.nicks')
self.assertNotError('channel enable channel nicks') self.assertNotError('channel enable channel nicks')
self.assertNotRegexp('channel capabilities', '-Channel.nicks') self.assertNotRegexp('channel capability list', '-Channel.nicks')
self.assertNotRegexp('channel capabilities', 'nicks') self.assertNotRegexp('channel capability list', 'nicks')
self.assertNotError('channel disable nicks') self.assertNotError('channel disable nicks')
self.assertRegexp('channel capabilities', 'nicks') self.assertRegexp('channel capability list', 'nicks')
self.assertNotError('channel enable nicks') self.assertNotError('channel enable nicks')
self.assertError('channel disable invalidPlugin') self.assertError('channel disable invalidPlugin')
self.assertError('channel disable channel invalidCommand') self.assertError('channel disable channel invalidCommand')
@ -167,24 +167,24 @@ class ChannelTestCase(ChannelPluginTestCase):
## self.assertNotRegexp('kban foobar time', 'ValueError') ## self.assertNotRegexp('kban foobar time', 'ValueError')
## self.assertError('kban %s' % self.irc.nick) ## self.assertError('kban %s' % self.irc.nick)
def testPermban(self): def testBan(self):
self.assertNotError('permban foo!bar@baz') self.assertNotError('ban add foo!bar@baz')
self.assertNotError('unpermban foo!bar@baz') self.assertNotError('ban remove foo!bar@baz')
orig = conf.supybot.protocols.irc.strictRfc() orig = conf.supybot.protocols.irc.strictRfc()
try: try:
conf.supybot.protocols.irc.strictRfc.setValue(True) conf.supybot.protocols.irc.strictRfc.setValue(True)
# something wonky is going on here. irc.error (src/Channel.py|449) # something wonky is going on here. irc.error (src/Channel.py|449)
# is being called but the assert is failing # is being called but the assert is failing
self.assertError('permban not!a.hostmask') self.assertError('ban add not!a.hostmask')
self.assertNotRegexp('permban not!a.hostmask', 'KeyError') self.assertNotRegexp('ban add not!a.hostmask', 'KeyError')
finally: finally:
conf.supybot.protocols.irc.strictRfc.setValue(orig) conf.supybot.protocols.irc.strictRfc.setValue(orig)
def testIgnore(self): def testIgnore(self):
self.assertNotError('Channel ignore foo!bar@baz') self.assertNotError('channel ignore add foo!bar@baz')
self.assertResponse('Channel ignores', "'foo!bar@baz'") self.assertResponse('channel ignore list', "'foo!bar@baz'")
self.assertNotError('Channel unignore foo!bar@baz') self.assertNotError('channel ignore remove foo!bar@baz')
self.assertError('permban not!a.hostmask') self.assertError('ban add not!a.hostmask')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: