mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
Canonicalize nicks
For IRC, this mean case insensitivity
This commit is contained in:
parent
a7ac4f8b1c
commit
c03f518b96
4 changed files with 57 additions and 1 deletions
50
tipbot.py
50
tipbot.py
|
@ -334,6 +334,20 @@ def OnCommandProxy(link,cmd):
|
|||
log_error('Exception running command %s: %s' % (str(cmd),str(e)))
|
||||
link.batch_send_done()
|
||||
|
||||
def lower_nick(s,net):
|
||||
news = ""
|
||||
start_idx = s.find(net)
|
||||
if start_idx >= 0:
|
||||
start_idx += len(net)
|
||||
news = s[:start_idx]
|
||||
while start_idx < len(s) and s[start_idx] != ':':
|
||||
news = news + s[start_idx].lower()
|
||||
start_idx += 1
|
||||
news = news + s[start_idx:]
|
||||
else:
|
||||
news = s
|
||||
return news
|
||||
|
||||
def MigrateRedis():
|
||||
balances=redis_hgetall('balances')
|
||||
for balance in balances:
|
||||
|
@ -374,6 +388,42 @@ def MigrateRedis():
|
|||
log_info('copying %s to %s' % (key,altkey))
|
||||
redisdb.restore(altkey,0,redisdb.dump(key))
|
||||
|
||||
keys=redisdb.keys()
|
||||
for key in keys:
|
||||
if key.find("freenode:") >= 0 and not key.endswith("freenode:"):
|
||||
altkey=lower_nick(key,"freenode:")
|
||||
if altkey == key:
|
||||
continue
|
||||
for ck in keys:
|
||||
if key != ck and lower_nick(ck,"freenode:")==altkey:
|
||||
log_error('Found two congruent keys: %s and %s' % (key,ck))
|
||||
exit()
|
||||
log_info('renaming %s to %s' % (key,altkey))
|
||||
redisdb.restore(altkey,0,redisdb.dump(key))
|
||||
redisdb.delete(key)
|
||||
for hashname in ['balances','paymentid','bookie:1','password','dice:serverseed','dice:playerseed','blackjack:serverseed','blackjack:playerseed']:
|
||||
entries=redis_hgetall(hashname)
|
||||
for k in entries.keys():
|
||||
v=entries[k]
|
||||
if v.find("freenode:") >= 0 and not v.endswith("freenode:"):
|
||||
altv=lower_nick(v,"freenode:")
|
||||
if altv == v:
|
||||
continue
|
||||
log_info('changing %s:%s value %s to %s' % (hashname,k,v,altv))
|
||||
redis_hset(hashname,k,altv)
|
||||
|
||||
if k.find("freenode:") >= 0 and not k.endswith("freenode:"):
|
||||
altkey=lower_nick(k,"freenode:")
|
||||
if altkey == k:
|
||||
continue
|
||||
for ck in keys:
|
||||
if k != ck and lower_nick(ck,"freenode:")==altkey:
|
||||
log_error('Found two congruent keys in %s: %s and %s' % (hashname,k,ck))
|
||||
exit()
|
||||
log_info('renaming %s key %s to %s' % (hashname,k,altkey))
|
||||
redisdb.hset(hashname,altkey,redis_hget(hashname,k))
|
||||
redisdb.hdel(hashname,k)
|
||||
|
||||
RegisterCommands()
|
||||
redisdb = connect_to_redis(config.redis_host,config.redis_port)
|
||||
MigrateRedis()
|
||||
|
|
|
@ -17,7 +17,7 @@ class Link:
|
|||
self.user=user
|
||||
self.group=group
|
||||
self.data=data
|
||||
self.identity_string = self.network.name+":"+self.user.nick
|
||||
self.identity_string = self.network.name+":"+network.canonicalize(self.user.nick)
|
||||
self.batch_message = None
|
||||
self.batch_message_private = None
|
||||
|
||||
|
|
|
@ -87,6 +87,9 @@ class IRCNetwork(Network):
|
|||
def is_identified(self,link):
|
||||
return link.identity() in self.registered_users
|
||||
|
||||
def canonicalize(self,nick):
|
||||
return nick.lower()
|
||||
|
||||
def join(self,chan):
|
||||
self._irc_sendmsg('JOIN '+chan)
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ class Network:
|
|||
def update_users_list(self,group_name=None):
|
||||
pass
|
||||
|
||||
def canonicalize(self,name):
|
||||
return name
|
||||
|
||||
def update(self):
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue