]> jfr.im git - erebus.git/blobdiff - modules/userinfo.py
userinfo - add function/command to delete
[erebus.git] / modules / userinfo.py
index be6e33be11b2b0810f97d626084c82f86752bf2c..d907b088ff5209e40e02bbdf74876f8dd324b228 100644 (file)
@@ -6,7 +6,7 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1,2],
+       'compatible': [2],
        'depends': [],
        'softdeps': ['help'],
 }
@@ -44,7 +44,7 @@ def getauth(thing):
                if thing.auth is not None:
                        return "#"+thing.auth
        elif isinstance(thing, basestring):
-               if thing[0] == "#":
+               if thing.startswith("#"):
                        return thing
                else:
                        if parent.user(thing).auth is not None:
@@ -54,11 +54,13 @@ def getauth(thing):
 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
 def _has(user, key):
+       key = key.lower()
        return (
                key in db.get(getauth(user), {}) or
                key in db.get(str(user).lower(), {})
        )
 def _get(user, key, default=None):
+       key = key.lower()
        return (
                db.get(getauth(user), {}). #try to get the auth
                        get(key, #try to get the info-key by auth
@@ -67,15 +69,24 @@ def _get(user, key, default=None):
                                default #otherwise throw out whatever default
        )))
 def _set(user, key, value):
+       key = key.lower()
        if getauth(user) is not None:
                db.setdefault(getauth(user), {})[key] = value #use auth if we can
        db.setdefault(str(user).lower(), {})[key] = value #but set nick too
+def _del(user, key):
+       key = key.lower()
+       auth = getauth(user)
+       if auth is not None and auth in db and key in db[auth]:
+               del db[auth][key]
+       target = str(user).lower()
+       if target in db and key in db[target]:
+               del db[target][key]
 
 #commands
-@lib.hook(needchan=False)
+@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 and realtarget == chan.name: replyto = chan
+       if chan is not None: replyto = chan
        else: replyto = user
 
        if len(args) > 0:
@@ -85,11 +96,11 @@ def getitems(bot, user, chan, realtarget, *args):
 
        bot.msg(replyto, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(_keys(target)))})
 
-@lib.hook(needchan=False)
+@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 and realtarget == chan.name: replyto = chan
+       if chan is not None: replyto = chan
        else: replyto = user
 
        if len(args) > 1:
@@ -113,10 +124,26 @@ def setinfo(bot, user, chan, realtarget, *args):
        closeshop()
        bot.msg(user, "Done.")
 
-@lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.hook(needchan=False)
+@lib.help("<item>", "deletes an info item about you")
+@lib.argsEQ(1)
+def delinfo(bot, user, chan, realtarget, *args):
+       _del(user, args[0])
+       closeshop()
+       bot.msg(user, "Done.")
+
+@lib.hook(glevel=lib.ADMIN, needchan=False)
 @lib.help("<target> <item> <value>", "sets an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
 @lib.argsGE(3)
 def osetinfo(bot, user, chan, realtarget, *args):
        _set(args[0], args[1], ' '.join(args[2:]))
        closeshop()
        bot.msg(user, "Done.")
+
+@lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<target> <item>", "deletes an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
+@lib.argsEQ(2)
+def odelinfo(bot, user, chan, realtarget, *args):
+       _del(args[0], args[1])
+       closeshop()
+       bot.msg(user, "Done.")