irc: Fix nick rename, was not updating channel structures
patch 595793eb543ce778275da1ad086c675444e04c34
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Feb 21 01:12:58 CET 2021
* irc: Fix nick rename, was not updating channel structures
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-11-22 16:18:08.985109853 +0100
+++ new-irgramd/irc.py 2024-11-22 16:18:08.985109853 +0100
@@ -13,7 +13,7 @@
from include import VERSION, CHAN_MAX_LENGHT, NICK_MAX_LENGTH
from irc_replies import irc_codes
-from utils import chunks
+from utils import chunks, set_replace
# Constants
@@ -145,8 +145,13 @@
elif user.password == user.recv_pass:
if user.registered:
# rename
+ current = user.irc_nick.lower()
await self.send_users_irc(user, 'NICK', (nick,))
- del self.users[user.irc_nick.lower()]
+ del self.users[current]
+ for ch in self.irc_channels.keys():
+ set_replace(self.irc_channels[ch], current, ni)
+ set_replace(self.irc_channels_ops[ch], current, ni)
+ set_replace(self.irc_channels_founder[ch], current, ni)
user.irc_nick = nick
self.users[ni] = user
if not user.registered and user.irc_username:
diff -rN -u old-irgramd/utils.py new-irgramd/utils.py
--- old-irgramd/utils.py 2024-11-22 16:18:08.985109853 +0100
+++ new-irgramd/utils.py 2024-11-22 16:18:08.989109846 +0100
@@ -7,3 +7,8 @@
''' Return iterable consisting of a sequence of n-length chunks '''
args = [iter(iterable)] * n
return itertools.zip_longest(*args, fillvalue=fillvalue)
+
+def set_replace(set, item, new_item):
+ if item in set:
+ set.remove(item)
+ set.add(new_item)