html/tracknick.pl
1 # created for irssi 0.7.98, Copyright (c) 2000 Timo Sirainen
2
3 # Are you ever tired of those people who keep changing their nicks?
4 # Or maybe you just don't like someone's nick?
5 # This script lets you see them with the real nick all the time no matter
6 # what nick they're currently using.
7
8 # Features:
9 # - when you first join to channel the nick is detected from real name
10 # - when the nick join to channel, it's detected from host mask
11 # - keeps track of parts/quits/nick changes
12 # - /find[realnick] command for seeing the current "fake nick"
13 # - all public messages coming from the nick are displayed as coming from
14 # the real nick.
15 # - all other people's replies to the fake nick are changed to show the
16 # real nick instead ("fakenick: hello" -> "realnick: hello")
17 # - if you reply to the real nick, it's automatically changed to the
18 # fake nick
19
20 # TODO:
21 # - ability to detect always from either address or real name (send whois
22 # requests after join)
23 # - don't force the trackchannel
24 # - nick completion should complete to the real nick too (needs changes
25 # to irssi code, perl module doesn't recognize "completion word" signal)
26 # - support for runtime configuration + multiple nicks
27 # - support for /whois and some other commands? private messages?
28
29 use Irssi;
30 use Irssi::Irc;
31 use vars qw($VERSION %IRSSI);
32 $VERSION = "0.01";
33 %IRSSI = (
34 authors => "Timo Sirainen",
35 contact => "tss\@iki.fi",
36 name => "track nick",
37 description => "Are you ever tired of those people who keep changing their nicks? Or maybe you just don't like someone's nick? This script lets you see them with the real nick all the time no matter what nick they're currently using.",
38 license => "Public Domain",
39 url => "http://irssi.org/",
40 changed => "2002-03-04T22:47+0100"
41 );
42
43 # change these to the values you want them to be
44 # change these to the values you want them to be
45 my $trackchannel = '#channel';
46 my $realnick = 'nick';
47 my $address_regexp = 'user@address.fi$';
48 my $realname_regexp = 'first.*lastname';
49
50 my $fakenick = '';
51
52 sub event_nick {
53 my ($newnick, $server, $nick, $address) = @_;
54 $newnick = substr($newnick, 1) if ($newnick =~ /^:/);
55
56 $fakenick = $newnick if ($nick eq $fakenick)
57 }
58
59 sub event_join {
60 my ($data, $server, $nick, $address) = @_;
61
62 if (!$fakenick && $data eq $trackchannel &&
63 $address =~ /$address_regexp/) {
64 $fakenick = $nick;
65 }
66 }
67
68 sub event_part {
69 my ($data, $server, $nick, $address) = @_;
70 my ($channel, $reason) = $data =~ /^(\S*)\s:(.*)/;
71
72 $fakenick = '' if ($fakenick eq $nick && $channel eq $trackchannel);
73 }
74
75 sub event_quit {
76 my ($data, $server, $nick, $address) = @_;
77
78 $fakenick = '' if ($fakenick eq $nick);
79 }
80
81 sub event_wholist {
82 my ($channel) = @_;
83
84 find_realnick($channel) if ($channel->{name} eq $trackchannel);
85 }
86
87 sub find_realnick {
88 my ($channel) = @_;
89
90 my @nicks = $channel->nicks();
91 $fakenick = '';
92 foreach $nick (@nicks) {
93 my $realname = $nick->{realname};
94 if ($realname =~ /$realname_regexp/i) {
95 $fakenick = $nick->{nick};
96 break;
97 }
98 }
99 }
100
101 sub sig_public {
102 my ($server, $msg, $nick, $address, $target) = @_;
103
104 return if ($target ne $trackchannel || !$fakenick ||
105 $fakenick eq $realnick);
106
107 if ($nick eq $fakenick) {
108 # text sent by fake nick - change it to real nick
109 send_real_public($server, $msg, $nick, $address, $target);
110 return;
111 }
112
113 if ($msg =~ /^$fakenick([:',].*)/) {
114 # someone's message starts with the fake nick,
115 # automatically change it to real nick
116 $msg = $realnick.$1;
117 Irssi::signal_emit("message public", $server, $msg,
118 $nick, $address, $target);
119 Irssi::signal_stop();
120 }
121 }
122
123 sub send_real_public
124 {
125 my ($server, $msg, $nick, $address, $target) = @_;
126
127 my $channel = $server->channel_find($target);
128 return if (!$channel);
129
130 my $nickrec = $channel->nick_find($nick);
131 return if (!$nickrec);
132
133 # create temporarily the nick to the nick list so that
134 # nick mode can be displayed correctly
135 my $newnick = $channel->nick_insert($realnick,
136 $nickrec->{op},
137 $nickrec->{voice}, 0);
138
139 Irssi::signal_emit("message public", $server, $msg,
140 $realnick, $address, $target);
141 $channel->nick_remove($newnick);
142 Irssi::signal_stop();
143 }
144
145 sub sig_send_text {
146 my ($data, $server, $item) = @_;
147
148 return if (!$fakenick || !$item ||
149 $item->{name} ne $trackchannel);
150
151 if ($fakenick ne $realnick && $data =~ /^$realnick([:',].*)/) {
152 # sending message to realnick, change it to fakenick
153 $data = $fakenick.$1;
154 Irssi::signal_emit("send text", $data, $server, $item);
155 Irssi::signal_stop();
156 }
157 }
158
159 sub cmd_realnick {
160 if ($fakenick) {
161 Irssi::print("$realnick is currently with nick: $fakenick");
162 } else {
163 Irssi::print("I can't find $realnick currently.");
164 }
165 }
166
167 my $channel = Irssi::channel_find($trackchannel);
168 find_realnick($channel) if ($channel);
169
170 Irssi::signal_add('event nick', 'event_nick');
171 Irssi::signal_add('event join', 'event_join');
172 Irssi::signal_add('event part', 'event_part');
173 Irssi::signal_add('event quit', 'event_quit');
174 Irssi::signal_add('message public', 'sig_public');
175 Irssi::signal_add('send text', 'sig_send_text');
176 Irssi::signal_add('channel wholist', 'event_wholist');
177
178 Irssi::command_bind("find$realnick", 'cmd_realnick');