At last, a non-trivial patch.

By default, XoIRC uses the username when another nick is not
provided.  Alas, for every XO, this is 'olpc'.  This makes for
rather a mess in the IRC channels.

This patch instead generates a more-meaningful nick:

* It takes up to 11 alphabetic characters from the user's Sugar
  nick;
* it appends a hyphen; and
* it adds the last four hexadecimal digits of the MD5 hash of
  the user's public key.

The last serves a dual purpose: it (fairly) uniquely identifies
each XO, and it keeps the collisions to a theoretical minimum
if there are, say, lots of 'jane's or 'john's signing on.

The bug that this patch was originally posted to is at:

   http://dev.laptop.org/ticket/5385

Phil
diff -ur XoIRC.activity/purk/irc.py XoIRC.activity.nickfix/purk/irc.py
--- XoIRC.activity/purk/irc.py	2007-12-06 22:26:30.000000000 -0600
+++ XoIRC.activity.nickfix/purk/irc.py	2007-12-21 17:13:53.860637383 -0600
@@ -43,8 +43,34 @@
     try:
         nicks = [conf.get('nick')] + conf.get('altnicks',[])
         if not nicks[0]:
-            import getpass
-            nicks = [getpass.getuser()]
+
+            # We're going to generate a nick based on the user's nick name
+            # and their public key.
+            import sugar.profile
+            import md5
+
+            user_name = sugar.profile.get_nick_name()
+            pubkey = sugar.profile.get_pubkey()
+            m = md5.new()
+            m.update(pubkey)
+            hexhash = m.hexdigest()
+
+            # Okay.  Get all of the alphabetic bits of the username:
+            user_name_letters = "".join([x for x in user_name if x.isalpha()])
+            
+            # If that came up with nothing, make it 'XO'.  Also, shorten it
+            # if it's more than 11 characters (as we need 5 for - and the
+            # hash).
+            if len(user_name_letters) == 0:
+               user_name_letters = "XO"
+            if len(user_name_letters) > 11:
+               user_name_letters = user_name_letters[0:11]
+
+            # Finally, generate a nick by using those letters plus the last
+            # four hash bits of the user's public key.
+            user_nick = user_name_letters + "-" + hexhash[-4:]
+
+            nicks = [user_nick]
     except:
         nicks = ["mrurk"]
     return nicks
_______________________________________________
Devel mailing list
[email protected]
http://lists.laptop.org/listinfo/devel

Reply via email to