This commit is contained in:
Jeremy Fincher 2004-10-02 02:36:10 +00:00
parent 8a98fe66f4
commit e21be94af0
1 changed files with 67 additions and 117 deletions

View File

@ -49,7 +49,7 @@ 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
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
import supybot.commands as commands from supybot.commands import wrap
import supybot.schedule as schedule import supybot.schedule as schedule
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
@ -79,11 +79,10 @@ class Channel(callbacks.Privmsg):
itself. itself.
""" """
irc.queueMsg(ircmsgs.mode(channel, args)) irc.queueMsg(ircmsgs.mode(channel, args))
mode = commands.wrap(mode, mode = wrap(mode,
['channel', [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'change the mode')],
('haveOp', 'change the mode')], requireExtra=True)
requireExtra=True)
def limit(self, irc, msg, args, channel, limit): def limit(self, irc, msg, args, channel, limit):
"""[<channel>] [<limit>] """[<channel>] [<limit>]
@ -96,10 +95,9 @@ class Channel(callbacks.Privmsg):
irc.queueMsg(ircmsgs.mode(channel, ['+l', limit])) irc.queueMsg(ircmsgs.mode(channel, ['+l', limit]))
else: else:
irc.queueMsg(ircmsgs.mode(channel, ['-l'])) irc.queueMsg(ircmsgs.mode(channel, ['-l']))
limit = commands.wrap(mode, ['channel', limit = wrap(mode, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'change the limit'),
('haveOp', 'change the limit'), ('?nonNegativeInt', 0)])
('?nonNegativeInt', 0)])
def moderate(self, irc, msg, args, channel): def moderate(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -109,9 +107,8 @@ class Channel(callbacks.Privmsg):
message isn't sent in the channel itself. message isn't sent in the channel itself.
""" """
irc.queueMsg(ircmsgs.mode(channel, ['+m'])) irc.queueMsg(ircmsgs.mode(channel, ['+m']))
moderate = commands.wrap(moderate, ['channel', moderate = wrap(moderate, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'moderate the channel')])
('haveOp', 'moderate the channel')])
def unmoderate(self, irc, msg, args, channel): def unmoderate(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -121,10 +118,8 @@ class Channel(callbacks.Privmsg):
message isn't sent in the channel itself. message isn't sent in the channel itself.
""" """
irc.queueMsg(ircmsgs.mode(channel, ['-m'])) irc.queueMsg(ircmsgs.mode(channel, ['-m']))
unmoderate = commands.wrap(unmoderate, ['channel', unmoderate = wrap(unmoderate, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'unmoderate the channel')])
('haveOp',
'unmoderate the channel')])
def key(self, irc, msg, args, channel, key): def key(self, irc, msg, args, channel, key):
"""[<channel>] [<key>] """[<channel>] [<key>]
@ -137,10 +132,8 @@ class Channel(callbacks.Privmsg):
irc.queueMsg(ircmsgs.mode(channel, ['+k', key])) irc.queueMsg(ircmsgs.mode(channel, ['+k', key]))
else: else:
irc.queueMsg(ircmsgs.mode(channel, ['-k'])) irc.queueMsg(ircmsgs.mode(channel, ['-k']))
key = commands.wrap(key, ['channel', key = wrap(key, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'change the keyword'), '?capability'])
('haveOp', 'change the keyword'),
'?somethingWithoutSpaces'])
def op(self, irc, msg, args, channel): def op(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...] """[<channel>] [<nick> ...]
@ -153,9 +146,7 @@ class Channel(callbacks.Privmsg):
if not args: if not args:
args = [msg.nick] args = [msg.nick]
irc.queueMsg(ircmsgs.ops(channel, args)) irc.queueMsg(ircmsgs.ops(channel, args))
op = commands.wrap(op, ['channel', op = wrap(op, [('checkChannelCapability', 'op'), ('haveOp', 'op someone')])
('checkChannelCapability', 'op'),
('haveOp', 'op someone')])
def halfop(self, irc, msg, args, channel): def halfop(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -168,9 +159,8 @@ class Channel(callbacks.Privmsg):
if not args: if not args:
args = [msg.nick] args = [msg.nick]
irc.queueMsg(ircmsgs.halfops(channel, args)) irc.queueMsg(ircmsgs.halfops(channel, args))
halfop = commands.wrap(halfop, ['channel', halfop = wrap(halfop, [('checkChannelCapability', 'halfop'),
('checkChannelCapability', 'halfop'), ('haveOp', 'halfop someone')])
('haveOp', 'halfop someone')])
def voice(self, irc, msg, args, channel): def voice(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -183,9 +173,8 @@ class Channel(callbacks.Privmsg):
if not args: if not args:
args = [msg.nick] args = [msg.nick]
irc.queueMsg(ircmsgs.voices(channel, args)) irc.queueMsg(ircmsgs.voices(channel, args))
voice = commands.wrap(voice, ['channel', voice = wrap(voice, [('checkChannelCapability', 'voice'),
('checkChannelCapability', 'voice'), ('haveOp', 'voice someone')])
('haveOp', 'voice someone')])
def deop(self, irc, msg, args, channel): def deop(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...] """[<channel>] [<nick> ...]
@ -202,9 +191,8 @@ class Channel(callbacks.Privmsg):
'yourself.') 'yourself.')
else: else:
irc.queueMsg(ircmsgs.deops(channel, args)) irc.queueMsg(ircmsgs.deops(channel, args))
deop = commands.wrap(deop, ['channel', deop = wrap(deop, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'deop someone')])
('haveOp', 'deop someone')])
def dehalfop(self, irc, msg, args, channel): def dehalfop(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...] """[<channel>] [<nick> ...]
@ -221,9 +209,8 @@ class Channel(callbacks.Privmsg):
'dehalfop me yourself.') 'dehalfop me yourself.')
else: else:
irc.queueMsg(ircmsgs.dehalfops(channel, args)) irc.queueMsg(ircmsgs.dehalfops(channel, args))
dehalfop = commands.wrap(dehalfop, ['channel', dehalfop = wrap(dehalfop, [('checkChannelCapability', 'halfop'),
('checkChannelCapability', 'halfop'), ('haveOp', 'dehalfop someone')])
('haveOp', 'dehalfop someone')])
def devoice(self, irc, msg, args, channel): def devoice(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...] """[<channel>] [<nick> ...]
@ -240,9 +227,8 @@ class Channel(callbacks.Privmsg):
'me yourself.') 'me yourself.')
else: else:
irc.queueMsg(ircmsgs.devoices(channel, args)) irc.queueMsg(ircmsgs.devoices(channel, args))
devoice = commands.wrap(devoice, ['channel', devoice = wrap(devoice, [('checkChannelCapability', 'voice'),
('checkChannelCapability', 'voice'), ('haveOp', 'devoice someone')])
('haveOp', 'devoice someone')])
def cycle(self, irc, msg, args, channel, key): def cycle(self, irc, msg, args, channel, key):
"""[<channel>] [<key>] """[<channel>] [<key>]
@ -257,9 +243,7 @@ class Channel(callbacks.Privmsg):
irc.queueMsg(ircmsgs.part(channel)) irc.queueMsg(ircmsgs.part(channel))
irc.queueMsg(ircmsgs.join(channel, key)) irc.queueMsg(ircmsgs.join(channel, key))
irc.noReply() irc.noReply()
cycle = commands.wrap(cycle, ['channel', cycle = wrap(cycle, [('checkChannelCapability','op'),'?anything'])
('checkChannelCapability', 'op'),
'?anything'])
def kick(self, irc, msg, args, channel, nick, reason): def kick(self, irc, msg, args, channel, nick, reason):
"""[<channel>] <nick> [<reason>] """[<channel>] <nick> [<reason>]
@ -281,11 +265,8 @@ class Channel(callbacks.Privmsg):
return return
irc.queueMsg(ircmsgs.kick(channel, nick, reason)) irc.queueMsg(ircmsgs.kick(channel, nick, reason))
irc.noReply() irc.noReply()
kick = commands.wrap(kick, ['channel', kick = wrap(kick, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'kick someone'), 'nick', '?anything'])
('haveOp', 'kick someone'),
'nick',
'?anything'])
def kban(self, irc, msg, args, def kban(self, irc, msg, args,
optlist, channel, bannedNick, length, reason): optlist, channel, bannedNick, length, reason):
@ -316,8 +297,7 @@ class Channel(callbacks.Privmsg):
try: try:
bannedHostmask = irc.state.nickToHostmask(bannedNick) bannedHostmask = irc.state.nickToHostmask(bannedNick)
except KeyError: except KeyError:
irc.error('I haven\'t seen %s.' % bannedNick) irc.error('I haven\'t seen %s.' % bannedNick, Raise=True)
return
capability = ircdb.makeChannelCapability(channel, 'op') capability = ircdb.makeChannelCapability(channel, 'op')
if optlist: if optlist:
(nick, user, host) = ircutils.splitHostmask(bannedHostmask) (nick, user, host) = ircutils.splitHostmask(bannedHostmask)
@ -375,14 +355,14 @@ class Channel(callbacks.Privmsg):
msg.prefix, capability) msg.prefix, capability)
irc.errorNoCapability(capability) irc.errorNoCapability(capability)
exact,nick,user,host exact,nick,user,host
kban = commands.wrap(kban, ['channel', kban = wrap(kban,
('checkChannelCapability', 'op'), [('checkChannelCapability', 'op'),
('haveOp', 'kick or ban someone'), ('haveOp', 'kick or ban someone'),
'nick', ('expiry?', 0), '?anything'], 'nick', ('expiry?', 0), '?anything'],
getopts={'exact': None, getopts={'exact': None,
'nick': None, 'nick': None,
'user': None, 'user': None,
'host': None}) 'host': None})
def unban(self, irc, msg, args, channel, hostmask): def unban(self, irc, msg, args, channel, hostmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -393,10 +373,8 @@ class Channel(callbacks.Privmsg):
in the channel itself. in the channel itself.
""" """
irc.queueMsg(ircmsgs.unban(channel, hostmask)) irc.queueMsg(ircmsgs.unban(channel, hostmask))
unban = commands.wrap(unban, ['channel', unban = wrap(unban, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'unban someone'), 'hostmask'])
('haveOp', 'unban someone'),
'hostmask'])
def invite(self, irc, msg, args, channel, nick): def invite(self, irc, msg, args, channel, nick):
"""[<channel>] <nick> """[<channel>] <nick>
@ -406,10 +384,8 @@ class Channel(callbacks.Privmsg):
sent in the channel itself. sent in the channel itself.
""" """
irc.queueMsg(ircmsgs.invite(nick, channel)) irc.queueMsg(ircmsgs.invite(nick, channel))
invite = commands.wrap(invite, ['channel', invite = wrap(invite, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), ('haveOp', 'invite someone'), 'nick'])
('haveOp', 'invite someone'),
'nick'])
def lobotomize(self, irc, msg, args, channel): def lobotomize(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -423,8 +399,7 @@ class Channel(callbacks.Privmsg):
c.lobotomized = True c.lobotomized = True
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
lobotomize = commands.wrap(lobotomize, ['channel', lobotomize = wrap(lobotomize, [('checkChannelCapability', 'op')])
('checkChannelCapability', 'op')])
def unlobotomize(self, irc, msg, args, channel): def unlobotomize(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -438,9 +413,7 @@ class Channel(callbacks.Privmsg):
c.lobotomized = False c.lobotomized = False
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unlobotomize = commands.wrap(unlobotomize, unlobotomize = wrap(unlobotomize, [('checkChannelCapability', 'op')])
['channel',
('checkChannelCapability', 'op')])
def permban(self, irc, msg, args, channel, banmask, expires): def permban(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
@ -458,10 +431,8 @@ class Channel(callbacks.Privmsg):
c.addBan(banmask, expires) c.addBan(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
permban = commands.wrap(permban, ['channel', permban = wrap(permban, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), 'hostmask', ('?expiry', 0)])
'hostmask',
('?expiry', 0)])
def unpermban(self, irc, msg, args, channel, banmask): def unpermban(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -474,9 +445,7 @@ class Channel(callbacks.Privmsg):
c.removeBan(banmask) c.removeBan(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unpermban = commands.wrap(unpermban, ['channel', unpermban = wrap(unpermban, [('checkChannelCapability', 'op'), 'hostmask'])
('checkChannelCapability', 'op'),
'hostmask'])
def permbans(self, irc, msg, args, channel): def permbans(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -490,8 +459,7 @@ class Channel(callbacks.Privmsg):
irc.reply(utils.commaAndify(map(utils.dqrepr, c.bans))) irc.reply(utils.commaAndify(map(utils.dqrepr, c.bans)))
else: else:
irc.reply('There are currently no permanent bans on %s' % channel) irc.reply('There are currently no permanent bans on %s' % channel)
permbans = commands.wrap(permbans, ['channel', permbans = wrap(permbans, [('checkChannelCapability', 'op')])
('checkChannelCapability', 'op')])
def ignore(self, irc, msg, args, channel, banmask, expires): def ignore(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
@ -507,10 +475,8 @@ class Channel(callbacks.Privmsg):
c.addIgnore(banmask, expires) c.addIgnore(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
ignore = commands.wrap(ignore, ['channel', ignore = wrap(ignore, [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), 'hostmask', ('?expiry', 0)])
'hostmask',
('?expiry', 0)])
def unignore(self, irc, msg, args, channel, banmask): def unignore(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -523,9 +489,7 @@ class Channel(callbacks.Privmsg):
c.removeIgnore(banmask) c.removeIgnore(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unignore = commands.wrap(unignore, ['channel', unignore = wrap(unignore, [('checkChannelCapability', 'op'), 'hostmask'])
('checkChannelCapability', 'op'),
'hostmask'])
def ignores(self, irc, msg, args, channel): def ignores(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -542,8 +506,7 @@ class Channel(callbacks.Privmsg):
else: else:
L = sorted(c.ignores) L = sorted(c.ignores)
irc.reply(utils.commaAndify(imap(repr, L))) irc.reply(utils.commaAndify(imap(repr, L)))
ignores = commands.wrap(ignores, ['channel', ignores = wrap(ignores, [('checkChannelCapability', 'op')])
('checkChannelCapability', 'op')])
def addcapability(self, irc, msg, args, channel, hostmask, capabilities): def addcapability(self, irc, msg, args, channel, hostmask, capabilities):
"""[<channel>] <name|hostmask> <capability> [<capability> ...] """[<channel>] <name|hostmask> <capability> [<capability> ...]
@ -563,11 +526,8 @@ class Channel(callbacks.Privmsg):
user.addCapability(c) user.addCapability(c)
ircdb.users.setUser(id, user) ircdb.users.setUser(id, user)
irc.replySuccess() irc.replySuccess()
addcapability = commands.wrap(addcapability, addcapability = wrap(addcapability, [('checkChannelCapability', 'op'),
['channel', 'hostmask', 'capability'])
('checkChannelCapability', 'op'),
'hostmask',
'somethingWithoutSpaces'])
def removecapability(self, irc, msg, args, channel, hostmask, capabilities): def removecapability(self, irc, msg, args, channel, hostmask, capabilities):
"""[<channel>] <name|hostmask> <capability> [<capability> ...] """[<channel>] <name|hostmask> <capability> [<capability> ...]
@ -596,11 +556,9 @@ class Channel(callbacks.Privmsg):
(utils.commaAndify(fail), (utils.commaAndify(fail),
utils.pluralize('capability', len(fail))), Raise=True) utils.pluralize('capability', len(fail))), Raise=True)
irc.replySuccess() irc.replySuccess()
removecapability = commands.wrap(removecapability, removecapability = wrap(removecapability,
['channel', [('checkChannelCapability', 'op'),
('checkChannelCapability', 'op'), 'hostmask', 'capability'])
'hostmask',
'somethingWithoutSpaces'])
# 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.
@ -619,10 +577,8 @@ class Channel(callbacks.Privmsg):
c.setDefaultCapability(False) c.setDefaultCapability(False)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
setdefaultcapability = commands.wrap(setdefaultcapability, setdefaultcapability = wrap(setdefaultcapability,
['channel', [('checkChannelCapability', 'op'), 'boolean'])
('checkChannelCapability', 'op'),
'boolean'])
def setcapability(self, irc, msg, args, channel, capabilities): def setcapability(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
@ -632,14 +588,12 @@ class Channel(callbacks.Privmsg):
only necessary if the message isn't sent in the channel itself. only necessary if the message isn't sent in the channel itself.
""" """
chan = ircdb.channels.getChannel(channel) chan = ircdb.channels.getChannel(channel)
for c in capabilities.split(): for c in capabilities:
chan.addCapability(c) chan.addCapability(c)
ircdb.channels.setChannel(channel, chan) ircdb.channels.setChannel(channel, chan)
irc.replySuccess() irc.replySuccess()
setcapability = commands.wrap(setcapability, setcapability = wrap(setcapability,
['channel', [('checkChannelCapability', 'op'), 'capability+'])
('checkChannelCapability', 'op'),
'something'])
def unsetcapability(self, irc, msg, args, channel, capabilities): def unsetcapability(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
@ -651,7 +605,7 @@ class Channel(callbacks.Privmsg):
""" """
chan = ircdb.channels.getChannel(channel) chan = ircdb.channels.getChannel(channel)
fail = [] fail = []
for c in capabilities.split(): for c in capabilities:
try: try:
chan.removeCapability(c) chan.removeCapability(c)
except KeyError: except KeyError:
@ -662,10 +616,8 @@ class Channel(callbacks.Privmsg):
(utils.commaAndify(fail), (utils.commaAndify(fail),
utils.pluralize('capability', len(fail))), Raise=True) utils.pluralize('capability', len(fail))), Raise=True)
irc.replySuccess() irc.replySuccess()
unsetcapability = commands.wrap(unsetcapability, unsetcapability = wrap(unsetcapability,
['channel', [('checkChannelCapability', 'op'), 'capability+'])
('checkChannelCapability', 'op'),
'somethingWithoutSpaces'])
def capabilities(self, irc, msg, args, channel): def capabilities(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -676,7 +628,7 @@ class Channel(callbacks.Privmsg):
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 = commands.wrap(capabilities, ['channel']) capabilities = wrap(capabilities, ['channel'])
def lobotomies(self, irc, msg, args): def lobotomies(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -703,7 +655,7 @@ class Channel(callbacks.Privmsg):
L = list(irc.state.channels[channel].users) L = list(irc.state.channels[channel].users)
utils.sortBy(str.lower, L) utils.sortBy(str.lower, L)
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
nicks = commands.wrap(nicks, ['channel']) nicks = wrap(nicks, ['channel'])
def alertOps(self, irc, channel, s, frm=None): def alertOps(self, irc, channel, s, frm=None):
"""Internal message for notifying all the #channel,ops in a channel of """Internal message for notifying all the #channel,ops in a channel of
@ -724,9 +676,7 @@ class Channel(callbacks.Privmsg):
capability. capability.
""" """
self.alertOps(irc, channel, text, frm=msg.nick) self.alertOps(irc, channel, text, frm=msg.nick)
alert = commands.wrap(alert, ['channel', alert = wrap(alert, [('checkChannelCapability', 'op'), 'text'])
('checkChannelCapability', 'op'),
'something'])
Class = Channel Class = Channel