From a91c55a93a34007036db6e4ed2ac8b3278110470 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 29 Sep 2003 05:01:41 +0000 Subject: [PATCH] Updated to use checkChannelCapability. --- src/ChannelCommands.py | 268 ++++++++++++++--------------------- test/test_ChannelCommands.py | 14 ++ 2 files changed, 123 insertions(+), 159 deletions(-) diff --git a/src/ChannelCommands.py b/src/ChannelCommands.py index 7a095e83e..a79d09ee7 100755 --- a/src/ChannelCommands.py +++ b/src/ChannelCommands.py @@ -45,71 +45,55 @@ import privmsgs import callbacks class ChannelCommands(callbacks.Privmsg): - def op(self, irc, msg, args): + def op(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.op capability, this will give you ops. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - if irc.nick in irc.state.channels[channel].ops: - irc.queueMsg(ircmsgs.op(channel, msg.nick)) - else: - irc.error(msg, 'How can I op you? I\'m not opped!') + if irc.nick in irc.state.channels[channel].ops: + irc.queueMsg(ircmsgs.op(channel, msg.nick)) else: - irc.error(msg, conf.replyNoCapability % capability) + irc.error(msg, 'How can I op you? I\'m not opped!') + op = privmsgs.checkChannelCapability(op, 'op') - def halfop(self, irc, msg, args): + def halfop(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.halfop capability, this will give you halfops. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'halfop') - if ircdb.checkCapability(msg.prefix, capability): - if irc.nick in irc.state.channels[channel].ops: - irc.queueMsg(ircmsgs.halfop(channel, msg.nick)) - else: - irc.error(msg, 'How can I halfop you? I\'m not opped!') + if irc.nick in irc.state.channels[channel].ops: + irc.queueMsg(ircmsgs.halfop(channel, msg.nick)) else: - irc.error(msg, conf.replyNoCapability % capability) + irc.error(msg, 'How can I halfop you? I\'m not opped!') + halfop = privmsgs.checkChannelCapability(halfop, 'halfop') - def voice(self, irc, msg, args): + def voice(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.voice capability, this will give you voice. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'voice') - if ircdb.checkCapability(msg.prefix, capability): - if irc.nick in irc.state.channels[channel].ops: - irc.queueMsg(ircmsgs.voice(channel, msg.nick)) - else: - irc.error(msg, 'How can I voice you? I\'m not opped!') + if irc.nick in irc.state.channels[channel].ops: + irc.queueMsg(ircmsgs.voice(channel, msg.nick)) else: - irc.error(msg, conf.replyNoCapability % capability) - - def cycle(self, irc, msg, args): + irc.error(msg, 'How can I voice you? I\'m not opped!') + voice = privmsgs.checkChannelCapability(voice, 'voice') + + def cycle(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.op capability, this will cause the bot to "cycle", or PART and then JOIN the channel. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - irc.queueMsg(ircmsgs.part(channel)) - irc.queueMsg(ircmsgs.join(channel)) - else: - irc.error(msg, conf.replyNoCapability % capability) + irc.queueMsg(ircmsgs.part(channel)) + irc.queueMsg(ircmsgs.join(channel)) + cycle = privmsgs.checkChannelCapability(cycle, 'op') def kban(self, irc, msg, args): """[] [] @@ -140,7 +124,7 @@ class ChannelCommands(callbacks.Privmsg): else: irc.error(msg, conf.replyNoCapability % capability) - def lobotomize(self, irc, msg, args): + def lobotomize(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -148,15 +132,11 @@ class ChannelCommands(callbacks.Privmsg): this will "lobotomize" the bot, making it silent and unanswering to all requests made in the channel. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - ircdb.channels.getChannel(channel).lobotomized = True - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % capability) + ircdb.channels.getChannel(channel).lobotomized = True + irc.reply(msg, conf.replySuccess) + lobotomize = privmsgs.checkChannelCapability(lobotomize, 'op') - def unlobotomize(self, irc, msg, args): + def unlobotomize(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -164,15 +144,11 @@ class ChannelCommands(callbacks.Privmsg): this will unlobotomize the bot, making it respond to requests made in the channel again. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - ircdb.channels.getChannel(channel).lobotomized = False - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % capability) + ircdb.channels.getChannel(channel).lobotomized = False + irc.reply(msg, conf.replySuccess) + unlobotomize = privmsgs.checkChannelCapability(unlobotomize, 'op') - def permban(self, irc, msg, args): + def permban(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -180,40 +156,35 @@ class ChannelCommands(callbacks.Privmsg): this will effect a permanent (persistent) ban on the given (or the current hostmask associated with . """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') arg = privmsgs.getArgs(args) if ircutils.isNick(arg): banmask = ircutils.banmask(irc.state.nickToHostmask(arg)) - else: + elif ircutils.isUserHostmask(arg): banmask = arg - if ircdb.checkCapability(msg.prefix, capability): - c = ircdb.channels.getChannel(channel) - c.addBan(banmask) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) else: - irc.error(msg, conf.replyNoCapability % capability) + irc.error(msg, 'That\'s not a valid nick or hostmask.') + return + c = ircdb.channels.getChannel(channel) + c.addBan(banmask) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + permban = privmsgs.checkChannelCapability(permban, 'op') - def unpermban(self, irc, msg, args): + def unpermban(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.op capability, this will remove the permanent ban on . """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') banmask = privmsgs.getArgs(args) - if ircdb.checkCapability(msg.prefix, capability): - c = ircdb.channels.getChannel(channel) - c.removeBan(banmask) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % capability) + c = ircdb.channels.getChannel(channel) + c.removeBan(banmask) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + unpermban = privmsgs.checkChannelCapability(unpermban, 'op') - def chanignore(self, irc, msg, args): + def chanignore(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -221,40 +192,35 @@ class ChannelCommands(callbacks.Privmsg): this will set a permanent (persistent) ignore on or the hostmask currently associated with . """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') arg = privmsgs.getArgs(args) if ircutils.isNick(arg): banmask = ircutils.banmask(irc.state.nickToHostmask(arg)) - else: + elif ircutils.isUserHostmask(arg): banmask = arg - if ircdb.checkCapability(msg.prefix, capability): - c = ircdb.channels.getChannel(channel) - c.addIgnore(banmask) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) else: - irc.error(msg, conf.replyNoCapability % capability) + irc.error(msg, 'That\'s not a valid nick or hostmask.') + return + c = ircdb.channels.getChannel(channel) + c.addIgnore(banmask) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + chanignore = privmsgs.checkChannelCapability(chanignore, 'op') - def unchanignore(self, irc, msg, args): + def unchanignore(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.op capability, this will remove the permanent ignore on in the channel. """ - channel = privmsgs.getChannel(msg, args) - capability = ircdb.makeChannelCapability(channel, 'op') banmask = privmsgs.getArgs(args) - if ircdb.checkCapability(msg.prefix, capability): - c = ircdb.channels.getChannel(channel) - c.removeIgnore(banmask) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % capability) + c = ircdb.channels.getChannel(channel) + c.removeIgnore(banmask) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + unchanignore = privmsgs.checkChannelCapability(unchanignore, 'op') - def addchancapability(self, irc, msg, args): + def addchancapability(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -262,23 +228,19 @@ class ChannelCommands(callbacks.Privmsg): this will give the user currently identified as (or the user to whom maps) the capability in the channel. """ - channel = privmsgs.getChannel(msg, args) (name, capability) = privmsgs.getArgs(args, 2) - neededcapability = ircdb.makeChannelCapability(channel, 'op') capability = ircdb.makeChannelCapability(channel, capability) - if ircdb.checkCapability(msg.prefix, neededcapability): - try: - id = ircdb.users.getUserId(name) - user = ircdb.users.getUser(id) - user.addCapability(capability) - ircdb.users.setUser(id, user) - irc.reply(msg, conf.replySuccess) - except KeyError: - irc.error(msg, conf.replyNoUser) - else: - irc.error(msg, conf.replyNoCapability % neededcapability) + try: + id = ircdb.users.getUserId(name) + user = ircdb.users.getUser(id) + user.addCapability(capability) + ircdb.users.setUser(id, user) + irc.reply(msg, conf.replySuccess) + except KeyError: + irc.error(msg, conf.replyNoUser) + addchancapability = privmsgs.checkChannelCapability(addchancapability,'op') - def removechancapability(self, irc, msg, args): + def removechancapability(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -287,23 +249,20 @@ class ChannelCommands(callbacks.Privmsg): user to whom maps) the capability in the channel. """ - channel = privmsgs.getChannel(msg, args) (name, capability) = privmsgs.getArgs(args, 2) - neededcapability = ircdb.makeChannelCapability(channel, 'op') capability = ircdb.makeChannelCapability(channel, capability) - if ircdb.checkCapability(msg.prefix, neededcapability): - try: - id = ircdb.users.getUser(name) - user = ircdb.users.getUser(id) - user.removeCapability(capability) - ircdb.users.setUser(id, user) - irc.reply(msg, conf.replySuccess) - except KeyError: - irc.error(msg, conf.replyNoUser) - else: - irc.error(msg, conf.replyNoCapability % neededcapability) + try: + id = ircdb.users.getUser(name) + user = ircdb.users.getUser(id) + user.removeCapability(capability) + ircdb.users.setUser(id, user) + irc.reply(msg, conf.replySuccess) + except KeyError: + irc.error(msg, conf.replyNoUser) + removechancapability = \ + privmsgs.checkChannelCapability(removechancapability, 'op') - def setdefaultchancapability(self, irc, msg, args): + def setdefaultchancapability(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -311,26 +270,23 @@ class ChannelCommands(callbacks.Privmsg): this will set the default response to non-power-related (that is, not {op, halfop, voice} capabilities to be the value you give. """ - channel = privmsgs.getChannel(msg, args) v = privmsgs.getArgs(args) - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - c = ircdb.channels.getChannel(channel) - v = v.capitalize() - if v == 'True': - c.setDefaultCapability(True) - elif v == 'False': - c.setDefaultCapability(False) - else: - s = 'The default value must be either True or False.' - irc.error(msg, s) - return - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) + c = ircdb.channels.getChannel(channel) + v = v.capitalize() + if v == 'True': + c.setDefaultCapability(True) + elif v == 'False': + c.setDefaultCapability(False) else: - irc.error(msg, conf.replyNoCapability % capability) + s = 'The default value must be either True or False.' + irc.error(msg, s) + return + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + setdefaultchancapability = \ + privmsgs.checkChannelCapability(setdefaultchancapability, 'op') - def setchancapability(self, irc, msg, args): + def setchancapability(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -338,18 +294,15 @@ class ChannelCommands(callbacks.Privmsg): this will add the channel capability for all users in the channel. """ - channel = privmsgs.getChannel(msg, args) - neededcapability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, neededcapability): - capability = privmsgs.getArgs(args) - c = ircdb.channels.getChannel(channel) - c.addCapability(capability) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % neededcapability) + capability = privmsgs.getArgs(args) + c = ircdb.channels.getChannel(channel) + c.addCapability(capability) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + setchancapability = privmsgs.checkChannelCapability(setchancapability, + 'op') - def unsetchancapability(self, irc, msg, args): + def unsetchancapability(self, irc, msg, args, channel): """[] The argument is only necessary if the message isn't being @@ -358,16 +311,13 @@ class ChannelCommands(callbacks.Privmsg): specific capability or the channel default capability will take precedence. """ - channel = privmsgs.getChannel(msg, args) - neededcapability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, neededcapability): - capability = privmsgs.getArgs(args) - c = ircdb.channels.getChannel(channel) - c.removeCapability(capability) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) - else: - irc.error(msg, conf.replyNoCapability % neededcapability) + capability = privmsgs.getArgs(args) + c = ircdb.channels.getChannel(channel) + c.removeCapability(capability) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) + unsetchancapability = privmsgs.checkChannelCapability(unsetchancapability, + 'op') def chancapabilities(self, irc, msg, args): """[] diff --git a/test/test_ChannelCommands.py b/test/test_ChannelCommands.py index 9c994b66e..d5dbc6c4c 100644 --- a/test/test_ChannelCommands.py +++ b/test/test_ChannelCommands.py @@ -58,6 +58,20 @@ class ChannelCommandsTestCase(ChannelPluginTestCase, PluginDocumentation): self.irc.feedMsg(ircmsgs.op(self.channel, self.nick)) self.assertNotError('kban foobar') + def testLobotomizers(self): + self.assertNotError('lobotomize') + self.assertNotError('unlobotomize') + + def testPermban(self): + self.assertNotError('permban foo!bar@baz') + self.assertNotError('unpermban foo!bar@baz') + self.assertError('permban not!a.hostmask') + + def testChanignore(self): + self.assertNotError('chanignore foo!bar@baz') + self.assertNotError('unchanignore foo!bar@baz') + self.assertError('permban not!a.hostmask') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: