Author: simplet
Date: 2008-12-08 18:26:33 +0100 (Mon, 08 Dec 2008)
New Revision: 3043
Added:
software_suite_v2/software/scripts/droidlite/
software_suite_v2/software/scripts/droidlite/droidlite.pl
Log:
* first V2 for droidlite. this need to be beta tested.
Added: software_suite_v2/software/scripts/droidlite/droidlite.pl
===================================================================
--- software_suite_v2/software/scripts/droidlite/droidlite.pl
(rev 0)
+++ software_suite_v2/software/scripts/droidlite/droidlite.pl 2008-12-08
17:26:33 UTC (rev 3043)
@@ -0,0 +1,252 @@
+#!/usr/bin/perl
+# Adapted from the original irssi OSD script made by Jeroen Coekaerts and
Koenraad Heijlen.
+# December 2008 : Converted to API v2 by Simplet <simplet _at_ ptigeek _dot_
net>
+
+use strict;
+use IO::Handle;
+use vars qw($VERSION %IRSSI);
+
+use Irssi;
+$VERSION = '1.0';
+%IRSSI = (
+ authors => 'Nico Kempe',
+ contact => '[EMAIL PROTECTED]',
+ name => 'DroidLite',
+ description => 'Let\'s TuxDroid read any highlights to you.',
+ license => 'BSD',
+ changed => '2008-09-14'
+);
+
+#--------------------------------------------------------------------
+# TODO:
+# - Finish the check_deps() function
+# - Finish the droid_say() function (would be nice you know..)
+# - Add option for voice selection
+# - Add options to use other Droid functions like blinking and stuff
+# - Add option to choose between system() and exec() for letting
+# TuxDroid speak. Allowing for quicker response time at the cost
+# of no error-checking (thus less userfriendlyness).
+#--------------------------------------------------------------------
+
+#--------------------------------------------------------------------
+# Public Variables
+#--------------------------------------------------------------------
+my %myHELP = ();
+
+#--------------------------------------------------------------------
+# Help function
+#--------------------------------------------------------------------
+sub cmd_help {
+ my ($about) = @_;
+
+ %myHELP = (
+ droid_test => "
+droid_test
+
+Let's TuxDroid speak a test message.
+",
+
+ droid => "
+DroidLite
+
+TuxDroid can read your highlights for you.
+
+Settings:
+---------
+
+* droid_readmsg (default: yes)
+Currently the setting is: " . Irssi::settings_get_str('droid_allowpubmsg') . "
+
+Let TuxDroid read the message text. This can be annoying when people highlight
you often or type long sentences. In that case, you might want to set this
option to 'no'..)
+
+* droid_allowpubmsg (default: yes)
+Currently the setting is: " . Irssi::settings_get_str('droid_allowpubmsg') . "
+
+When set to yes, DroidLite will be triggered even if the channel is the active
channel.
+Also, DroidLite will be triggered if you send a message from your own nick.
+
+When set to no, DroidLite will only be triggered on private messages that are
not from yourself.
+
+* droid_intro (default: \"I R C highlight on \")
+Currently the setting is: " . Irssi::settings_get_str('droid_intro') . "
+
+What to say before the actual highlight quote. Leave this blank if you don't
want to use the intro.
+
+
+Unfortunately, because of the way the TuxDroid and it's scripts work, it will
take a few seconds each time before TuxDroid will actually speak. During this
time Irssi may appear not to respond.
+
+
+You can test the settings with the 'droid_test' command.
+
+",
+);
+
+ if ( $about =~ /(droid_test|droid)/i ) {
+ Irssi::print($myHELP{lc($1)});
+ }
+}
+
+#--------------------------------------------------------------------
+# Irssi::Settings
+#--------------------------------------------------------------------
+
+Irssi::settings_add_str('DroidLite', 'droid_allowpubmsg', "yes");
+Irssi::settings_add_str('DroidLite', 'droid_readmsg', "yes");
+Irssi::settings_add_str('DroidLite', 'droid_intro', "I R C highlight on ");
+# Irssi::settings_add_str('DroidLite', 'droid_voice',
"fem-gb-or-something-like-that");
+
+#--------------------------------------------------------------------
+# initialize the pipe, test it.
+#--------------------------------------------------------------------
+
+sub init {
+ check_deps();
+ Irssi::print("DroidLite initiated. Please use the 'droid_test' command
to test it.");
+}
+
+#--------------------------------------------------------------------
+# Check for dependencies
+#--------------------------------------------------------------------
+
+sub check_deps {
+# TODO; check if the needed TuxDroid files are there <<<<<<<<<<<<<<<<
+}
+
+#--------------------------------------------------------------------
+# Make strings more safe to use and easy to say.
+# Yes, it's a tiny function, but it makes changing the filter easier.
+#--------------------------------------------------------------------
+sub filter_str {
+ my ($text) = @_;
+ # Next line should replace all url-like text with the text 'some url'.
+ $text =~ s/(((ht|f)tp(s?):\/\/)|(www\.))[^\s]+/some u r l/gi;
+ # Remove chars that won't help TuxDroid (or the system) when reading
them.
+ $text =~ s/[^a-z0-9,.!?:;()\s]//gi;
+ return $text;
+}
+
+#--------------------------------------------------------------------
+# Private message parsing
+#--------------------------------------------------------------------
+
+sub priv_msg {
+ my ($server,$msg,$nick,$address,$target) = @_;
+ if (Irssi::settings_get_str('droid_readmsg') =~ /yes/) {
+ $msg = ' : '.$msg;
+ } else {
+ $msg = '';
+ }
+ if ((Irssi::settings_get_str('droid_allowpubmsg') =~ /yes/) or
+ not (Irssi::active_win()->get_active_name() eq "$nick") ) {
+
droidsay(Irssi::settings_get_str('droid_intro').$server->{chatnet}."from: $nick
$msg");
+ }
+}
+
+#--------------------------------------------------------------------
+# Public message parsing
+#--------------------------------------------------------------------
+
+sub pub_msg {
+ my ($server,$msg,$nick,$address, $channel) = @_;
+ my $show;
+
+ if (Irssi::settings_get_str('droid_allowpubmsg') =~ /yes/) {
+ $show = 1;
+ } elsif(uc(Irssi::active_win()->get_active_name()) eq uc($channel)) {
+ $show = 0;
+ }
+
+ if (Irssi::settings_get_str('droid_readmsg') =~ /yes/) {
+ $msg = ' : '.$msg;
+ } else {
+ $msg = '';
+ }
+ if ($show) {
+ my $onick= quotemeta "$server->{nick}";
+ my $pat ='(\:|\,|\s)'; # option...
+ if($msg =~ /^$onick\s*$pat/i){
+
droidsay(Irssi::settings_get_str('droid_intro').$channel."from: $nick $msg");
+ }
+ }
+}
+
+#--------------------------------------------------------------------
+# The actual talking
+#--------------------------------------------------------------------
+
+sub droidsay {
+ my ($text) = @_;
+ $text = filter_str($text);
+ my $command;
+ my $filename = "/tmp/DroidLiteTxt";
+ # This seems a stupid way to do this, and it probably is,
+ # but it's the only way I can come up with to let TuxDroid
+ # say the lines without letting the output mess up the Irssi screen.
+ # If you know a better way of handling this, please let me know.
+ system("/bin/rm $filename &>/dev/null");
+ $command = "echo -e \"".
+ "#!/usr/bin/python\n".
+
+ "import sys, string;\n".
+ "import time;\n".
+ "from tuxisalive.api import *\n".
+
+ "tux = TuxAPI('192.168.1.5', 270)\n".
+ "tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'DroidLite',
'NONE')\n".
+ "tux.server.waitConnected(10.0)\n".
+ "tux.dongle.waitConnected(10.0)\n".
+ "tux.radio.waitConnected(10.0)\n".
+ "if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):\n".
+
+ "tux.tts.speak('$text', 'Julie', 100);\n".
+
+ "tux.access.release()\n".
+ "tux.server.disconnect()\n".
+ "tux.destroy()\" > $filename";
+ if (system($command) != 0) {
+ Irssi::print("Something went wrong in DroidLite while trying to
get ready to read your highlight. Please try the following commands on the
shell if you want to take a stab at it..)");
+ Irssi::print($command);
+ }
+
+ $command = "/usr/bin/python -W ignore -u $filename &>/dev/null";
+ if (system($command) != 0) {
+ Irssi::print("Something went wrong in DroidLite while trying to
read your highlight. Please try the following command on the shell if you want
to take a stab at it..)");
+ Irssi::print("/usr/bin/python $filename");
+ } else {
+ system("/bin/rm $filename &>/dev/null");
+ }
+}
+
+#--------------------------------------------------------------------
+# A test command.
+#--------------------------------------------------------------------
+
+sub cmd_droid_test {
+ droidsay("This is a DroidLite test message.");
+}
+
+#--------------------------------------------------------------------
+# Irssi::signal_add_last / Irssi::command_bind
+#--------------------------------------------------------------------
+
+Irssi::signal_add_last("message public", "pub_msg");
+Irssi::signal_add_last("message private", "priv_msg");
+
+Irssi::command_bind("droid_test","cmd_droid_test");
+Irssi::command_bind("help","cmd_help", "Irssi commands");
+Irssi::command_bind("droid","cmd_help", "Irssi commands");
+
+#--------------------------------------------------------------------
+# The command that's executed at load time.
+#--------------------------------------------------------------------
+
+init();
+
+#--------------------------------------------------------------------
+# This text is printed at Load time.
+#--------------------------------------------------------------------
+
+Irssi::print("Use /help droid for more information.");
+
+
+#- end
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn