summaryrefslogtreecommitdiffstats
path: root/ksirc/advfollow.pl
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /ksirc/advfollow.pl
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksirc/advfollow.pl')
-rw-r--r--ksirc/advfollow.pl125
1 files changed, 125 insertions, 0 deletions
diff --git a/ksirc/advfollow.pl b/ksirc/advfollow.pl
new file mode 100644
index 00000000..c7254641
--- /dev/null
+++ b/ksirc/advfollow.pl
@@ -0,0 +1,125 @@
+#
+#
+&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>/){
+ my $n = $1;
+ return if $n eq $nick;
+ if(!defined($K_FOLLOW{$n})){
+ $K_FOLLOW{$n} = $K_VAL_COL [ &sum_nick($n) % $#K_VAL_COL];
+ }
+ my $c = $K_FOLLOW{$n};
+ $_[0] =~ s/<~n\w+~c>/<~$c$n~c>/;
+ }
+ elsif ($_[0] =~ /~\* (\w+) \w+/) {
+ my $n = $1;
+ return if $n eq $nick;
+ if(!defined($K_FOLLOW{$n})){
+ $K_FOLLOW{$n} = $K_VAL_COL [ &sum_nick($n) % $#K_VAL_COL];
+ }
+ my $c = $K_FOLLOW{$n};
+ $_[0] =~ s/\* \w+ (\w+)/\* ~$c$n~c $1/;
+ }
+}
+addhook("print", "ksircadvfollow");
+
+$K_ADV_LENGTH = 0;
+
+sub kadv_save {
+ &kadv_load();
+ return if($K_ADV_LENGTH == (scalar %K_FOLLOW));
+
+ open(SAVE, ">$ENV{HOME}/.adv_follow") || return;
+ my $n, $v;
+ while(($n, $v) = each %K_FOLLOW){
+ print SAVE "$n\t$v\n";
+ }
+ close SAVE;
+ $K_ADV_LENGTH = scalar %K_FOLLOW;
+}
+
+sub kadv_load {
+ open(SAVE, "<$ENV{HOME}/.adv_follow") || return;
+ while(<SAVE>){
+ chomp;
+ my ($n, $v) = split(/\t/, $_);
+ if(!defined($K_FOLLOW{$n})){
+ $K_FOLLOW{$n} = $v;
+ }
+
+ }
+ close SAVE;
+}
+
+&kadv_load();
+sub kadv_timer_save {
+ &timer(300, "&kadv_timer_save()", 324325);
+ &kadv_save();
+}
+&timer(300, "&kadv_timer_save()", 324325);
+
+
+sub cmd_afflush {
+ %K_FOLLOW = ();
+}
+
+addhelp("afflush", "Usaage: afflush\nDelete all coloured nicks");
+addcmd("afflush");
+
+
+sub cmd_afnick {
+ &getarg;
+ my $n = $newarg;
+ &getarg;
+ if($newarg){
+ $K_FOLLOW{$n} = $newarg;
+ }
+ else {
+ $K_FOLLOW{$n} = $K_VAL_COL [int (rand scalar (@K_VAL_COL))];
+ }
+}
+
+addhelp("afnick", "Usage: afnick nick <col>\nResets the colour for nick. If col is specefied it is set to col. Random otherwise.");
+addcmd("afnick");
+
+sub cmd_afoff {
+ remhook("print", "ksircadvfollow");
+}
+addhelp("afoff", "Usage: afoff\nTurn off advance follow");
+addcmd("afoff");
+
+sub cmd_afon {
+ addhook("print", "ksircadvfollow");
+}
+addhelp("afon", "Usage: afon\nTurn on advange follow");
+addcmd("afon");
+
+print "*** Advance follow Loaded\n";
+print "*** New commands: /afflush /afnick /afoff /afon\n";
+