initial checkin
[grml-etc.git] / etc / skel / .irssi / scripts / osd.pl
1 use strict;
2 use IO::Handle;
3 use vars qw($VERSION %IRSSI);
4
5 use Irssi;
6 $VERSION = '0.3.3';
7 %IRSSI = (
8         authors     => 'Jeroen Coekaerts, Koenraad Heijlen',
9         contact     => 'vipie@ulyssis.org, jeroen@coekaerts.be',
10         name        => 'osd',
11         description => 'An OnScreenDisplay (osd) it show\'s who is talking to you, on what IRC Network.',
12         license     => 'BSD',
13         url         => 'http://vipie.studentenweb.org/dev/irssi/',
14         changed     => '2004-01-09'
15 );
16
17
18 #--------------------------------------------------------------------
19 # Public Variables
20 #--------------------------------------------------------------------
21 my %myHELP = ();
22
23 #--------------------------------------------------------------------
24 # Help function
25 #--------------------------------------------------------------------
26 sub cmd_help { 
27         my ($about) = @_;
28
29         %myHELP = (
30                 osd_test => "
31 osd_test
32
33 Displays a small test message on screen
34 ",
35
36                 osd => "
37 OSD 
38
39 You can display on screen who is paging/msg'ing you on IRC.
40
41 When you CHANGE the settings you SHOULD use /osd_reload to let these changes
42 take effect.
43
44 Settings:
45 ---------
46
47 * osd_showactivechannel (default: yes)
48 Currently the setting is: " . Irssi::settings_get_str('osd_showactivechannel') . "
49
50 When set to yes, OSD will be triggered even if the channel is the active channel.
51 When set to yes, OSD will be triggered if you send a message from your own nick.
52
53 You can test the OSD settings with the 'osd_test' command!
54 he 'osd_test' to test them.
55
56 ",
57 );
58
59         if ( $about =~ /(osd_reload|osd_test|osd)/i ) { 
60                 Irssi::print($myHELP{lc($1)});
61         } 
62 }
63
64 #--------------------------------------------------------------------
65 # Irssi::Settings
66 #--------------------------------------------------------------------
67
68 Irssi::settings_add_str('OSD', 'osd_showactivechannel', "yes");
69
70 #--------------------------------------------------------------------
71 # initialize the pipe, test it.
72 #--------------------------------------------------------------------
73
74 sub init {
75         osdprint("OSD Loaded.");
76 }
77
78 #--------------------------------------------------------------------
79 # open the OSD pipe
80 #--------------------------------------------------------------------
81
82 sub pipe_open {
83     open(OSDPIPE, "| nc -q 1 localhost 1234 2>/dev/null");
84         OSDPIPE->autoflush(1);
85 }
86
87 #--------------------------------------------------------------------
88 # Private message parsing
89 #--------------------------------------------------------------------
90
91 sub priv_msg {
92         my ($server,$msg,$nick,$address,$target) = @_;
93     osdprint("IRC:*private:$nick");
94 }
95
96 #--------------------------------------------------------------------
97 # Public message parsing
98 #--------------------------------------------------------------------
99
100 sub pub_msg {
101         my ($server,$msg,$nick,$address, $channel) = @_;
102         my $show;
103
104     if ($msg =~ /$server->{nick}/) {
105         osdprint("IRC:$channel:$nick");
106     }
107 }
108
109 #--------------------------------------------------------------------
110 # The actual printing
111 #--------------------------------------------------------------------
112
113 sub osdprint {
114         my ($text) = @_;
115     pipe_open();
116         print OSDPIPE "$text\n";
117         OSDPIPE->flush();
118     close(OSDPIPE);
119 }
120
121 #--------------------------------------------------------------------
122 # A test command.
123 #--------------------------------------------------------------------
124
125 sub cmd_osd_test {
126         osdprint("Testing OSD");
127 }
128
129 #--------------------------------------------------------------------
130 # Irssi::signal_add_last / Irssi::command_bind
131 #--------------------------------------------------------------------
132
133 Irssi::signal_add_last("message public", "pub_msg");
134 Irssi::signal_add_last("message private", "priv_msg");
135
136 Irssi::command_bind("osd_test","cmd_osd_test", "OSD");
137 Irssi::command_bind("help","cmd_help", "Irssi commands");
138
139 #--------------------------------------------------------------------
140 # The command that's executed at load time.
141 #--------------------------------------------------------------------
142
143 init();
144
145 #--------------------------------------------------------------------
146 # This text is printed at Load time.
147 #--------------------------------------------------------------------
148
149 Irssi::print("Use /help osd for more information."); 
150
151
152 #- end