summaryrefslogtreecommitdiff
path: root/scripts/perl/sound.pl
diff options
context:
space:
mode:
authorJulien Louis <ptitlouis@sysif.net>2006-09-16 20:48:42 +0000
committerJulien Louis <ptitlouis@sysif.net>2006-09-16 20:48:42 +0000
commit0493cb89eb404e4c7c7e31cbeef71606b8461317 (patch)
tree2109942ea83bd8ec9e8dec272a671e0c283a3802 /scripts/perl/sound.pl
parentcb95bfc8464ef37165ee9d900554a98a87ac68e6 (diff)
downloadweechat-0493cb89eb404e4c7c7e31cbeef71606b8461317.zip
Initial import
Diffstat (limited to 'scripts/perl/sound.pl')
-rw-r--r--scripts/perl/sound.pl95
1 files changed, 95 insertions, 0 deletions
diff --git a/scripts/perl/sound.pl b/scripts/perl/sound.pl
new file mode 100644
index 000000000..f6d04d693
--- /dev/null
+++ b/scripts/perl/sound.pl
@@ -0,0 +1,95 @@
+#
+# Copyright (c) 2006 by FlashCode <flashcode@flashtux.org>
+#
+# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+#
+# Play a sound when highlighted/private msg, or for ctcp sound event.
+#
+# History:
+#
+# 2006-05-30, FlashCode <flashcode@flashtux.org>:
+# added plugin options for commands
+# 2004-10-01, FlashCode <flashcode@flashtux.org>:
+# initial release
+#
+
+use strict;
+
+my $version = "0.3";
+my $command_suffix = " >/dev/null 2>&1 &";
+
+# default values in setup file (~/.weechat/plugins.rc)
+my $default_cmd_highlight = "alsaplay -i text ~/sound_highlight.wav";
+my $default_cmd_pv = "alsaplay -i text ~/sound_pv.wav";
+my $default_cmd_ctcp = "alsaplay -i text \$filename";
+
+weechat::register("Sound", $version, "", "Sound for highlights/privates & CTCP sound events");
+weechat::set_plugin_config("cmd_highlight", $default_cmd_highlight) if (weechat::get_plugin_config("cmd_highlight") eq "");
+weechat::set_plugin_config("cmd_pv", $default_cmd_pv) if (weechat::get_plugin_config("cmd_pv") eq "");
+weechat::set_plugin_config("cmd_ctcp", $default_cmd_ctcp) if (weechat::get_plugin_config("cmd_ctcp") eq "");
+
+weechat::add_message_handler("PRIVMSG", "sound");
+weechat::add_message_handler("weechat_highlight", "highlight");
+weechat::add_message_handler("weechat_pv", "pv");
+weechat::add_command_handler("sound", "sound_cmd");
+
+sub sound
+{
+ my $server = $_[0];
+ if ($_[1] =~ /(.*) PRIVMSG (.*)/)
+ {
+ my ($host, $msg) = ($1, $2);
+ if ($host ne "localhost")
+ {
+ if ($msg =~ /\001SOUND ([^ ]*)\001/)
+ {
+ my $filename = $1;
+ my $command = weechat::get_plugin_config("cmd_ctcp");
+ $command =~ s/(\$\w+)/$1/gee;
+ system($command.$command_suffix);
+ }
+ }
+ }
+ return weechat::PLUGIN_RC_OK;
+}
+
+sub highlight
+{
+ my $command = weechat::get_plugin_config("cmd_highlight");
+ system($command.$command_suffix);
+ return weechat::PLUGIN_RC_OK;
+}
+
+sub pv
+{
+ my $command = weechat::get_plugin_config("cmd_pv");
+ system($command.$command_suffix);
+ return weechat::PLUGIN_RC_OK;
+}
+
+sub sound_cmd
+{
+ if ($#_ == 1)
+ {
+ my $filename = $_[1].".wav";
+ my $command = weechat::get_plugin_config("cmd_ctcp");
+ $command =~ s/(\$\w+)/$1/gee;
+ system($command.$command_suffix);
+ weechat::command("/quote PRIVMSG ".weechat::get_info("channel")." :\001SOUND $filename\001") if (@_);
+ }
+ return weechat::PLUGIN_RC_OK;
+}