Made making modules that rely on certain capabilities being preset much easier to to write (CapabilityChecker)

This commit is contained in:
Jeremy Fincher 2003-03-27 06:02:37 +00:00
parent 21ad5fa890
commit ee6a33b7e7
1 changed files with 128 additions and 235 deletions

View File

@ -105,7 +105,12 @@ def getKeywordArgs(irc, msg, d=None):
return (args, d) return (args, d)
class CapabilityChecker(callbacks.Privmsg):
def callCommand(self, f, irc, msg, args):
if ircdb.checkCapability(msg.prefix, self.capability):
callbacks.Privmsg.callCommand(self, f, irc, msg, args)
else:
irc.error(msg, conf.replyNoCapability % self.capability)
### ###
# Privmsg Callbacks. # Privmsg Callbacks.
@ -124,7 +129,6 @@ class ChannelCommands(callbacks.Privmsg):
irc.queueMsg(ircmsgs.op(channel, msg.nick)) irc.queueMsg(ircmsgs.op(channel, msg.nick))
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def halfop(self, irc, msg, args): def halfop(self, irc, msg, args):
"""[<channel>] """[<channel>]
@ -139,7 +143,6 @@ class ChannelCommands(callbacks.Privmsg):
irc.queueMsg(ircmsgs.halfop(channel, msg.nick)) irc.queueMsg(ircmsgs.halfop(channel, msg.nick))
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def voice(self, irc, msg, args): def voice(self, irc, msg, args):
"""[<channel>] """[<channel>]
@ -154,7 +157,6 @@ class ChannelCommands(callbacks.Privmsg):
irc.queueMsg(ircmsgs.halfop(channel, msg.nick)) irc.queueMsg(ircmsgs.halfop(channel, msg.nick))
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def cycle(self, irc, msg, args): def cycle(self, irc, msg, args):
"""[<channel>] """[<channel>]
@ -170,7 +172,6 @@ class ChannelCommands(callbacks.Privmsg):
irc.queueMsg(ircmsgs.join(channel)) irc.queueMsg(ircmsgs.join(channel))
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
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>]
@ -197,7 +198,6 @@ class ChannelCommands(callbacks.Privmsg):
schedule.addEvent(f, time.time() + length) schedule.addEvent(f, time.time() + length)
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def lobotomize(self, irc, msg, args): def lobotomize(self, irc, msg, args):
"""[<channel>] """[<channel>]
@ -212,10 +212,8 @@ class ChannelCommands(callbacks.Privmsg):
if ircdb.checkCapability(msg.prefix, capability): if ircdb.checkCapability(msg.prefix, capability):
ircdb.channels.getChannel(channel).lobotomized = True ircdb.channels.getChannel(channel).lobotomized = True
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def unlobotomize(self, irc, msg, args): def unlobotomize(self, irc, msg, args):
"""[<channel>] """[<channel>]
@ -230,10 +228,8 @@ class ChannelCommands(callbacks.Privmsg):
if ircdb.checkCapability(msg.prefix, capability): if ircdb.checkCapability(msg.prefix, capability):
ircdb.channels.getChannel(channel).lobotomized = False ircdb.channels.getChannel(channel).lobotomized = False
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def permban(self, irc, msg, args): def permban(self, irc, msg, args):
"""[<channel>] <nick|hostmask> """[<channel>] <nick|hostmask>
@ -255,10 +251,8 @@ class ChannelCommands(callbacks.Privmsg):
c.addBan(banmask) c.addBan(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def unpermban(self, irc, msg, args): def unpermban(self, irc, msg, args):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -275,10 +269,8 @@ class ChannelCommands(callbacks.Privmsg):
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)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def chanignore(self, irc, msg, args): def chanignore(self, irc, msg, args):
"""[<channel>] <nick|hostmask> """[<channel>] <nick|hostmask>
@ -300,10 +292,8 @@ class ChannelCommands(callbacks.Privmsg):
c.addIgnore(banmask) c.addIgnore(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def unchanignore(self, irc, msg, args): def unchanignore(self, irc, msg, args):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -320,10 +310,8 @@ class ChannelCommands(callbacks.Privmsg):
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)
return
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
return
def addchancapability(self, irc, msg, args): def addchancapability(self, irc, msg, args):
"""[<channel>] <name|hostmask> <capability> """[<channel>] <name|hostmask> <capability>
@ -343,13 +331,10 @@ class ChannelCommands(callbacks.Privmsg):
u.addCapability(capability) u.addCapability(capability)
ircdb.users.setUser(name, u) ircdb.users.setUser(name, u)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
except KeyError: except KeyError:
irc.error(msg, conf.replyNoUser) irc.error(msg, conf.replyNoUser)
return
else: else:
irc.error(msg, conf.replyNoCapability % neededcapability) irc.error(msg, conf.replyNoCapability % neededcapability)
return
def removechancapability(self, irc, msg, args): def removechancapability(self, irc, msg, args):
"""[<channel>] <name|hostmask> <capability> """[<channel>] <name|hostmask> <capability>
@ -423,14 +408,11 @@ class ChannelCommands(callbacks.Privmsg):
c.addCapability(capability, value) c.addCapability(capability, value)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
s = 'Value of the capability must be True or False' s = 'Value of the capability must be True or False'
irc.error(msg, s) irc.error(msg, s)
return
else: else:
irc.error(msg, conf.replyNoCapability % neededcapability) irc.error(msg, conf.replyNoCapability % neededcapability)
return
def unsetchancapability(self, irc, msg, args): def unsetchancapability(self, irc, msg, args):
"""[<chanel>] <capability> """[<chanel>] <capability>
@ -449,37 +431,28 @@ class ChannelCommands(callbacks.Privmsg):
c.removeCapability(capability) c.removeCapability(capability)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % neededcapability) irc.error(msg, conf.replyNoCapability % neededcapability)
return
class AdminCommands(callbacks.Privmsg): class AdminCommands(CapabilityChecker):
capability = 'admin'
def join(self, irc, msg, args): def join(self, irc, msg, args):
"""<channel> [<channel> ...] """<channel> [<channel> ...]
Tell the bot to join the whitespace-separated list of channels Tell the bot to join the whitespace-separated list of channels
you give it. you give it.
""" """
if ircdb.checkCapability(msg.prefix, 'admin'): irc.queueMsg(ircmsgs.joins(args))
irc.queueMsg(ircmsgs.joins(args)) for channel in args:
for channel in args: irc.queueMsg(ircmsgs.who(channel))
irc.queueMsg(ircmsgs.who(channel))
else:
irc.error(msg, conf.replyNoCapability % 'admin')
return
def nick(self, irc, msg, args): def nick(self, irc, msg, args):
"""<nick> """<nick>
Changes the bot's nick to <nick>.""" Changes the bot's nick to <nick>."""
nick = getArgs(args) nick = getArgs(args)
if ircdb.checkCapability(msg.prefix, 'admin'): irc.queueMsg(ircmsgs.nick(nick))
irc.queueMsg(ircmsgs.nick(nick))
else:
irc.error(msg, conf.replyNoCapability % 'admin')
return
def part(self, irc, msg, args): def part(self, irc, msg, args):
"""<channel> [<channel> ...] """<channel> [<channel> ...]
@ -487,11 +460,7 @@ class AdminCommands(callbacks.Privmsg):
Tells the bot to part the whitespace-separated list of channels Tells the bot to part the whitespace-separated list of channels
you give it. you give it.
""" """
if ircdb.checkCapability(msg.prefix, 'admin'): irc.queueMsg(ircmsgs.parts(args, msg.nick))
irc.queueMsg(ircmsgs.parts(args, msg.nick))
else:
irc.error(msg, conf.replyNoCapability % 'admin')
return
def disable(self, irc, msg, args): def disable(self, irc, msg, args):
"""<command> """<command>
@ -499,21 +468,16 @@ class AdminCommands(callbacks.Privmsg):
Disables the command <command> for all non-owner users. Disables the command <command> for all non-owner users.
""" """
command = getArgs(args) command = getArgs(args)
if ircdb.checkCapability(msg.prefix, 'admin'): if command in ('enable', 'identify'):
if command in ('enable', 'identify'): irc.error(msg, 'You can\'t disable %s!' % command)
irc.error(msg, 'You can\'t disable %s!' % command)
else:
# This has to know that defaultCapabilties gets turned into a
# dictionary.
if command in conf.defaultCapabilities:
conf.defaultCapabilities.remove(command)
capability = ircdb.makeAntiCapability(command)
conf.defaultCapabilities.add(capability)
irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % 'admin') # This has to know that defaultCapabilties gets turned into a
return # dictionary.
if command in conf.defaultCapabilities:
conf.defaultCapabilities.remove(command)
capability = ircdb.makeAntiCapability(command)
conf.defaultCapabilities.add(capability)
irc.reply(msg, conf.replySuccess)
def enable(self, irc, msg, args): def enable(self, irc, msg, args):
"""<command> """<command>
@ -522,17 +486,11 @@ class AdminCommands(callbacks.Privmsg):
""" """
command = getArgs(args) command = getArgs(args)
anticapability = ircdb.makeAntiCapability(command) anticapability = ircdb.makeAntiCapability(command)
if ircdb.checkCapability(msg.prefix, 'admin'): if anticapability in conf.defaultCapabilities:
if anticapability in conf.defaultCapabilities: conf.defaultCapabilities.remove(anticapability)
conf.defaultCapabilities.remove(anticapability) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
return
else:
irc.error(msg, 'That command wasn\'t disabled.')
return
else: else:
irc.error(msg, conf.replyNoCapability % 'admin') irc.error(msg, 'That command wasn\'t disabled.')
return
def addcapability(self, irc, msg, args): def addcapability(self, irc, msg, args):
"""<name|hostmask> <capability> """<name|hostmask> <capability>
@ -541,26 +499,19 @@ class AdminCommands(callbacks.Privmsg):
currently maps) the specified capability <capability> currently maps) the specified capability <capability>
""" """
(name, capability) = getArgs(args, 2) (name, capability) = getArgs(args, 2)
if ircdb.checkCapability(msg.prefix, 'admin'): # This next check to make sure 'admin's can't hand out 'owner'.
# This next check to make sure 'admin's can't hand out 'owner'. if ircdb.checkCapability(msg.prefix, capability) or \
if ircdb.checkCapability(msg.prefix, capability) or \ '!' in capability:
'!' in capability: try:
try: u = ircdb.users.getUser(name)
u = ircdb.users.getUser(name) u.addCapability(capability)
u.addCapability(capability) ircdb.users.setUser(name, u)
ircdb.users.setUser(name, u) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) except KeyError:
return irc.error(msg, conf.replyNoUser)
except KeyError:
irc.error(msg, conf.replyNoUser)
return
else:
s = 'You can\'t add capabilities you don\'t have.'
irc.error(msg, s)
return
else: else:
irc.error(msg, conf.replyNoCapability % 'admin') s = 'You can\'t add capabilities you don\'t have.'
return irc.error(msg, s)
def removecapability(self, irc, msg, args): def removecapability(self, irc, msg, args):
"""<name|hostmask> <capability> """<name|hostmask> <capability>
@ -569,21 +520,18 @@ class AdminCommands(callbacks.Privmsg):
<hostmask> currently maps) the specified capability <capability> <hostmask> currently maps) the specified capability <capability>
""" """
(name, capability) = getArgs(args, 2) (name, capability) = getArgs(args, 2)
if ircdb.checkCapability(msg.prefix, 'admin'): if ircdb.checkCapability(msg.prefix, capability) or \
if ircdb.checkCapability(msg.prefix, capability) or \ '!' in capability:
'!' in capability: try:
try: u = ircdb.users.getUser(name)
u = ircdb.users.getUser(name) u.addCapability(capability)
u.addCapability(capability) ircdb.users.setUser(name, u)
ircdb.users.setUser(name, u) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) except KeyError:
except KeyError: irc.error(msg, conf.replyNoUser)
irc.error(msg, conf.replyNoUser)
else:
s = 'You can\'t remove capabilities you don\'t have.'
irc.error(msg, s)
else: else:
irc.error(msg, conf.replyNoCapability % 'admin') s = 'You can\'t remove capabilities you don\'t have.'
irc.error(msg, s)
def setprefixchar(self, irc, msg, args): def setprefixchar(self, irc, msg, args):
"""<prefixchars> """<prefixchars>
@ -591,36 +539,29 @@ class AdminCommands(callbacks.Privmsg):
Sets the prefix chars by which the bot can be addressed. Sets the prefix chars by which the bot can be addressed.
""" """
s = getArgs(args) s = getArgs(args)
if ircdb.checkCapability(msg.prefix, 'admin'): if s.translate(string.ascii, string.ascii_letters) == '':
if s.translate(string.ascii, string.ascii_letters) == '': irc.error(msg, 'Prefixes cannot contain letters.')
irc.error(msg, 'Prefixes cannot contain letters.')
else:
conf.prefixChars = s
irc.reply(msg, conf.replySuccess)
else: else:
irc.error(msg, conf.replyNoCapability % 'admin') conf.prefixChars = s
irc.reply(msg, conf.replySuccess)
class OwnerCommands(callbacks.Privmsg): class OwnerCommands(CapabilityChecker):
capability = 'owner'
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
setattr(self.__class__, 'eval', self._eval)
#setattr(self.__class__, 'import', self._import)
setattr(self.__class__, 'exec', self._exec) setattr(self.__class__, 'exec', self._exec)
def _eval(self, irc, msg, args): def eval(self, irc, msg, args):
"""<string to be evaluated by the Python interpreter>""" """<string to be evaluated by the Python interpreter>"""
if ircdb.checkCapability(msg.prefix, 'owner'): if conf.allowEval:
if conf.allowEval: s = getArgs(args)
s = getArgs(args) try:
try: irc.reply(msg, repr(eval(s)))
irc.reply(msg, repr(eval(s))) except Exception, e:
except Exception, e: irc.reply(msg, debug.exnToString(e))
irc.reply(msg, debug.exnToString(e))
else:
irc.error(msg, conf.replyEvalNotAllowed)
else: else:
irc.error(msg, conf.replyNoCapability % 'owner') irc.error(msg, conf.replyEvalNotAllowed)
''' '''
def _import(self, irc, msg, args): def _import(self, irc, msg, args):
@ -642,42 +583,33 @@ class OwnerCommands(callbacks.Privmsg):
def _exec(self, irc, msg, args): def _exec(self, irc, msg, args):
"""<code to exec>""" """<code to exec>"""
if ircdb.checkCapability(msg.prefix, 'owner'): if conf.allowEval:
if conf.allowEval: s = getArgs(args)
s = getArgs(args) try:
try: exec s
exec s irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess) except Exception, e:
except Exception, e: irc.reply(msg, debug.exnToString(e))
irc.reply(msg, debug.exnToString(e))
else:
irc.error(msg, conf.replyEvalNotAllowed)
else: else:
irc.error(msg, conf.replyNoCapability % 'owner') irc.error(msg, conf.replyEvalNotAllowed)
def setdefaultcapability(self, irc, msg, args): def setdefaultcapability(self, irc, msg, args):
"""<capability> """<capability>
Sets the default capability to be allowed for any command. Sets the default capability to be allowed for any command.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): capability = getArgs(args)
capability = getArgs(args) conf.defaultCapabilities[capability] = True
conf.defaultCapabilities[capability] = True irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def unsetdefaultcapability(self, irc, msg, args): def unsetdefaultcapability(self, irc, msg, args):
"""<capability> """<capability>
Unsets the default capability for any command. Unsets the default capability for any command.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): capability = getArgs(args)
capability = getArgs(args) del conf.defaultCapabilities[capability]
del conf.defaultCapabilities[capability] irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def settrace(self, irc, msg, args): def settrace(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -685,66 +617,51 @@ class OwnerCommands(callbacks.Privmsg):
Starts the function-tracing debug mode; beware that this makes *huge* Starts the function-tracing debug mode; beware that this makes *huge*
logfiles. logfiles.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): sys.settrace(debug.tracer)
sys.settrace(debug.tracer) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def unsettrace(self, irc, msg, args): def unsettrace(self, irc, msg, args):
"""takes no arguments """takes no arguments
Stops the function-tracing debug mode.""" Stops the function-tracing debug mode."""
if ircdb.checkCapability(msg.prefix, 'owner'): sys.settrace(None)
sys.settrace(None) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def ircquote(self, irc, msg, args): def ircquote(self, irc, msg, args):
"""<string to be sent to the server> """<string to be sent to the server>
Sends the raw string given to the server. Sends the raw string given to the server.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): s = getArgs(args)
s = getArgs(args) try:
try: m = ircmsgs.IrcMsg(s)
m = ircmsgs.IrcMsg(s) irc.queueMsg(m)
irc.queueMsg(m) except Exception:
except Exception: debug.recoverableException()
debug.recoverableException() irc.error(msg, conf.replyError)
irc.error(msg, conf.replyError)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def quit(self, irc, msg, args): def quit(self, irc, msg, args):
"""[<int return value>] """[<int return value>]
Exits the program with the given return value (the default is 0) Exits the program with the given return value (the default is 0)
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): try:
try: i = int(args[0])
i = int(args[0]) except (ValueError, IndexError):
except (ValueError, IndexError): i = 0
i = 0 for driver in drivers._drivers.itervalues():
for driver in drivers._drivers.itervalues(): driver.die()
driver.die() for irc in world.ircs:
for irc in world.ircs: irc.die()
irc.die() debug.exit(i)
debug.exit(i)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def flush(self, irc, msg, args): def flush(self, irc, msg, args):
"""takes no arguments """takes no arguments
Runs all the periodic flushers in world.flushers. Runs all the periodic flushers in world.flushers.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): world.flush()
world.flush() irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
''' '''
def reload(self, irc, msg, args): def reload(self, irc, msg, args):
@ -759,7 +676,6 @@ class OwnerCommands(callbacks.Privmsg):
except Exception, e: except Exception, e:
m = '%s: %s' % (name, debug.exnToString(e)) m = '%s: %s' % (name, debug.exnToString(e))
irc.reply(msg, m) irc.reply(msg, m)
return
else: else:
try: try:
module = sys.modules[module] module = sys.modules[module]
@ -768,10 +684,8 @@ class OwnerCommands(callbacks.Privmsg):
return return
world.superReload(module) world.superReload(module)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyNoCapability % 'owner') irc.error(msg, conf.replyNoCapability % 'owner')
return
''' '''
def set(self, irc, msg, args): def set(self, irc, msg, args):
@ -781,52 +695,37 @@ class OwnerCommands(callbacks.Privmsg):
include "noflush" which, if set to true value, will prevent the include "noflush" which, if set to true value, will prevent the
periodic flushing that normally occurs. periodic flushing that normally occurs.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): (name, value) = getArgs(args, optional=1)
(name, value) = getArgs(args, optional=1) world.tempvars[name] = value
world.tempvars[name] = value irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
return
else:
irc.error(msg, conf.replyNoCapability % 'owner')
return
def unset(self, irc, msg, args): def unset(self, irc, msg, args):
"""<name> """<name>
Unsets the value of variables set via the 'set' command. Unsets the value of variables set via the 'set' command.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): name = getArgs(args)
name = getArgs(args) try:
try: del world.tempvars[name]
del world.tempvars[name]
except KeyError:
irc.error(msg, 'That variable wasn\'t set.')
return
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return except KeyError:
else: irc.error(msg, 'That variable wasn\'t set.')
irc.error(msg, conf.replyNoCapability % 'owner')
return
def load(self, irc, msg, args): def load(self, irc, msg, args):
"""<plugin> """<plugin>
Loads the plugin <plugin> from the plugins/ directory. Loads the plugin <plugin> from the plugins/ directory.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): plugin = getArgs(args)
plugin = getArgs(args) try:
try: moduleInfo = imp.find_module(plugin)
moduleInfo = imp.find_module(plugin) except ImportError:
except ImportError: irc.error(msg, 'Sorry, no plugin %s exists.' % plugin)
irc.error(msg, 'Sorry, no plugin %s exists.' % plugin)
return
module = imp.load_module(plugin, *moduleInfo)
callback = module.Class()
irc.addCallback(callback)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
return return
module = imp.load_module(plugin, *moduleInfo)
callback = module.Class()
irc.addCallback(callback)
irc.reply(msg, conf.replySuccess)
def unload(self, irc, msg, args): def unload(self, irc, msg, args):
"""<callback name> """<callback name>
@ -834,18 +733,15 @@ class OwnerCommands(callbacks.Privmsg):
Unloads the callback by name; use the 'list' command to see a list Unloads the callback by name; use the 'list' command to see a list
of the currently loaded callbacks. of the currently loaded callbacks.
""" """
if ircdb.checkCapability(msg.prefix, 'owner'): name = getArgs(args)
name = getArgs(args) numCallbacks = len(irc.callbacks)
numCallbacks = len(irc.callbacks) callbacks = irc.removeCallback(name)
callbacks = irc.removeCallback(name) for callback in callbacks:
for callback in callbacks: callback.die()
callback.die() if len(irc.callbacks) < numCallbacks:
if len(irc.callbacks) < numCallbacks: irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, 'There was no callback %s' % name)
else: else:
irc.error(msg, conf.replyNoCapability % 'owner') irc.error(msg, 'There was no callback %s' % name)
class UserCommands(callbacks.Privmsg): class UserCommands(callbacks.Privmsg):
@ -972,10 +868,9 @@ class UserCommands(callbacks.Privmsg):
name = getArgs(args) name = getArgs(args)
try: try:
user = ircdb.users.getUser(name) user = ircdb.users.getUser(name)
irc.reply(msg, repr(user.hostmasks))
except KeyError: except KeyError:
irc.error(msg, conf.replyNoUser) irc.error(msg, conf.replyNoUser)
return
irc.reply(msg, repr(user.hostmasks))
def capabilities(self, irc, msg, args): def capabilities(self, irc, msg, args):
"""[<name>] """[<name>]
@ -993,10 +888,9 @@ class UserCommands(callbacks.Privmsg):
name = getArgs(args) name = getArgs(args)
try: try:
user = ircdb.users.getUser(name) user = ircdb.users.getUser(name)
irc.reply(msg, '[%s]' % ', '.join(user.capabilities))
except KeyError: except KeyError:
irc.error(msg, conf.replyNoUser) irc.error(msg, conf.replyNoUser)
return
irc.reply(msg, '[%s]' % ', '.join(user.capabilities))
def identify(self, irc, msg, args): def identify(self, irc, msg, args):
"""<name> <password> """<name> <password>
@ -1014,10 +908,8 @@ class UserCommands(callbacks.Privmsg):
u.setAuth(msg.prefix) u.setAuth(msg.prefix)
ircdb.users.setUser(name, u) ircdb.users.setUser(name, u)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
return
else: else:
irc.error(msg, conf.replyIncorrectAuth) irc.error(msg, conf.replyIncorrectAuth)
return
def unidentify(self, irc, msg, args): def unidentify(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -1169,4 +1061,5 @@ standardPrivmsgModules = (OwnerCommands,
ChannelCommands, ChannelCommands,
UserCommands, UserCommands,
MiscCommands) MiscCommands)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: