Start implementing prefixes

This commit is contained in:
Mark Veidemanis 2020-07-09 19:43:47 +01:00
parent 3acf182171
commit 82c5c2d163
3 changed files with 31 additions and 15 deletions

View File

@ -156,6 +156,7 @@ class IRCBot(IRCClient):
# syntax from now on
self.wantList = False # we want to send a LIST, but not all relays are active yet
self.chanlimit = 0
self.prefix = {}
self.servername = None
self._regAttempt = None
@ -376,12 +377,11 @@ class IRCBot(IRCClient):
def sanit(self, data):
if len(data) >= 1:
if data[0] in ["!", "~", "&", "@", "%", "+"]:
data = data[1:]
return data
return data
if data[0] in self.prefix.keys():
return (self.prefix[data[0]], data[1:]) # would use a set but it's possible these are the same
return (None, data)
else:
return False
return (None, False)
def names(self, channel):
d = Deferred()
@ -412,9 +412,9 @@ class IRCBot(IRCClient):
newNicklist = []
for i in nicklist[1]:
for x in i:
f = self.sanit(x)
if f:
newNicklist.append(f)
mode, nick = self.sanit(x)
if nick:
newNicklist.append((mode, nick))
userinfo.initialNames(self.net, nicklist[0], newNicklist)
def myInfo(self, servername, version, umodes, cmodes):
@ -503,10 +503,8 @@ class IRCBot(IRCClient):
chankeep.initialList(self.net, self.num, listinfo, self.chanlimit)
def recheckList(self):
print("list being rechecked")
allRelays = chankeep.allRelaysActive(self.net)
if allRelays:
print("allrelays now passed")
name = self.net+"1"
if main.IRCPool[name].wantList == True:
main.IRCPool[name].list(nocheck=True)
@ -536,7 +534,12 @@ class IRCBot(IRCClient):
self.recheckList()
def seed_prefix(self, prefix):
print("PREFIX", prefix)
prefix = prefix.replace(")", "")
prefix = prefix.replace("(", "")
length = len(prefix)
half = int(length/2)
prefixToMode = dict(zip(prefix[half:], prefix[:half]))
self.prefix = prefixToMode
def isupport(self, options):
interested = {"CHANLIMIT", "MAXCHANNELS", "PREFIX"}

View File

@ -19,6 +19,8 @@ def parsemeta(numName, c):
# in which case, do not do this
if c["type"] in ["msg", "notice", "action", "topic", "mode"]:
userinfo.editUser(c["net"], c["muser"])
if c["type"] == "mode":
userinfo.updateMode(c)
elif c["type"] == "nick":
userinfo.renameUser(c["net"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
elif c["type"] == "kick":

View File

@ -91,9 +91,11 @@ def initialUsers(name, channel, users):
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)
for mode, nick in names:
p.sadd(namespace, nick)
p.sadd("live.chan."+name+"."+nick, channel)
if mode:
p.hset("live.prefix."+name+"."+channel, nick, mode)
p.execute()
def initialNames(name, channel, names):
@ -126,6 +128,7 @@ def delUser(name, channel, nick, user):
p.srem(namespace, nick)
if channels == {channel.encode()}: # can we only see them on this channel?
p.delete(chanspace) # remove channel tracking entry
p.hdel("live.prefix."+name+"."+channel, nick) # remove prefix tracking entry
p.hdel(mapspace, nick) # remove nick mapping entry
if user:
p.srem(gnamespace, user) # remove global userinfo entry
@ -177,6 +180,10 @@ def renameUser(name, oldnick, olduser, newnick, newuser):
p.sadd("live.who."+name+"."+i, newnick)
p.hdel(mapspace, oldnick)
p.hset(mapspace, newnick, newuser)
if main.r.exists("live.prefix."+name+"."+i): # if there's a prefix entry for the channel
if main.r.hexists("live.prefix."+name+"."+i, oldnick): # if the old nick is in it
mode = main.r.hget("live.prefix."+name+"."+i, oldnick) # retrieve old modes
p.hset("live.prefix."+name+"."+i, newnick, mode) # set old modes to new nickname
if main.r.exists(chanspace):
p.rename(chanspace, newchanspace)
else:
@ -197,6 +204,8 @@ def delUserByNetwork(name, nick, user): # quit
p.srem(gnamespace, user)
for i in main.r.smembers(chanspace):
p.srem("live.who."+name+"."+i.decode(), nick)
p.hdel("live.prefix."+name+"."+i, nick)
p.delete(chanspace)
p.hdel(mapspace, nick)
p.execute()
@ -216,14 +225,16 @@ def _delChannels(net, channels):
if main.r.smembers("live.chan."+net+"."+nick) == {channel.encode()}:
if user:
p.srem(gnamespace, user)
p.delete("live.chan."+net+"."+nick)
p.hdel(mapspace, nick) # remove map entry
else:
p.srem("live.chan."+net+"."+nick, channel)
p.delete(namespace)
p.delete("live.prefix."+net+"."+channel)
p.execute()
def delChannels(net, channels):
def delChannels(net, channels): # we have left a channel
debug("Purging channel %s for %s" % (", ".join(channels), net))
d = deferToThread(_delChannels, net, channels)
#d.addCallback(testCallback)