git » msnlib » commit 03973d4

Fix user renaming.

author Alberto Bertogli
2005-04-12 18:32:37 UTC
committer Alberto Bertogli
2005-04-12 18:32:37 UTC
parent 724c84d61f8fbd6a14892003ce89764ee5d0673e

Fix user renaming.

msn +17 -3
msnlib.py +6 -0

diff --git a/msn b/msn
index 13872e4..ed99d3f 100644
--- a/msn
+++ b/msn
@@ -1078,14 +1078,13 @@ def parse_cmd(cmd):
 
 	elif cmd == 'ren':		# rename a user
 		p = params.split()
-		if len(p) != 2: return 'Error parsing command'
+		if len(p) < 2: return 'Error parsing command'
 		email = nick2email(p[0])
 		if not email:
 			return 'Unkown nick (%s)' % p[0]
 		newnick = p[1]
 		u = m.users[email]
-		m.userdel(email)
-		m.useradd(email, newnick, u.gid)
+		m.userren(email, newnick)
 
 	elif cmd == 'gadd':		# add a group
 		p = params.split()
@@ -1488,6 +1487,21 @@ def cb_rem(md, type, tid, params):
 	msncb.cb_rem(md, type, tid, params)
 m.cb.rem = cb_rem
 
+def cb_rea(md, type, tid, params):
+	t = params.split(' ')
+	email = t[1]
+	nick = urllib.unquote(t[2])
+	if email != md.email:
+		out = '\r' + c.blue + c.bold + email + ' ' + c.magenta \
+			+ 'has been renamed\n'
+		printl(out)
+	else:
+		out = '\r' + c.magenta + c.bold \
+			+ 'Your nick has been changed\n'
+		printl(out)
+	msncb.cb_rea(md, type, tid, params)
+m.cb.rea = cb_rea
+
 def cb_adg(md, type, tid, params):
 	t = params.split(' ')
 	lver, name, gid = t[0:3]
diff --git a/msnlib.py b/msnlib.py
index 9339894..93b6403 100644
--- a/msnlib.py
+++ b/msnlib.py
@@ -385,6 +385,12 @@ class msnd:
 		self._send('REM', 'AL ' + email)
 		self._send('REM', 'FL ' + email)
 		return 1
+	
+	def userren(self, email, newnick):
+		"Renames a user"
+		newnick = urllib.quote(newnick)
+		self._send('REA', email + ' ' + newnick)
+		return 1
 
 	def userblock(self, email):
 		self._send('REM', 'AL ' + email)