Move user metadata info into redis
parent
b31b5d40e8
commit
36105c7e9a
@ -1,31 +1,131 @@
|
|||||||
import main
|
import main
|
||||||
from string import digits
|
from string import digits
|
||||||
#from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
|
||||||
def setWho(network, newObjects):
|
def getWhoSingle(name, query):
|
||||||
if not network in main.wholist.keys():
|
result = main.r.sscan("live.who."+name, 0, query)
|
||||||
main.wholist[network] = {}
|
if result[1] == []:
|
||||||
for i in newObjects.keys():
|
return None
|
||||||
main.wholist[network][i] = newObjects[i]
|
return [i.decode() for i in result[1]]
|
||||||
|
|
||||||
return
|
def getWho(query):
|
||||||
|
result = {}
|
||||||
|
for i in main.pool.keys():
|
||||||
|
f = getWhoSingle(i, query)
|
||||||
|
if f:
|
||||||
|
result[i] = f
|
||||||
|
print(result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def getNumWhoEntries(name):
|
||||||
|
return main.r.scard("live.who."+name)
|
||||||
|
|
||||||
|
def getNumTotalWhoEntries():
|
||||||
|
total = 0
|
||||||
|
for i in main.pool.keys():
|
||||||
|
total += getNumWhoEntries(i)
|
||||||
|
return total
|
||||||
|
|
||||||
|
def getNamespace(name, channel, nick):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
namespace = "live.who.%s.%s" % (name, channel)
|
||||||
|
chanspace = "live.chan.%s.%s" % (name, nick)
|
||||||
|
return [gnamespace, namespace, chanspace]
|
||||||
|
|
||||||
|
def initialUsers(name, channel, users):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
p = main.r.pipeline()
|
||||||
|
for i in users:
|
||||||
|
p.sadd(gnamespace, i[0]+"!"+i[1]+"@"+i[2])
|
||||||
|
p.execute()
|
||||||
|
|
||||||
|
def initialNames(name, channel, names):
|
||||||
|
namespace = "live.who.%s.%s" % (name, channel)
|
||||||
|
p = main.r.pipeline()
|
||||||
|
for i in names:
|
||||||
|
p.sadd(namespace, i)
|
||||||
|
p.sadd("live.chan."+name+"."+i, channel)
|
||||||
|
p.execute()
|
||||||
|
|
||||||
|
def editUser(name, channel, nick, user):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
main.r.sadd(gnamespace, user)
|
||||||
|
|
||||||
|
def addUser(name, channel, nick, user):
|
||||||
|
gnamespace, namespace, chanspace = getNamespace(name, channel, nick)
|
||||||
|
p = main.r.pipeline()
|
||||||
|
p.sadd(gnamespace, user)
|
||||||
|
p.sadd(namespace, nick)
|
||||||
|
p.sadd(chanspace, channel)
|
||||||
|
p.execute()
|
||||||
|
|
||||||
def setWhoSingle(network, nick, ident, host):
|
def delUser(name, channel, nick, user):
|
||||||
if network in main.wholist.keys():
|
gnamespace, namespace, chanspace = getNamespace(name, channel, nick)
|
||||||
if nick in main.wholist[network].keys():
|
p = main.r.pipeline()
|
||||||
main.wholist[network][nick][1] = ident
|
channels = main.r.smembers(chanspace)
|
||||||
main.wholist[network][nick][2] = host
|
p.srem(namespace, nick)
|
||||||
|
if channels == {channel.encode()}:
|
||||||
|
p.delete(chanspace)
|
||||||
|
p.srem(gnamespace, user)
|
||||||
|
else:
|
||||||
|
p.srem(chanspace, channel)
|
||||||
|
p.execute()
|
||||||
|
|
||||||
|
def getUserByNick(name, nick):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
usermatch = main.r.sscan(gnamespace, match=nick+"!*")
|
||||||
|
if usermatch[1] == []:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if len(usermatch[1]) == 1:
|
||||||
|
user = usermatch[1][0]
|
||||||
|
return user
|
||||||
else:
|
else:
|
||||||
main.wholist[network][nick] = [nick, ident, host, None, None, None]
|
return False
|
||||||
|
|
||||||
|
def renameUser(name, oldnick, olduser, newnick, newuser):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
chanspace = "live.chan.%s.%s" % (name, oldnick)
|
||||||
|
newchanspace = "live.chan.%s.%s" % (name, newnick)
|
||||||
|
p = main.r.pipeline()
|
||||||
|
p.srem(gnamespace, olduser)
|
||||||
|
p.sadd(gnamespace, newuser)
|
||||||
|
for i in main.r.smembers(chanspace):
|
||||||
|
i = i.decode()
|
||||||
|
p.srem("live.who."+name+"."+i, oldnick)
|
||||||
|
p.sadd("live.who."+name+"."+i, newnick)
|
||||||
|
if main.r.exists(chanspace):
|
||||||
|
p.rename(chanspace, newchanspace)
|
||||||
else:
|
else:
|
||||||
main.wholist[network] = {nick: [nick, ident, host, None, None, None]}
|
warn("Key doesn't exist: %s" % chanspace)
|
||||||
|
p.execute()
|
||||||
|
|
||||||
def getWho(nick):
|
def delUserByNick(name, channel, nick):
|
||||||
result = {}
|
gnamespace = "live.who.%s" % name
|
||||||
for i in main.wholist.keys():
|
user = getUserByNick(name, nick)
|
||||||
for x in main.wholist[i].keys():
|
delUser(name, channel, nick, user)
|
||||||
if nick.lower() == x.lower():
|
|
||||||
if not i in result.keys():
|
def delUserByNetwork(name, nick, user):
|
||||||
result[i] = []
|
gnamespace = "live.who.%s" % name
|
||||||
result[i].append(main.wholist[i][x])
|
chanspace = "live.chan.%s.%s" % (name, nick)
|
||||||
return result
|
p = main.r.pipeline()
|
||||||
|
p.srem(gnamespace, user)
|
||||||
|
for i in main.r.smembers(chanspace):
|
||||||
|
p.srem("live.who."+name+"."+i.decode(), nick)
|
||||||
|
p.delete(chanspace)
|
||||||
|
p.execute()
|
||||||
|
|
||||||
|
def delChannel(name, channel):
|
||||||
|
gnamespace = "live.who.%s" % name
|
||||||
|
namespace = "live.who.%s.%s" % (name, channel)
|
||||||
|
p = main.r.pipeline()
|
||||||
|
for i in main.r.smembers(namespace):
|
||||||
|
user = getUserByNick(name, i.decode())
|
||||||
|
if main.r.smembers("live.chan."+name+"."+i.decode()) == {channel.encode()}:
|
||||||
|
if user:
|
||||||
|
p.srem(gnamespace, user)
|
||||||
|
p.delete("live.chan."+name+"."+i.decode())
|
||||||
|
else:
|
||||||
|
p.srem("live.chan."+name+"."+i.decode(), channel)
|
||||||
|
p.delete(namespace)
|
||||||
|
p.execute()
|
||||||
|
Loading…
Reference in New Issue