Added SILC Thread Queue API
[runtime.git] / apps / irssi / scripts / examples / msg-event.pl
1 # Example how to react on specific messages:
2
3 # !reverse <text> sends back the text reversed.
4
5 use Irssi;
6 use strict;
7 use vars qw($VERSION %IRSSI);
8
9 $VERSION = "1.00";
10 %IRSSI = (
11     authors     => 'Timo Sirainen',
12     name        => 'msg-event',
13     description => 'Event example',
14     license     => 'Public Domain'
15 );
16
17 sub event_privmsg {
18         # $server = server record where the message came
19         # $data = the raw data received from server, with PRIVMSGs it is:
20         #         "target :text" where target is either your nick or #channel
21         # $nick = the nick who sent the message
22         # $host = host of the nick who sent the message
23         my ($server, $data, $nick, $host) = @_;
24
25         # split data to target/text
26         my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
27
28         # skip lines not beginning with !reverse
29         return if ($text !~ /!reverse (.*)/);
30         $text = $1;
31
32         if (!$server->ischannel($target)) {
33                 # private message, $target contains our nick, so we'll need
34                 # to change it to $nick
35                 $target = $nick;
36         }
37
38         $server->command("notice $target reversed $text = ".reverse($text));
39 }
40
41 Irssi::signal_add('event privmsg', 'event_privmsg');