Skip to content

Commit fccf8fe

Browse files
committed
added scripts from .irssi
mainly needed vim-mode.pl
1 parent 4c75417 commit fccf8fe

10 files changed

+4847
-0
lines changed

.irssi/scripts/autorun/dispatch.pl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../dispatch.pl

.irssi/scripts/autorun/nickcolor.pl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../nickcolor.pl

.irssi/scripts/autorun/uberprompt.pl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../uberprompt.pl

.irssi/scripts/autorun/usercount.pl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../usercount.pl

.irssi/scripts/autorun/vim_mode.pl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../vim_mode.pl

.irssi/scripts/dispatch.pl

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use strict;
2+
use warnings;
3+
use Irssi;
4+
use Irssi::Irc;
5+
use vars qw($VERSION %IRSSI);
6+
7+
$VERSION = "0.0.2";
8+
%IRSSI = (
9+
authors => "Sebastian 'yath' Schmidt",
10+
contact => "yathen\@web.de",
11+
name => "Command dispatcher",
12+
description => "This scripts sends unknown commands to the server",
13+
license => "GNU GPLv2",
14+
changed => "Tue Mar 5 14:55:29 CET 2002",
15+
);
16+
17+
sub event_default_command {
18+
my ($command, $server) = @_;
19+
return if (Irssi::settings_get_bool("dispatch_unknown_commands") == 0
20+
|| !$server);
21+
$server->send_raw($command);
22+
Irssi::signal_stop();
23+
}
24+
25+
Irssi::settings_add_bool("misc", "dispatch_unknown_commands", 1);
26+
Irssi::signal_add_first("default command", "event_default_command");

.irssi/scripts/nickcolor.pl

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
use strict;
2+
use Irssi 20020101.0250 ();
3+
use vars qw($VERSION %IRSSI);
4+
$VERSION = "1";
5+
%IRSSI = (
6+
authors => "Timo Sirainen, Ian Peters",
7+
contact => "tss\@iki.fi",
8+
name => "Nick Color",
9+
description => "assign a different color for each nick",
10+
license => "Public Domain",
11+
url => "http://irssi.org/",
12+
changed => "2002-03-04T22:47+0100"
13+
);
14+
15+
# hm.. i should make it possible to use the existing one..
16+
Irssi::theme_register([
17+
'pubmsg_hilight', '{pubmsghinick $0 $3 $1}$2'
18+
]);
19+
20+
my %saved_colors;
21+
my %session_colors = {};
22+
my @colors = qw/2 3 4 5 6 7 9 10 11 12 13/;
23+
24+
sub load_colors {
25+
open COLORS, "$ENV{HOME}/.irssi/saved_colors";
26+
27+
while (<COLORS>) {
28+
# I don't know why this is necessary only inside of irssi
29+
my @lines = split "\n";
30+
foreach my $line (@lines) {
31+
my($nick, $color) = split ":", $line;
32+
$saved_colors{$nick} = $color;
33+
}
34+
}
35+
36+
close COLORS;
37+
}
38+
39+
sub save_colors {
40+
open COLORS, ">$ENV{HOME}/.irssi/saved_colors";
41+
42+
foreach my $nick (keys %saved_colors) {
43+
print COLORS "$nick:$saved_colors{$nick}\n";
44+
}
45+
46+
close COLORS;
47+
}
48+
49+
# If someone we've colored (either through the saved colors, or the hash
50+
# function) changes their nick, we'd like to keep the same color associated
51+
# with them (but only in the session_colors, ie a temporary mapping).
52+
53+
sub sig_nick {
54+
my ($server, $newnick, $nick, $address) = @_;
55+
my $color;
56+
57+
$newnick = substr ($newnick, 1) if ($newnick =~ /^:/);
58+
59+
if ($color = $saved_colors{$nick}) {
60+
$session_colors{$newnick} = $color;
61+
} elsif ($color = $session_colors{$nick}) {
62+
$session_colors{$newnick} = $color;
63+
}
64+
}
65+
66+
# This gave reasonable distribution values when run across
67+
# /usr/share/dict/words
68+
69+
sub simple_hash {
70+
my ($string) = @_;
71+
chomp $string;
72+
my @chars = split //, $string;
73+
my $counter;
74+
75+
foreach my $char (@chars) {
76+
$counter += ord $char;
77+
}
78+
79+
$counter = $colors[$counter % 11];
80+
81+
return $counter;
82+
}
83+
84+
# FIXME: breaks /HILIGHT etc.
85+
sub sig_public {
86+
my ($server, $msg, $nick, $address, $target) = @_;
87+
my $chanrec = $server->channel_find($target);
88+
return if not $chanrec;
89+
my $nickrec = $chanrec->nick_find($nick);
90+
return if not $nickrec;
91+
my $nickmode = $nickrec->{op} ? "@" : $nickrec->{voice} ? "+" : "";
92+
93+
# Has the user assigned this nick a color?
94+
my $color = $saved_colors{$nick};
95+
96+
# Have -we- already assigned this nick a color?
97+
if (!$color) {
98+
$color = $session_colors{$nick};
99+
}
100+
101+
# Let's assign this nick a color
102+
if (!$color) {
103+
$color = simple_hash $nick;
104+
$session_colors{$nick} = $color;
105+
}
106+
107+
$color = "0".$color if ($color < 10);
108+
$server->command('/^format pubmsg {pubmsgnick $2 {pubnick '.chr(3).$color.'$0}}$1');
109+
}
110+
111+
sub cmd_color {
112+
my ($data, $server, $witem) = @_;
113+
my ($op, $nick, $color) = split " ", $data;
114+
115+
$op = lc $op;
116+
117+
if (!$op) {
118+
Irssi::print ("No operation given");
119+
} elsif ($op eq "save") {
120+
save_colors;
121+
} elsif ($op eq "set") {
122+
if (!$nick) {
123+
Irssi::print ("Nick not given");
124+
} elsif (!$color) {
125+
Irssi::print ("Color not given");
126+
} elsif ($color < 2 || $color > 14) {
127+
Irssi::print ("Color must be between 2 and 14 inclusive");
128+
} else {
129+
$saved_colors{$nick} = $color;
130+
}
131+
} elsif ($op eq "clear") {
132+
if (!$nick) {
133+
Irssi::print ("Nick not given");
134+
} else {
135+
delete ($saved_colors{$nick});
136+
}
137+
} elsif ($op eq "list") {
138+
Irssi::print ("\nSaved Colors:");
139+
foreach my $nick (keys %saved_colors) {
140+
Irssi::print (chr (3) . "$saved_colors{$nick}$nick" .
141+
chr (3) . "1 ($saved_colors{$nick})");
142+
}
143+
} elsif ($op eq "preview") {
144+
Irssi::print ("\nAvailable colors:");
145+
foreach my $i (2..14) {
146+
Irssi::print (chr (3) . "$i" . "Color #$i");
147+
}
148+
}
149+
}
150+
151+
load_colors;
152+
153+
Irssi::command_bind('color', 'cmd_color');
154+
155+
Irssi::signal_add('message public', 'sig_public');
156+
Irssi::signal_add('event nick', 'sig_nick');

0 commit comments

Comments
 (0)