html/talk.pl
1 # -*- CPerl -*-
2 # $Id$
3 use Irssi;
4 use vars qw($VERSION %IRSSI);
5 $VERSION = '1.01';
6 %IRSSI = (
7 authors => 'Alexander Mieland',
8 contact => 'dma147\@mieland-programming.de',
9 name => 'Talk',
10 description => 'This script talks to you *g*. It reads the chat-msgs for you.',
11 license => 'GPL2',
12 );
13
14 ##########################################################################
15 #
16 # Change your preferred language here
17 my $language = "en"; # (en|de)
18 #
19 # should I say all of the joins, parts and quits?
20 my $sayjpq = "0"; # (1|0)
21 #
22 # should I say all of the nickchanges?
23 my $saynickchg = "0"; # (1|0)
24 #
25 ##########################################################################
26
27
28 Irssi::theme_register(
29 [
30 'talk_loaded',
31 '{line_start}{hilight Talk:} $0',
32 ]);
33
34 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'talk_loaded', "Version 1.0 loaded. Type /talk_help, if you have any questions or problems.");
35
36 sub cmd_talk_help
37 {
38 my $help = "
39 [talk.pl]
40
41 This script is a text2speech engine for your irssi. It reads the msgs from
42 your irssi client and speaks them through your soundcard.
43
44 It is highly recommended, that you\'ve set up your txt2speech in linux with
45 a tutorial, which provides a little bash-script, called \'say\', which must
46 be able to be useed in a pipe.
47
48 Because this irssi-script makes use of the bash-script /usr/(local/)bin/say
49 and it uses it in a pipe.
50 Otherwise this irssi-script will *not* work.
51
52 For german people, I would prefer:
53 http://www.linux-magazin.de/Artikel/ausgabe/2000/05/Sprachsynthese/sprachsynthese.html
54
55 ==========================================================================
56
57 Commands:
58
59 /say [message] : Speaks the given message through your soundcard
60 /talk_about : Licence and Information about this script
61 /talk_help : This helptext
62 ";
63 Irssi::print($help, MSGLEVEL_CLIENTCRAP);
64 }
65
66 sub cmd_talk_about
67 {
68 my $about = "
69 [talk.pl]
70
71 This script is a text2speech engine for your irssi. It reads the msgs from
72 your irssi client and speaks them through your soundcard.
73
74 For information how to use, type /talk_help
75
76 This script is written and copyrighted 2004 by Alexander Mieland
77 Contact: dma147 in #gentoo.de @ irc.freenode.net
78 This script is licenced under the terms of GNU - General Public Licence
79 Version 2.
80 ";
81 Irssi::print($about, MSGLEVEL_CLIENTCRAP);
82 }
83
84 sub RepCrap
85 {
86 my $string = lc(shift) || return;
87 $string =~ s/['#\`]//g;
88 $string =~ s/ä/ae/g;
89 $string =~ s/ö/oe/g;
90 $string =~ s/ü/ue/g;
91 $string =~ s/Ã/ss/g;
92 if ($language eq "de")
93 {
94 $string =~ s/([ ]+[0-9]*)mbit/\1megabit/g;
95 $string =~ s/([ ]+[0-9,\.]*)[ ]*kbit/\1kilobit/g;
96 $string =~ s/([ ]+[0-9,\.]*)[ ]*bit/\1bit/g;
97 $string =~ s/([ ]+[0-9,\.]*)[ ]*mbyte/\1megabeit/g;
98 $string =~ s/([ ]+[0-9,\.]*)[ ]*kbyte/\1megabeit/g;
99 $string =~ s/([ ]+[0-9,\.]*)[ ]*byte/\1beit/g;
100 $string =~ s/([ ]+[0-9,\.]*)[ ]*mb/\1megabeit/g;
101 $string =~ s/([ ]+[0-9,\.]*)[ ]*kb/\1kilobeit/g;
102 $string =~ s/\"/anfuehrungszeichen/g;
103 $string =~ s/_/unterstrich/g;
104 $string =~ s/;\)/zwinkernder smeili/g;
105 $string =~ s/;-\)/zwinkernder smeili/g;
106 $string =~ s/:\)/smeili/g;
107 $string =~ s/:-\)/smeili/g;
108 $string =~ s/:\(/trauriger smeili/g;
109 $string =~ s/:-\(/trauriger smeili/g;
110 $string =~ s/\*g\*/grins/g;
111 $string =~ s/\*gg\*/grins grins/g;
112 $string =~ s/\*fg\*/freches grinsen/g;
113 $string =~ s/\*ffg\*/sehr freches grinsen/g;
114 $string =~ s/afaik/so weit ich weiss/g;
115 $string =~ s/imho/meiner meinung nach/g;
116 $string =~ s/([^ ]+)\.([^ ]+)/\1punkt\2/g;
117 }
118 else
119 {
120 $string =~ s/([ ]+[0-9,\.]*)[ ]*mbit/\1megabit/g;
121 $string =~ s/([ ]+[0-9,\.]*)[ ]*kbit/\1kilobit/g;
122 $string =~ s/([ ]+[0-9,\.]*)[ ]*mbyte/\1megabyte/g;
123 $string =~ s/([ ]+[0-9,\.]*)[ ]*kbyte/\1megabyte/g;
124 $string =~ s/([ ]+[0-9,\.]*)[ ]*mb/\1megabyte/g;
125 $string =~ s/([ ]+[0-9,\.]*)[ ]*kb/\1kilobyte/g;
126 $string =~ s/\"/quote/g;
127 $string =~ s/_/underscore/g;
128 $string =~ s/;\)/winking smilie/g;
129 $string =~ s/;-\)/winking smilie/g;
130 $string =~ s/:\)/smilie/g;
131 $string =~ s/:-\)/smilie/g;
132 $string =~ s/:\(/sad smilie/g;
133 $string =~ s/:-\(/sad smilie/g;
134 $string =~ s/\*g\*/grin/g;
135 $string =~ s/\*gg\*/grin grin/g;
136 $string =~ s/\*fg\*/sassy grin/g;
137 $string =~ s/\*ffg\*/very sassy grin/g;
138 $string =~ s/afaik/as far as i know/g;
139 $string =~ s/imho/in my humble opinion/g;
140 $string =~ s/([^ ]+)\.([^ ]+)/\1point\2/g;
141 }
142 $string =~ s/;/semicolon/g;
143 $string =~ s/-/minus/g;
144 $string =~ s/\+/plus/g;
145 return($string);
146 }
147
148 sub Say
149 {
150 my $text = lc(shift) || return;
151 $text = " ".$text." ";
152 $text = RepCrap($text);
153 system("bash -c \"echo \\\"$text\\\" | say\" &");
154 }
155
156 sub on_privmsg
157 {
158 my ($server, $data, $nick, $hostmask) = @_;
159 my ($channel, $text) = split(/ :/, $data, 2);
160 if ($language eq "de")
161 { Say("$nick sagt: $text"); }
162 else
163 { Say("$nick says: $text"); }
164 return 0;
165 }
166
167 sub on_join
168 {
169 my ($server, $channel, $nick, $hostmask) = @_;
170 if ($language eq "de")
171 { Say("$nick hat den Channel $channel betreten."); }
172 else
173 { Say("$nick has entered the channel $channel."); }
174 return 0;
175 }
176
177 sub on_quit
178 {
179 my ($server, $data, $nick, $hostmask) = @_;
180 my ($channel, $text) = split(/ :/, $data, 2);
181 if ($language eq "de")
182 { Say("$nick hat den Server verlassen."); }
183 else
184 { Say("$nick has left the server."); }
185 return 0;
186 }
187
188 sub on_part
189 {
190 my ($server, $data, $nick, $hostmask) = @_;
191 my ($channel, $text) = split(/ :/, $data, 2);
192 if ($language eq "de")
193 { Say("$nick hat den Channel $channel verlassen."); }
194 else
195 { Say("$nick has left the channel $channel."); }
196 return 0;
197 }
198
199 sub on_nick
200 {
201 my ($server, $newnick, $nick, $hostmask) = @_;
202 if ($language eq "de")
203 { Say("$nick heisst nun $newnick"); }
204 else
205 { Say("$nick is now known as $newnick"); }
206 return 0;
207 }
208
209 sub cmd_say
210 {
211 Say(@_);
212 return 0;
213 }
214
215 Irssi::command_bind('say', 'cmd_say', 'talk.pl');
216 Irssi::command_bind('talk_about', 'cmd_talk_about', 'talk.pl');
217 Irssi::command_bind('talk_help', 'cmd_talk_help', 'talk.pl');
218 Irssi::signal_add("event privmsg", 'on_privmsg');
219 if ($sayjpq eq "1")
220 {
221 Irssi::signal_add("event join", 'on_join');
222 Irssi::signal_add("event quit", 'on_quit');
223 Irssi::signal_add("event part", 'on_part');
224 }
225 if ($saynickchg eq "1")
226 {
227 Irssi::signal_add("event nick", 'on_nick');
228 }
229
230 #end