Updated to use checkChannelCapability.

This commit is contained in:
Jeremy Fincher 2003-09-29 05:01:41 +00:00
parent 6429a00a9a
commit a91c55a93a
2 changed files with 123 additions and 159 deletions

View File

@ -45,71 +45,55 @@ import privmsgs
import callbacks import callbacks
class ChannelCommands(callbacks.Privmsg): class ChannelCommands(callbacks.Privmsg):
def op(self, irc, msg, args): def op(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.op capability, sent in the channel itself. If you have the #channel.op capability,
this will give you ops. this will give you ops.
""" """
channel = privmsgs.getChannel(msg, args) if irc.nick in irc.state.channels[channel].ops:
capability = ircdb.makeChannelCapability(channel, 'op') irc.queueMsg(ircmsgs.op(channel, msg.nick))
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!')
else: 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):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.halfop sent in the channel itself. If you have the #channel.halfop
capability, this will give you halfops. capability, this will give you halfops.
""" """
channel = privmsgs.getChannel(msg, args) if irc.nick in irc.state.channels[channel].ops:
capability = ircdb.makeChannelCapability(channel, 'halfop') irc.queueMsg(ircmsgs.halfop(channel, msg.nick))
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!')
else: 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):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.voice capability, sent in the channel itself. If you have the #channel.voice capability,
this will give you voice. this will give you voice.
""" """
channel = privmsgs.getChannel(msg, args) if irc.nick in irc.state.channels[channel].ops:
capability = ircdb.makeChannelCapability(channel, 'voice') irc.queueMsg(ircmsgs.voice(channel, msg.nick))
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!')
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, 'How can I voice you? I\'m not opped!')
voice = privmsgs.checkChannelCapability(voice, 'voice')
def cycle(self, irc, msg, args): def cycle(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.op capability, 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. this will cause the bot to "cycle", or PART and then JOIN the channel.
""" """
channel = privmsgs.getChannel(msg, args) irc.queueMsg(ircmsgs.part(channel))
capability = ircdb.makeChannelCapability(channel, 'op') irc.queueMsg(ircmsgs.join(channel))
if ircdb.checkCapability(msg.prefix, capability): cycle = privmsgs.checkChannelCapability(cycle, 'op')
irc.queueMsg(ircmsgs.part(channel))
irc.queueMsg(ircmsgs.join(channel))
else:
irc.error(msg, conf.replyNoCapability % capability)
def kban(self, irc, msg, args): def kban(self, irc, msg, args):
"""[<channel>] <nick> [<number of seconds to ban>] """[<channel>] <nick> [<number of seconds to ban>]
@ -140,7 +124,7 @@ class ChannelCommands(callbacks.Privmsg):
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
def lobotomize(self, irc, msg, args): def lobotomize(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> 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 this will "lobotomize" the bot, making it silent and unanswering to
all requests made in the channel. all requests made in the channel.
""" """
channel = privmsgs.getChannel(msg, args) ircdb.channels.getChannel(channel).lobotomized = True
capability = ircdb.makeChannelCapability(channel, 'op') irc.reply(msg, conf.replySuccess)
if ircdb.checkCapability(msg.prefix, capability): lobotomize = privmsgs.checkChannelCapability(lobotomize, 'op')
ircdb.channels.getChannel(channel).lobotomized = True
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % capability)
def unlobotomize(self, irc, msg, args): def unlobotomize(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
The <channel> argument is only necessary if the message isn't being The <channel> 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 this will unlobotomize the bot, making it respond to requests made in
the channel again. the channel again.
""" """
channel = privmsgs.getChannel(msg, args) ircdb.channels.getChannel(channel).lobotomized = False
capability = ircdb.makeChannelCapability(channel, 'op') irc.reply(msg, conf.replySuccess)
if ircdb.checkCapability(msg.prefix, capability): unlobotomize = privmsgs.checkChannelCapability(unlobotomize, 'op')
ircdb.channels.getChannel(channel).lobotomized = False
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % capability)
def permban(self, irc, msg, args): def permban(self, irc, msg, args, channel):
"""[<channel>] <nick|hostmask> """[<channel>] <nick|hostmask>
The <channel> argument is only necessary if the message isn't being The <channel> 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 <hostmask> this will effect a permanent (persistent) ban on the given <hostmask>
(or the current hostmask associated with <nick>. (or the current hostmask associated with <nick>.
""" """
channel = privmsgs.getChannel(msg, args)
capability = ircdb.makeChannelCapability(channel, 'op')
arg = privmsgs.getArgs(args) arg = privmsgs.getArgs(args)
if ircutils.isNick(arg): if ircutils.isNick(arg):
banmask = ircutils.banmask(irc.state.nickToHostmask(arg)) banmask = ircutils.banmask(irc.state.nickToHostmask(arg))
else: elif ircutils.isUserHostmask(arg):
banmask = 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: 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):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.op capability, sent in the channel itself. If you have the #channel.op capability,
this will remove the permanent ban on <hostmask>. this will remove the permanent ban on <hostmask>.
""" """
channel = privmsgs.getChannel(msg, args)
capability = ircdb.makeChannelCapability(channel, 'op')
banmask = privmsgs.getArgs(args) banmask = privmsgs.getArgs(args)
if ircdb.checkCapability(msg.prefix, capability): 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.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) unpermban = privmsgs.checkChannelCapability(unpermban, 'op')
else:
irc.error(msg, conf.replyNoCapability % capability)
def chanignore(self, irc, msg, args): def chanignore(self, irc, msg, args, channel):
"""[<channel>] <nick|hostmask> """[<channel>] <nick|hostmask>
The <channel> argument is only necessary if the message isn't being The <channel> 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 <hostmask> or the this will set a permanent (persistent) ignore on <hostmask> or the
hostmask currently associated with <nick>. hostmask currently associated with <nick>.
""" """
channel = privmsgs.getChannel(msg, args)
capability = ircdb.makeChannelCapability(channel, 'op')
arg = privmsgs.getArgs(args) arg = privmsgs.getArgs(args)
if ircutils.isNick(arg): if ircutils.isNick(arg):
banmask = ircutils.banmask(irc.state.nickToHostmask(arg)) banmask = ircutils.banmask(irc.state.nickToHostmask(arg))
else: elif ircutils.isUserHostmask(arg):
banmask = 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: 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):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
sent in the channel itself. If you have the #channel.op capability, sent in the channel itself. If you have the #channel.op capability,
this will remove the permanent ignore on <hostmask> in the channel. this will remove the permanent ignore on <hostmask> in the channel.
""" """
channel = privmsgs.getChannel(msg, args)
capability = ircdb.makeChannelCapability(channel, 'op')
banmask = privmsgs.getArgs(args) banmask = privmsgs.getArgs(args)
if ircdb.checkCapability(msg.prefix, capability): 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.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) unchanignore = privmsgs.checkChannelCapability(unchanignore, 'op')
else:
irc.error(msg, conf.replyNoCapability % capability)
def addchancapability(self, irc, msg, args): def addchancapability(self, irc, msg, args, channel):
"""[<channel>] <name|hostmask> <capability> """[<channel>] <name|hostmask> <capability>
The <channel> argument is only necessary if the message isn't being The <channel> 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 <name> (or the user this will give the user currently identified as <name> (or the user
to whom <hostmask> maps) the capability <capability> in the channel. to whom <hostmask> maps) the capability <capability> in the channel.
""" """
channel = privmsgs.getChannel(msg, args)
(name, capability) = privmsgs.getArgs(args, 2) (name, capability) = privmsgs.getArgs(args, 2)
neededcapability = ircdb.makeChannelCapability(channel, 'op')
capability = ircdb.makeChannelCapability(channel, capability) capability = ircdb.makeChannelCapability(channel, capability)
if ircdb.checkCapability(msg.prefix, neededcapability): try:
try: id = ircdb.users.getUserId(name)
id = ircdb.users.getUserId(name) user = ircdb.users.getUser(id)
user = ircdb.users.getUser(id) user.addCapability(capability)
user.addCapability(capability) ircdb.users.setUser(id, user)
ircdb.users.setUser(id, user) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) except KeyError:
except KeyError: irc.error(msg, conf.replyNoUser)
irc.error(msg, conf.replyNoUser) addchancapability = privmsgs.checkChannelCapability(addchancapability,'op')
else:
irc.error(msg, conf.replyNoCapability % neededcapability)
def removechancapability(self, irc, msg, args): def removechancapability(self, irc, msg, args, channel):
"""[<channel>] <name|hostmask> <capability> """[<channel>] <name|hostmask> <capability>
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
@ -287,23 +249,20 @@ class ChannelCommands(callbacks.Privmsg):
user to whom <hostmask> maps) the capability <capability> in the user to whom <hostmask> maps) the capability <capability> in the
channel. channel.
""" """
channel = privmsgs.getChannel(msg, args)
(name, capability) = privmsgs.getArgs(args, 2) (name, capability) = privmsgs.getArgs(args, 2)
neededcapability = ircdb.makeChannelCapability(channel, 'op')
capability = ircdb.makeChannelCapability(channel, capability) capability = ircdb.makeChannelCapability(channel, capability)
if ircdb.checkCapability(msg.prefix, neededcapability): try:
try: id = ircdb.users.getUser(name)
id = ircdb.users.getUser(name) user = ircdb.users.getUser(id)
user = ircdb.users.getUser(id) user.removeCapability(capability)
user.removeCapability(capability) ircdb.users.setUser(id, user)
ircdb.users.setUser(id, user) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) except KeyError:
except KeyError: irc.error(msg, conf.replyNoUser)
irc.error(msg, conf.replyNoUser) removechancapability = \
else: privmsgs.checkChannelCapability(removechancapability, 'op')
irc.error(msg, conf.replyNoCapability % neededcapability)
def setdefaultchancapability(self, irc, msg, args): def setdefaultchancapability(self, irc, msg, args, channel):
"""[<channel>] <default response to unknown capabilities> <True|False> """[<channel>] <default response to unknown capabilities> <True|False>
The <channel> argument is only necessary if the message isn't being The <channel> 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, this will set the default response to non-power-related (that is,
not {op, halfop, voice} capabilities to be the value you give. not {op, halfop, voice} capabilities to be the value you give.
""" """
channel = privmsgs.getChannel(msg, args)
v = privmsgs.getArgs(args) v = privmsgs.getArgs(args)
capability = ircdb.makeChannelCapability(channel, 'op') c = ircdb.channels.getChannel(channel)
if ircdb.checkCapability(msg.prefix, capability): v = v.capitalize()
c = ircdb.channels.getChannel(channel) if v == 'True':
v = v.capitalize() c.setDefaultCapability(True)
if v == 'True': elif v == 'False':
c.setDefaultCapability(True) c.setDefaultCapability(False)
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)
else: 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):
"""[<channel>] <capability> """[<channel>] <capability>
The <channel> argument is only necessary if the message isn't being The <channel> argument is only necessary if the message isn't being
@ -338,18 +294,15 @@ class ChannelCommands(callbacks.Privmsg):
this will add the channel capability <capability> for all users in the this will add the channel capability <capability> for all users in the
channel. channel.
""" """
channel = privmsgs.getChannel(msg, args) capability = privmsgs.getArgs(args)
neededcapability = ircdb.makeChannelCapability(channel, 'op') c = ircdb.channels.getChannel(channel)
if ircdb.checkCapability(msg.prefix, neededcapability): c.addCapability(capability)
capability = privmsgs.getArgs(args) ircdb.channels.setChannel(channel, c)
c = ircdb.channels.getChannel(channel) irc.reply(msg, conf.replySuccess)
c.addCapability(capability) setchancapability = privmsgs.checkChannelCapability(setchancapability,
ircdb.channels.setChannel(channel, c) 'op')
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % neededcapability)
def unsetchancapability(self, irc, msg, args): def unsetchancapability(self, irc, msg, args, channel):
"""[<chanel>] <capability> """[<chanel>] <capability>
The <channel> argument is only necessary if the message isn't being The <channel> 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 specific capability or the channel default capability will take
precedence. precedence.
""" """
channel = privmsgs.getChannel(msg, args) capability = privmsgs.getArgs(args)
neededcapability = ircdb.makeChannelCapability(channel, 'op') c = ircdb.channels.getChannel(channel)
if ircdb.checkCapability(msg.prefix, neededcapability): c.removeCapability(capability)
capability = privmsgs.getArgs(args) ircdb.channels.setChannel(channel, c)
c = ircdb.channels.getChannel(channel) irc.reply(msg, conf.replySuccess)
c.removeCapability(capability) unsetchancapability = privmsgs.checkChannelCapability(unsetchancapability,
ircdb.channels.setChannel(channel, c) 'op')
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % neededcapability)
def chancapabilities(self, irc, msg, args): def chancapabilities(self, irc, msg, args):
"""[<channel>] """[<channel>]

View File

@ -58,6 +58,20 @@ class ChannelCommandsTestCase(ChannelPluginTestCase, PluginDocumentation):
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick)) self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
self.assertNotError('kban foobar') 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: