
#!/usr/bin/perl -w

# Talking IRC Xchat plugin to interface w/ speechd(http://speechio.undef.net/)
# Copyright (C) 1999  Joseph Elwell

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

IRC::print "\0035:: Loaded Talking IRC by Joseph Elwell jelwell\@singleclick.com::\003 \n";
IRC::print "\0035:: /speechon to activate /speechoff to deactivate::\003 \n";
IRC::register ("speech script", ".3", "closeSpeech", "");
IRC::add_command_handler("speechon", "speechOn");
IRC::add_command_handler("speechoff", "speechOff");

IRC::add_message_handler("PRIVMSG", "saySomething");

#IRC::add_message_handler("RPL_TOPIC", "saySomething");
#IRC::add_message_handler("332", "saySomething");


open (SPEECH, ">>/dev/speech") || return 0;
print SPEECH "Talking I.R.C. by Joseph Elwell loaded.\n";
close (SPEECH);

sub closeSpeech
{
        open (SPEECH, ">>/dev/speech") || return 0;
        print SPEECH "Talking I.R.C. by Joseph Elwell closed.\n";
        close (SPEECH);
}

sub saySomething
{
        my $line = shift(@_);
        if ($doTalk == 1)
        {
                open (SPEECH, ">>/dev/speech") || return 0;
                $line =~ /:(.*)!(.*@.*) .*:(.*)/;
#               print SPEECH "$1 says $3";
                print SPEECH "$3";
                close (SPEECH);
        }
        return 0;
}

sub speechOn
{
        $doTalk = 1;
        open (SPEECH, ">>/dev/speech") || return 0;
        print SPEECH "speech has been activated.";
        close (SPEECH);
}

sub speechOff
{
        $doTalk = 0;
        open (SPEECH, ">>/dev/speech") || return 0;
        print SPEECH "speech has been dee-activated.";
        close (SPEECH);
}

sub blahBlah
{
        $sayIt = $_;
        open (SPEECH, ">>/dev/speech") || return 0;
        print SPEECH $sayIt;
        close (SPEECH);
}

