]> jfr.im git - erebus.git/blobdiff - modules/userinfo.py
trivia add todo
[erebus.git] / modules / userinfo.py
index 65580f8690fa671b9dfaa08a85387e39a4f44d7e..9604b8b1d11cd0e2267128ee52867033acaca6a8 100644 (file)
@@ -25,7 +25,13 @@ def modstop(*args, **kwargs):
        return lib.modstop(*args, **kwargs)
 
 # module code
-import json
+import json, sys
+if sys.version_info.major >= 3:
+       import builtins as __builtin__
+       stringbase = str
+else:
+       import __builtin__
+       stringbase = basestring
 
 #setup
 def gotParent():
@@ -44,7 +50,7 @@ def _getauth(thing):
        if isinstance(thing, parent.User):
                if thing.auth is not None:
                        return "#"+thing.auth
-       elif isinstance(thing, basestring):
+       elif isinstance(thing, stringbase):
                if thing.startswith("#"):
                        return thing
                else:
@@ -54,7 +60,7 @@ def _getauth(thing):
        return None
 
 def keys(user):
-       return list(set(db.get(_getauth(user), {}).keys() + db.get(str(user).lower(), {}).keys())) #list-to-set-to-list to remove duplicates
+       return list(__builtin__.set(list(db.get(_getauth(user), {}).keys()) + list(db.get(str(user).lower(), {}).keys()))) #list-to-set-to-list to remove duplicates
 def has(user, key):
        key = key.lower()
        return (
@@ -88,23 +94,17 @@ def delete(user, key):
 @lib.hook(needchan=False, wantchan=True)
 @lib.help("[<target>]", "lists info items known about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
 def getitems(bot, user, chan, realtarget, *args):
-       if chan is not None: replyto = chan
-       else: replyto = user
-
        if len(args) > 0:
                target = args[0]
        else:
                target = user
 
-       bot.msg(replyto, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(keys(target)))})
+       return "%(target)s has the following info items: %(items)s" % {'target':target,'items':(', '.join(keys(target)))}
 
 @lib.hook(needchan=False, wantchan=True)
 @lib.help("[<target>] <item>", "gets an info item about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
 @lib.argsGE(1)
 def getinfo(bot, user, chan, realtarget, *args):
-       if chan is not None: replyto = chan
-       else: replyto = user
-
        if len(args) > 1:
                target = args[0]
                item = args[1]
@@ -114,9 +114,9 @@ def getinfo(bot, user, chan, realtarget, *args):
 
        value = get(target, item, None)
        if value is None:
-               bot.msg(replyto, "%(user)s: %(item)s on %(target)s is not set." % {'user':user,'item':item,'target':target})
+               return "%(item)s on %(target)s is not set." % {'item':item,'target':target}
        else:
-               bot.msg(replyto, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value})
+               return "%(item)s on %(target)s: %(value)s" % {'item':item,'target':target,'value':value}
 
 @lib.hook(needchan=False)
 @lib.help("<item> <value>", "sets an info item about you")