[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenetwork/ksirc
From:       Andrew Standley-Jones <asj () cban ! com>
Date:       2003-01-11 16:17:44
[Download RAW message or body]

CVS commit by asj: 

Improved advance follow script.
1. nick colours are selected using a deterministic approach, so if same
nick appears and we don't have it saved it will pick the same colour.
1b. nicks "postfixes" are removed in intial selection, so nick and nick-away
get the same colour.
2. prints out the colours it's using so you can see if their valid.


  M +23 -4     advfollow.pl   1.3


--- kdenetwork/ksirc/advfollow.pl  #1.2:1.3
@@ -1,12 +1,31 @@
 #
 #
-print "*** Loading advance follow...\n";
+&print("*** Loading advance follow...");
 
 @K_VAL_COL = (0,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
 
+print "*** Using colours:";
+foreach (@K_VAL_COL) {
+    print "~$_ $_";
+}
+print "\n";
+
 %K_FOLLOW = ();
 
 $KADV_ON = 1;
 
+sub sum_nick {
+    my $n = shift;
+    my $sum = 0;
+    
+    $n =~ s/^(.*)[-_|].*$/$1/;
+    
+    foreach (split(//, $n)) {
+        $sum += ord;
+    }
+    return $sum;
+        
+}
+
 sub hook_ksircadvfollow {
     if($_[0] =~ /<~n(\w+)~c>/){
@@ -14,5 +33,5 @@
         return if $n eq $nick;
         if(!defined($K_FOLLOW{$n})){
-            $K_FOLLOW{$n} = $K_VAL_COL [int (rand scalar (@K_VAL_COL))];
+            $K_FOLLOW{$n} = $K_VAL_COL [ &sum_nick($n) %  $#K_VAL_COL];
         }
         my $c = $K_FOLLOW{$n};
@@ -23,5 +42,5 @@
         return if $n eq $nick;
         if(!defined($K_FOLLOW{$n})){
-            $K_FOLLOW{$n} = $K_VAL_COL [int (rand scalar (@K_VAL_COL))];
+            $K_FOLLOW{$n} = $K_VAL_COL [ &sum_nick($n) % $#K_VAL_COL];
         }
         my $c = $K_FOLLOW{$n};
@@ -78,5 +97,5 @@
     }
     else {
-        delete $K_FOLLOW{$n};
+        $K_FOLLOW{$n} = $K_VAL_COL [int (rand scalar (@K_VAL_COL))];
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic