mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Made defaultplugin use the registry.
This commit is contained in:
parent
977d7a2279
commit
b94a7a3b4e
@ -223,15 +223,24 @@ if __name__ == '__main__':
|
|||||||
registry.open(registryFilename)
|
registry.open(registryFilename)
|
||||||
except registry.InvalidRegistryFile, e:
|
except registry.InvalidRegistryFile, e:
|
||||||
sys.stderr.write(str(e))
|
sys.stderr.write(str(e))
|
||||||
sys.stderr.write('\n')
|
sys.stderr.write(os.linesep)
|
||||||
|
sys.exit(-1)
|
||||||
|
except EnvironmentError, e:
|
||||||
|
sys.stderr.write(str(e))
|
||||||
|
sys.stderr.write(os.linesep)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
import log
|
import log
|
||||||
import conf
|
import conf
|
||||||
|
import world
|
||||||
|
|
||||||
def closeRegistry():
|
def closeRegistry():
|
||||||
|
# We only print if world.dying so we don't see these messages during
|
||||||
|
# upkeep.
|
||||||
|
if world.dying:
|
||||||
log.info('Writing registry file to %s', registryFilename)
|
log.info('Writing registry file to %s', registryFilename)
|
||||||
registry.close(conf.supybot, registryFilename, annotated=True)
|
registry.close(conf.supybot, registryFilename, annotated=True)
|
||||||
|
if world.dying:
|
||||||
log.info('Finished writing registry file.')
|
log.info('Finished writing registry file.')
|
||||||
world.flushers.append(closeRegistry)
|
world.flushers.append(closeRegistry)
|
||||||
|
|
||||||
|
@ -653,7 +653,7 @@ def main():
|
|||||||
# Done!
|
# Done!
|
||||||
output("""All done! Your new bot configuration is %s. If you're running
|
output("""All done! Your new bot configuration is %s. If you're running
|
||||||
a *nix based OS, you can probably start your bot with the command line
|
a *nix based OS, you can probably start your bot with the command line
|
||||||
"supybot ./%s". If you're not running a *nix or similar machine, you'll
|
"supybot %s". If you're not running a *nix or similar machine, you'll
|
||||||
just have to start it like you start all your other Python scripts.""" % \
|
just have to start it like you start all your other Python scripts.""" % \
|
||||||
(filename, filename))
|
(filename, filename))
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ def getWrapper(name):
|
|||||||
parts.pop(0)
|
parts.pop(0)
|
||||||
while parts:
|
while parts:
|
||||||
try:
|
try:
|
||||||
group = getattr(group, parts.pop(0))
|
group = group.get(parts.pop(0))
|
||||||
except registry.NonExistentRegistryEntry:
|
except registry.NonExistentRegistryEntry:
|
||||||
raise InvalidRegistryName, name
|
raise InvalidRegistryName, name
|
||||||
return group
|
return group
|
||||||
@ -144,15 +144,18 @@ class Config(callbacks.Privmsg):
|
|||||||
wrapper = getWrapper(name)
|
wrapper = getWrapper(name)
|
||||||
irc.reply(wrapper.default)
|
irc.reply(wrapper.default)
|
||||||
|
|
||||||
def flush(self, irc, msg, args):
|
def reload(self, irc, msg, args):
|
||||||
"""<filename>
|
"""takes no arguments
|
||||||
|
|
||||||
Flushes the current registry to the file given.
|
Reloads the various configuration files (user database, channel
|
||||||
|
database, registry, etc.).
|
||||||
"""
|
"""
|
||||||
filename = privmsgs.getArgs(args)
|
# TODO: Reload registry.
|
||||||
registry.close(conf.supybot, filename)
|
ircdb.users.reload()
|
||||||
|
ircdb.channels.reload()
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
flush = privmsgs.checkCapability(flush, 'owner')
|
reload = privmsgs.checkCapability(reload, 'owner')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = Config
|
Class = Config
|
||||||
|
79
src/Owner.py
79
src/Owner.py
@ -94,6 +94,24 @@ def loadPluginClass(irc, module):
|
|||||||
assert not irc.getCallback(callback.name())
|
assert not irc.getCallback(callback.name())
|
||||||
irc.addCallback(callback)
|
irc.addCallback(callback)
|
||||||
|
|
||||||
|
conf.registerGroup(conf.supybot, 'commands')
|
||||||
|
conf.registerGroup(conf.supybot.commands, 'defaultPlugins',
|
||||||
|
registry.GroupWithDefault(registry.String('', """
|
||||||
|
Determines what commands have default plugins set, and which
|
||||||
|
plugins are set to be the default for each of those
|
||||||
|
commands.""")))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'list', registry.String('Misc', ''))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'help', registry.String('Misc', ''))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'capabilities', registry.String('User', ''))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'addcapability', registry.String('Admin', ''))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'removecapability', registry.String('Admin', ''))
|
||||||
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
||||||
|
'reload', registry.String('Misc', ''))
|
||||||
|
|
||||||
class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
||||||
# This plugin must be first; its priority must be lowest; otherwise odd
|
# This plugin must be first; its priority must be lowest; otherwise odd
|
||||||
@ -104,11 +122,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
setattr(self.__class__, 'exec', self.__class__._exec)
|
setattr(self.__class__, 'exec', self.__class__._exec)
|
||||||
self.defaultPlugins = {'list': 'Misc',
|
|
||||||
'help': 'Misc',
|
|
||||||
'capabilities': 'User',
|
|
||||||
'addcapability': 'Admin',
|
|
||||||
'removecapability': 'Admin',}
|
|
||||||
for (name, s) in registry._cache.iteritems():
|
for (name, s) in registry._cache.iteritems():
|
||||||
if name.startswith('supybot.plugins'):
|
if name.startswith('supybot.plugins'):
|
||||||
try:
|
try:
|
||||||
@ -142,9 +155,13 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
ambiguousCommands = {}
|
ambiguousCommands = {}
|
||||||
if tokens:
|
if tokens:
|
||||||
command = callbacks.canonicalName(tokens[0])
|
command = callbacks.canonicalName(tokens[0])
|
||||||
if command in self.defaultPlugins:
|
try:
|
||||||
tokens.insert(0, self.defaultPlugins[command])
|
plugin = conf.supybot.commands.defaultPlugins.get(command)()
|
||||||
|
if plugin:
|
||||||
|
tokens.insert(0, plugin)
|
||||||
else:
|
else:
|
||||||
|
raise registry.NonExistentRegistryEntry
|
||||||
|
except registry.NonExistentRegistryEntry:
|
||||||
cbs = callbacks.findCallbackForCommand(irc, command)
|
cbs = callbacks.findCallbackForCommand(irc, command)
|
||||||
if len(cbs) > 1:
|
if len(cbs) > 1:
|
||||||
names = [cb.name() for cb in cbs]
|
names = [cb.name() for cb in cbs]
|
||||||
@ -200,44 +217,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
else:
|
else:
|
||||||
callbacks.IrcObjectProxy(irc, msg, tokens)
|
callbacks.IrcObjectProxy(irc, msg, tokens)
|
||||||
|
|
||||||
def defaultplugin(self, irc, msg, args):
|
|
||||||
"""<command> [<plugin>] [--remove]
|
|
||||||
|
|
||||||
Calls <command> from <plugin> by default, rather than complaining about
|
|
||||||
multiple plugins providing it. If <plugin> is not provided, shows the
|
|
||||||
current default plugin for <command>. If --remove is given, removes
|
|
||||||
the current default plugin for <command>.
|
|
||||||
"""
|
|
||||||
if '--remove' in args:
|
|
||||||
while '--remove' in args:
|
|
||||||
args.remove('--remove')
|
|
||||||
remove = True
|
|
||||||
else:
|
|
||||||
remove = False
|
|
||||||
(command, plugin) = privmsgs.getArgs(args, optional=1)
|
|
||||||
command = callbacks.canonicalName(command)
|
|
||||||
cbs = callbacks.findCallbackForCommand(irc, command)
|
|
||||||
if not cbs:
|
|
||||||
irc.error('That\'t not a valid command.')
|
|
||||||
return
|
|
||||||
if plugin:
|
|
||||||
self.defaultPlugins[command] = plugin
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
if remove:
|
|
||||||
del self.defaultPlugins[command]
|
|
||||||
else:
|
|
||||||
L = [command]
|
|
||||||
d = self.disambiguate(irc, L)
|
|
||||||
if d:
|
|
||||||
raise KeyError
|
|
||||||
assert len(L) == 2, 'Not disambiguated!'
|
|
||||||
irc.reply(L[0])
|
|
||||||
except KeyError:
|
|
||||||
irc.error('I have no default plugin for that command.')
|
|
||||||
return
|
|
||||||
irc.replySuccess()
|
|
||||||
|
|
||||||
if conf.allowEval:
|
if conf.allowEval:
|
||||||
def eval(self, irc, msg, args):
|
def eval(self, irc, msg, args):
|
||||||
"""<expression>
|
"""<expression>
|
||||||
@ -402,16 +381,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error('There was no callback %s' % name)
|
irc.error('There was no callback %s' % name)
|
||||||
|
|
||||||
def reconf(self, irc, msg, args):
|
|
||||||
"""takes no arguments
|
|
||||||
|
|
||||||
Reloads the configuration files for the user and channel databases:
|
|
||||||
conf/users.conf and conf/channels.conf, by default.
|
|
||||||
"""
|
|
||||||
ircdb.users.reload()
|
|
||||||
ircdb.channels.reload()
|
|
||||||
irc.replySuccess()
|
|
||||||
|
|
||||||
|
|
||||||
Class = Owner
|
Class = Owner
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ def registerChannelValue(group, name, value):
|
|||||||
def registerGlobalValue(group, name, value):
|
def registerGlobalValue(group, name, value):
|
||||||
group.register(name, value)
|
group.register(name, value)
|
||||||
|
|
||||||
def registerGroup(group, name):
|
def registerGroup(group, name, Group=None):
|
||||||
group.registerGroup(name)
|
group.registerGroup(name, Group)
|
||||||
|
|
||||||
class ValidNick(registry.String):
|
class ValidNick(registry.String):
|
||||||
def setValue(self, v):
|
def setValue(self, v):
|
||||||
|
@ -123,7 +123,6 @@ class Value(object):
|
|||||||
# the _cache.
|
# the _cache.
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
|
||||||
class Boolean(Value):
|
class Boolean(Value):
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
s = s.lower()
|
s = s.lower()
|
||||||
|
Loading…
Reference in New Issue
Block a user