Simon McVittie wrote:
> On Sat, 22 Dec 2007 at 18:36:49 -0600, Phil Bordelon wrote:
>> 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.
> 
> If you instead chose the *first* few hex digits of the *SHA-1* of the user's
> public key, it'd match the beginning of the XO's default userIDs in the normal
> activity sharing/chat mechanism, which may be useful if you're trying to sort
> out network issues.

Simon,

Thanks for the feedback!  Attached is a patch which does just that, instead
of the previous MD5 stuff.  I wasn't aware that SHA1 wasn't the way to go,
but that's an easy change.

____________________________________________
Devel mailing list
[email protected]
http://lists.laptop.org/listinfo/devel

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-28 11:16:23.660205389 -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 hashlib
+
+            user_name = sugar.profile.get_nick_name()
+            pubkey = sugar.profile.get_pubkey()
+            m = hashlib.sha1()
+            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 first
+            # four hash bits of the user's public key.
+            user_nick = user_name_letters + "-" + hexhash[0:4]
+
+            nicks = [user_nick]
     except:
         nicks = ["mrurk"]
     return nicks
_______________________________________________
Devel mailing list
[email protected]
http://lists.laptop.org/listinfo/devel

Reply via email to