diff --git a/tipbot.py b/tipbot.py index b15d527..81b04f2 100644 --- a/tipbot.py +++ b/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() diff --git a/tipbot/link.py b/tipbot/link.py index 1e048e8..bb3e7ff 100644 --- a/tipbot/link.py +++ b/tipbot/link.py @@ -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 diff --git a/tipbot/modules/irc.py b/tipbot/modules/irc.py index 16d5093..15258aa 100644 --- a/tipbot/modules/irc.py +++ b/tipbot/modules/irc.py @@ -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) diff --git a/tipbot/network.py b/tipbot/network.py index 92a19f8..dda1a5a 100644 --- a/tipbot/network.py +++ b/tipbot/network.py @@ -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