mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Updated to use checkChannelCapability.
This commit is contained in:
parent
6429a00a9a
commit
a91c55a93a
@ -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):
|
||||
"""[<channel>]
|
||||
|
||||
The <channel> 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):
|
||||
"""[<channel>]
|
||||
|
||||
The <channel> 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):
|
||||
"""[<channel>]
|
||||
|
||||
The <channel> 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):
|
||||
"""[<channel>]
|
||||
|
||||
The <channel> 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):
|
||||
"""[<channel>] <nick> [<number of seconds to ban>]
|
||||
@ -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):
|
||||
"""[<channel>]
|
||||
|
||||
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
|
||||
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):
|
||||
"""[<channel>]
|
||||
|
||||
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
|
||||
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):
|
||||
"""[<channel>] <nick|hostmask>
|
||||
|
||||
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>
|
||||
(or the current hostmask associated with <nick>.
|
||||
"""
|
||||
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):
|
||||
"""[<channel>] <hostmask>
|
||||
|
||||
The <channel> 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 <hostmask>.
|
||||
"""
|
||||
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):
|
||||
"""[<channel>] <nick|hostmask>
|
||||
|
||||
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
|
||||
hostmask currently associated with <nick>.
|
||||
"""
|
||||
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):
|
||||
"""[<channel>] <hostmask>
|
||||
|
||||
The <channel> 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 <hostmask> 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):
|
||||
"""[<channel>] <name|hostmask> <capability>
|
||||
|
||||
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
|
||||
to whom <hostmask> maps) the capability <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):
|
||||
"""[<channel>] <name|hostmask> <capability>
|
||||
|
||||
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
|
||||
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):
|
||||
"""[<channel>] <default response to unknown capabilities> <True|False>
|
||||
|
||||
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,
|
||||
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):
|
||||
"""[<channel>] <capability>
|
||||
|
||||
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
|
||||
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):
|
||||
"""[<chanel>] <capability>
|
||||
|
||||
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
|
||||
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):
|
||||
"""[<channel>]
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user