mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Updated some stuff, refactoring for the the User.config command.
This commit is contained in:
parent
1ed71e9181
commit
f9c030fe46
@ -57,10 +57,9 @@ class InvalidRegistryName(callbacks.Error):
|
||||
|
||||
def getWrapper(name):
|
||||
parts = name.split('.')
|
||||
if not parts or parts[0] != 'supybot':
|
||||
if not parts or parts[0] not in ('supybot', 'users'):
|
||||
raise InvalidRegistryName, name
|
||||
group = conf.supybot
|
||||
parts.pop(0)
|
||||
group = getattr(conf, parts.pop(0))
|
||||
while parts:
|
||||
try:
|
||||
group = group.get(parts.pop(0))
|
||||
@ -91,10 +90,28 @@ class Config(callbacks.Privmsg):
|
||||
irc.error(str(e))
|
||||
|
||||
def _canonicalizeName(self, name):
|
||||
if not name.startswith('supybot'):
|
||||
if not name.startswith('supybot') and not name.startswith('users'):
|
||||
name = 'supybot.' + name
|
||||
return name
|
||||
|
||||
def _list(self, name, groups=False):
|
||||
name = self._canonicalizeName(name)
|
||||
group = getWrapper(name)
|
||||
if groups:
|
||||
L = []
|
||||
for (vname, v) in group.children.iteritems():
|
||||
if v.added:
|
||||
L.append(vname)
|
||||
utils.sortBy(str.lower, L)
|
||||
return L
|
||||
else:
|
||||
try:
|
||||
L = zip(*group.getValues(fullNames=False))[0]
|
||||
utils.sortBy(str.lower, L)
|
||||
return L
|
||||
except TypeError:
|
||||
return []
|
||||
|
||||
def list(self, irc, msg, args):
|
||||
"""[--groups] <group>
|
||||
|
||||
@ -108,23 +125,12 @@ class Config(callbacks.Privmsg):
|
||||
if name == '--groups':
|
||||
groups = True
|
||||
name = privmsgs.getArgs(rest)
|
||||
name = self._canonicalizeName(name)
|
||||
group = getWrapper(name)
|
||||
if groups:
|
||||
L = []
|
||||
for (vname, v) in group.children.iteritems():
|
||||
if v.added:
|
||||
L.append(vname)
|
||||
L = self._list(name, groups)
|
||||
if L:
|
||||
utils.sortBy(str.lower, L)
|
||||
irc.reply(utils.commaAndify(L))
|
||||
else:
|
||||
elif groups:
|
||||
irc.reply('%s has no subgroups.' % name)
|
||||
else:
|
||||
try:
|
||||
L = zip(*group.getValues(fullNames=False))[0]
|
||||
irc.reply(utils.commaAndify(L))
|
||||
except TypeError:
|
||||
irc.error('There don\'t seem to be any values in %s' % name)
|
||||
|
||||
def search(self, irc, msg, args):
|
||||
|
37
src/User.py
37
src/User.py
@ -51,6 +51,8 @@ import ircutils
|
||||
import privmsgs
|
||||
import callbacks
|
||||
|
||||
import Config
|
||||
|
||||
class User(callbacks.Privmsg):
|
||||
def _checkNotChannel(self, irc, msg, password=' '):
|
||||
if password and ircutils.isChannel(msg.args[0]):
|
||||
@ -456,6 +458,41 @@ class User(callbacks.Privmsg):
|
||||
else:
|
||||
irc.error(conf.supybot.replies.incorrectAuthentication())
|
||||
|
||||
def config(self, irc, msg, args):
|
||||
"""[--list] <name> [<value>]
|
||||
|
||||
Sets the user configuration variable <name> to <value>, if given. If
|
||||
<value> is not given, returns the current value of <name> for the user
|
||||
giving the command. If --list is given, lists the values in <name>.
|
||||
"""
|
||||
try:
|
||||
id = ircdb.users.getUserId(msg.prefix)
|
||||
except KeyError:
|
||||
irc.errorNoUser()
|
||||
return
|
||||
list = False
|
||||
while '--list' in args:
|
||||
# XXX: Case-sensitive.
|
||||
list = True
|
||||
args.remove('--list')
|
||||
if len(args) >= 2:
|
||||
# We're setting.
|
||||
pass
|
||||
else:
|
||||
# We're getting.
|
||||
name = privmsgs.getArgs(args)
|
||||
if not name.startswith('users.'):
|
||||
name = 'users.' + name
|
||||
try:
|
||||
wrapper = Config.getWrapper(name)
|
||||
wrapper = wrapper.get(str(id))
|
||||
except InvalidRegistryValue, e:
|
||||
irc.error('%r is not a valid configuration variable.' % name)
|
||||
return
|
||||
if list:
|
||||
pass
|
||||
else:
|
||||
irc.reply(str(wrapper))
|
||||
|
||||
Class = User
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user