mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 12:12:54 +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):
|
def getWrapper(name):
|
||||||
parts = name.split('.')
|
parts = name.split('.')
|
||||||
if not parts or parts[0] != 'supybot':
|
if not parts or parts[0] not in ('supybot', 'users'):
|
||||||
raise InvalidRegistryName, name
|
raise InvalidRegistryName, name
|
||||||
group = conf.supybot
|
group = getattr(conf, parts.pop(0))
|
||||||
parts.pop(0)
|
|
||||||
while parts:
|
while parts:
|
||||||
try:
|
try:
|
||||||
group = group.get(parts.pop(0))
|
group = group.get(parts.pop(0))
|
||||||
@ -91,10 +90,28 @@ class Config(callbacks.Privmsg):
|
|||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
|
||||||
def _canonicalizeName(self, name):
|
def _canonicalizeName(self, name):
|
||||||
if not name.startswith('supybot'):
|
if not name.startswith('supybot') and not name.startswith('users'):
|
||||||
name = 'supybot.' + name
|
name = 'supybot.' + name
|
||||||
return 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):
|
def list(self, irc, msg, args):
|
||||||
"""[--groups] <group>
|
"""[--groups] <group>
|
||||||
|
|
||||||
@ -108,24 +125,13 @@ class Config(callbacks.Privmsg):
|
|||||||
if name == '--groups':
|
if name == '--groups':
|
||||||
groups = True
|
groups = True
|
||||||
name = privmsgs.getArgs(rest)
|
name = privmsgs.getArgs(rest)
|
||||||
name = self._canonicalizeName(name)
|
L = self._list(name, groups)
|
||||||
group = getWrapper(name)
|
if L:
|
||||||
if groups:
|
irc.reply(utils.commaAndify(L))
|
||||||
L = []
|
elif groups:
|
||||||
for (vname, v) in group.children.iteritems():
|
irc.reply('%s has no subgroups.' % name)
|
||||||
if v.added:
|
|
||||||
L.append(vname)
|
|
||||||
if L:
|
|
||||||
utils.sortBy(str.lower, L)
|
|
||||||
irc.reply(utils.commaAndify(L))
|
|
||||||
else:
|
|
||||||
irc.reply('%s has no subgroups.' % name)
|
|
||||||
else:
|
else:
|
||||||
try:
|
irc.error('There don\'t seem to be any values in %s' % name)
|
||||||
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):
|
def search(self, irc, msg, args):
|
||||||
"""<word>
|
"""<word>
|
||||||
|
37
src/User.py
37
src/User.py
@ -51,6 +51,8 @@ import ircutils
|
|||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
|
import Config
|
||||||
|
|
||||||
class User(callbacks.Privmsg):
|
class User(callbacks.Privmsg):
|
||||||
def _checkNotChannel(self, irc, msg, password=' '):
|
def _checkNotChannel(self, irc, msg, password=' '):
|
||||||
if password and ircutils.isChannel(msg.args[0]):
|
if password and ircutils.isChannel(msg.args[0]):
|
||||||
@ -456,6 +458,41 @@ class User(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error(conf.supybot.replies.incorrectAuthentication())
|
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
|
Class = User
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user