/usr/share/irssi/scripts/pggb_sound.pl is in irssi-scripts 20120326.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | ## This is the IRSSI-version!
## OK, here we go.
## For bugs/suggestions/help contact me at duck@cs.uni-frankfurt.de
##
## This script does nothing usefull but is extremely usefull to me ;-).
## It should handle CTCP SOUNDs correctly - even if the waves are stored
## in subdirs and/or on SMB shares.
## It can also initiate CTCP SOUNDs, handle sound requests and request
## waves automatically.
##
## This is my first perl script. Please be kind to me ;-).
## I built it on top of someone else's work, but I don't know whom...
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "0.2.3.23b";
%IRSSI = (
authors => 'Adam Duck',
contact => 'duck@cs.uni-frankfurt.de',
name => 'PGGB_sound',
description => 'does CTCP SOUNDs and other similar things.',
license => 'GPLv2',
url => '',
);
Irssi::settings_add_bool('PGGB', 'SOUND_autosend', 1);
Irssi::settings_add_bool('PGGB', 'SOUND_autoget', 0);
Irssi::settings_add_bool('PGGB', 'SOUND_play', 1);
Irssi::settings_add_int( 'PGGB', 'SOUND_display', 5);
Irssi::settings_add_str( 'PGGB', 'SOUND_hilight', '(none)');
Irssi::settings_add_str( 'PGGB', 'SOUND_DCC', '(none)');
Irssi::settings_add_str( 'PGGB', 'SOUND_dir', '~/.irssi/');
Irssi::settings_add_str( 'PGGB', 'SOUND_command', 'play');
my $autoget = Irssi::settings_get_bool("SOUND_autoget");
# You can use <nothing>, ".gz" or ".bz2" as extension, the script will
# honour it accordingly. I chose ".gz" because it should be available
# on most systems ...
# Btw, this is NOT the time consuming part. It's `parse_dir'.
my $cachefile = $ENV{HOME} . "/.irssi/wavdir.cache.gz";
########################################
# Changelog
# Sat 23 Mar 2002, 12:26:39 fixed stupid bug in sound_autosend
#
# ------------------------------------------------------------
# Don't edit below this line unless you are prepared to code!
# ------------------------------------------------------------
use File::Listing;
use File::Basename;
Irssi::command_bind("sound", "sound_command");
Irssi::signal_add_last("complete word", "sound_complete");
Irssi::signal_add("event privmsg", "sound_autosend");
Irssi::signal_add("ctcp msg", "CTCP_sound");
Irssi::signal_add('print text', 'hilight_sound');
Irssi::signal_add('dcc created', 'DCC_sound');
#IRC::add_message_handler("PRIVMSG", "sound_autoget");
Irssi::theme_register([
'ctcp', '{ctcp {hilight $0} $1}'
]);
sub help {
Irssi::print("USAGE: /sound setup|<somewav>(.wav)?");
Irssi::print("\nsetup: creates the (vital) cache file.");
Irssi::print("Please setup all variables through the /SET command (they all begin with \"SOUND_\").");
Irssi::print("\nIf you have copied new waves to your sounddir, be sure to run \"/sound setup\" again!");
}
sub find_wave {
unless ( -e "$cachefile" ) {
Irssi::print("Cache file not found...");
create_cache();}
my $sound = shift(@_);
unless ($sound =~ /^.*\.wav$/i) {$sound = $sound . ".*.wav"}
my $LISTING;
if ( -r $cachefile ) {
if ($cachefile =~ /\.gz$/i) { open(LISTING, "zcat $cachefile |") }
elsif ($cachefile =~ /\.bz2$/i) { open(LISTING, "bzcat $cachefile |") }
else { open(LISTING, "cat $cachefile |") };
} else {
Irssi::print("Cache file not readable. Nani?!?");
return;}
my @dir = parse_dir(\*LISTING, '+0001');
close(LISTING);
my $result = [];
for (@dir) {
my ($fName, $fType, $fSize, $fMtime, $fMode) = @$_;
if (basename($fName) =~ /^$sound$/i) {
#Irssi::print "$fName, $fType, $fSize, $fMtime, $fMode";
push @$result, $fName;}}
return @$result;
}
sub create_cache {
my $sounddir = Irssi::settings_get_str("SOUND_dir") . "/";
# we need the "LC_CTYPE=en" here because dir_parse is unable
# to parse things like "Mär 3" (German locale) ...
Irssi::print("Creating $cachefile (this could take a while...)");
my $command = "/exec LC_CTYPE=en ls -lR $sounddir";
if ($cachefile =~ /\.gz$/i) { $command = $command . " | gzip" }
elsif ($cachefile =~ /\.bz2$/i) { $command = $command . " | bzip2" }
Irssi::command("$command > $cachefile");
}
sub onoff { shift(@_) ? return "ON" : return "OFF"; }
sub sound_command {
my $sounddir = Irssi::settings_get_str("SOUND_dir") . "/";
my $soundcmd = Irssi::settings_get_str("SOUND_command");
my ($data, $server, $witem) = @_;
$data =~ /([\w\.]+)(.*)/;
my $sound = $1;
my $rest = $2;
$rest =~ s/ *//;
unless ($rest eq "") { $rest = " " . $rest;};
if ($sound =~ /^setup$/i) { create_cache(); return; }
if (!($sound =~ /.*\.wav/i)) { $sound = $sound . ".wav";}
if ($witem && ($witem->{type} eq "CHANNEL" ||
$witem->{type} eq "QUERY")) {
my $wavefile = (find_wave($sound))[0];
if ( -r $wavefile ) {
$witem->command("/CTCP $witem->{name} SOUND ".lc(basename($wavefile))."$rest");
my $playcmd = system("$soundcmd $wavefile &"); # that's not so good ...
} else {
$witem->print("\"$sound\" not found in \"$sounddir\" or cache file too old."); }
} else {
Irssi::print "There's no point in running a \"CTCP SOUND\" command here."; }
return 1;
}
sub sound_complete {
my ($complist, $window, $word, $linestart, $want_space) = @_;
if ($linestart =~ /^\/sound$/) {
my $coli = [];
for (find_wave($word)) { push(@$coli, basename($_)); }
my $max = Irssi::settings_get_int('SOUND_display');
if (@$coli > $max) {
$window->print("@$coli[0..($max-1)] ...");
} else {
push @$complist, @$coli; }}}
sub sound_autosend {
if (!Irssi::settings_get_bool("SOUND_autosend")) { return 0; }
my ($server, $data, $nick, $address) = @_;
my $myname = $server->{nick};
$data =~ /(.*) :!$myname +(.*\.wav)/i;
if ($2 eq "") { return 0; }
my $channel = $1;
my $wavefile = (find_wave($2))[0];
if ($wavefile ne "") {
Irssi::print("DCC sending $wavefile to $nick");
$server->command("/DCC SEND $nick $wavefile");
} else {
$server->send_message($nick, "Sorry, $nick. $2 not found.", 1);
}
return 1;
}
sub hilight_sound {
my ($dest, $text, $stripped) = @_;
my $server = $dest->{server};
unless ($server->{usermode_away}) {
my $hiwave = Irssi::settings_get_str('SOUND_hilight');
if (($hiwave ne '(none)') &&
($dest->{level} & (MSGLEVEL_HILIGHT|MSGLEVEL_MSGS)) &&
($dest->{level} & MSGLEVEL_NOHILIGHT) == 0) {
play_wave(find_wave($hiwave));}}}
sub DCC_sound {
my $dcc = shift(@_);
my $server = $dcc->{server};
Irssi::print("$dcc->{type}");
unless ($server->{usermode_away} || ($dcc->{type} eq "SEND")) {
my $hiwave = Irssi::settings_get_str('SOUND_DCC');
if ($hiwave ne '(none)') {
play_wave(find_wave($hiwave));}}}
sub play_wave {
my $wave = shift(@_);
my $sndcmd = Irssi::settings_get_str("SOUND_command");
if (-r "$wave") {
system("$sndcmd \"$wave\" &");}}
sub sound_autoget {
if (!$autoget) { return 0; }
my $sounddir = Irssi::settings_get_str("SOUND_dir") . "/";
my $line = shift (@_);
#:nick!host PRIVMSG channel :message
$line =~ /:(.*)!(\S+) PRIVMSG (.*) :(.*)/i;
my $name = $1;
my $channel = $3;
my $text = $4;
my $name = "$name";
my @wordlist = split(' ',$4);
if ($wordlist[0] eq "\001SOUND") {
my $tempsound = $wordlist[1];
$tempsound =~ s/[\r \001 \n]//;
IRC::print($tempsound);
if (!open(TEMPFILE, $sounddir.$tempsound)) {
IRC::send_raw("PRIVMSG $name :!$name $tempsound\r\n");
} else {
close(TEMPFILE);
}
}
return 0;
}
sub CTCP_sound {
my $play = Irssi::settings_get_bool("SOUND_play");
my $soundcmd = Irssi::settings_get_str("SOUND_command");
my ($server, $args, $nick, $addr, $target) = @_;
$args =~ /^SOUND (.*\.wav)(.*)$/i;
if ($1 eq "") { return 0; }
my $sound = $1;
my $wavfile = (find_wave($1))[0];
my $output = "";
my $rest = $2;
$rest =~ s/^ *//;
if ( $rest ne "" ) { # this one is for P&P & co.
$output = $output . $rest
} else {
$output = $output . " plays $sound";
}
if ($wavfile eq "") {
$output = $output . " (not found)";
if ($autoget) {
Irssi::send_raw("PRIVMSG $nick :!$nick $sound\r\n");
}
} else {
if ($play) {
system("$soundcmd \"$wavfile\" &");
} else {
$output = $output . " (muted)";
}
}
my $wItem = $server->window_find_item($target);
$wItem->printformat(MSGLEVEL_CTCPS, 'ctcp', $nick, $output);
Irssi::signal_stop();
}
|