Reimplemented set to be more general.

This commit is contained in:
Jeremy Fincher 2004-04-30 19:21:02 +00:00
parent 6b3ed89e17
commit d82c694a05

View File

@ -46,13 +46,11 @@ import registry
import callbacks import callbacks
conf.registerPlugin('UserInfo') conf.registerPlugin('UserInfo')
conf.registerUserValue(conf.users.plugins.UserInfo, 'name', conf.registerUserValue(conf.users, 'name',
registry.String('', '')) registry.String('', ''))
conf.registerUserValue(conf.users.plugins.UserInfo, 'email', conf.registerUserValue(conf.users, 'email',
registry.String('', '')) registry.String('', ''))
conf.registerUserValue(conf.users.plugins.UserInfo, 'pgpkey', conf.registerUserValue(conf.users, 'pgpkey',
registry.String('', ''))
conf.registerUserValue(conf.users.plugins.UserInfo, 'gpgkey',
registry.String('', '')) registry.String('', ''))
def configure(advanced): def configure(advanced):
@ -76,28 +74,35 @@ class UserInfo(callbacks.Privmsg):
if not name: if not name:
name = msg.prefix name = msg.prefix
try: try:
ircdb.users.getUser(name) id = ircdb.users.getUserId(name)
except KeyError: except KeyError:
irc.errorNoUser() irc.errorNoUser()
return return
L = [] L = []
for s in ('name', 'email', 'pgpkey', 'gpgkey'): end = '.%s' % id
v = self.userValue(s, name) for name, wrapper in conf.users.getValues(getChildren=True):
if v: if name.endswith(end):
L.append('%s: %s' % (s.capitalize(), v)) L.append('%s: %s' % ('.'.join(name.split('.')[1:-1]), wrapper))
if L: if L:
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
else: else:
irc.reply('I don\'t have any info on that user.') irc.reply('I don\'t have any info on that user.')
def set(self, irc, msg, args): def set(self, irc, msg, args):
"""<name|email|pgpkey> <value> """<name> <value>
Sets the name, email, or pgpkey of <name> to <value>. Sets some arbitrary data for the user giving the command. Some good
things to set are 'name', 'email', and 'pgpkey'. Other names will
depend on the plugins to which they belong.
""" """
(name, value) = privmsgs.getArgs(args, required=2) (name, value) = privmsgs.getArgs(args, required=2)
try: try:
self.setUserValue(msg.prefix, name, value) id = str(ircdb.users.getUserId(msg.prefix))
group = conf.users
for name in name.split('.'):
group = group.get(name)
group = group.get(id)
group.set(value)
irc.replySuccess() irc.replySuccess()
except KeyError: except KeyError:
irc.errorNoUser() irc.errorNoUser()
@ -107,6 +112,7 @@ class UserInfo(callbacks.Privmsg):
except registry.InvalidRegistryValue, e: except registry.InvalidRegistryValue, e:
irc.error(str(e)) irc.error(str(e))
Class = UserInfo Class = UserInfo
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: