play.pl: -fmt added, -stop fixed
This commit is contained in:
parent
2f1d8d7064
commit
c163b514cc
@ -13,10 +13,11 @@ our (%queue, %timer);
|
||||
if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
|
||||
$SCRIPT_LICENCE, $SCRIPT_DESC, '', '')) {
|
||||
weechat::hook_command('play', 'Play ASCII art',
|
||||
"[-delay ms] [-find] [-pipe \"command\"] filename\n-stop",
|
||||
qq([-delay ms] [-find] [-pipe "command"] [-fmt "text"] filename\n-stop),
|
||||
"-delay: delay in milliseconds between lines\n".
|
||||
"-find: list matching files, don't play\n".
|
||||
"-pipe: pipe output into command\n".
|
||||
"-fmt: treat file as a format string and replace with text\n".
|
||||
"filename: file to play. Supports wildcards. By default, searches\n".
|
||||
" subdirectories as well unless '/' is found in the filename\n".
|
||||
"-stop: stop currently playing file in buffer",
|
||||
@ -36,8 +37,8 @@ if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
|
||||
}
|
||||
|
||||
sub parse {
|
||||
my ($input, $delay, $pipe, $find, $repeat) =
|
||||
(shift, weechat::config_get_plugin('delay'), '/msg *', 0, 1);
|
||||
my ($input, $delay, $pipe, $find, $repeat, $fmt) =
|
||||
(shift, weechat::config_get_plugin('delay'), '/msg *', 0, 1, '');
|
||||
|
||||
if ($input =~ / *-delay +([0-9]+) /) {
|
||||
$delay = $1;
|
||||
@ -47,19 +48,22 @@ sub parse {
|
||||
$find = 1;
|
||||
$input =~ s/-find//;
|
||||
}
|
||||
if ($input =~ / *-fmt +("(?:[^"\\]|\\.)+"|[^ ]+) /) {
|
||||
$fmt = $1;
|
||||
$fmt =~ s/^"(.+)"$/$1/ if $fmt =~ /^".+"$/;
|
||||
$input =~ s/-fmt +("(?:[^"\\]|\\.)+"|[^ ]+)//;
|
||||
}
|
||||
if ($input =~ / *-repeat +([0-9]+) /) {
|
||||
$repeat = $1;
|
||||
$input =~ s/-repeat +[0-9]+//;
|
||||
}
|
||||
# greedy match within quotes so we don't need to escape quotes.
|
||||
# i don't think we will be affected negatively by this
|
||||
if ($input =~ / *-pipe +(".+"|[^ ]+) /) {
|
||||
if ($input =~ / *-pipe +("(?:[^"\\]|\\.)+"|[^ ]+) /) {
|
||||
$pipe = $1;
|
||||
$pipe =~ s/^"(.+)"$/$1/ if $pipe =~ /^".+"$/;
|
||||
$input =~ s/-pipe +(?:".+"|[^ ]+)//;
|
||||
$input =~ s/-pipe +("(?:[^"\\]|\\.)+"|[^ ]+)//;
|
||||
}
|
||||
|
||||
return ($delay, $pipe, $find, $repeat, $input =~ s/^ +| +$//r);
|
||||
return ($delay, $pipe, $find, $repeat, $fmt, $input =~ s/^ +| +$//r);
|
||||
}
|
||||
|
||||
sub play {
|
||||
@ -74,13 +78,15 @@ sub play {
|
||||
sub cmd_play {
|
||||
my $buffer = $_[1];
|
||||
|
||||
if ($_[2] eq '-stop' and exists $timer{$buffer}) {
|
||||
weechat::unhook($timer{$buffer});
|
||||
delete $queue{$buffer};
|
||||
if ($_[2] eq '-stop') {
|
||||
if (exists $timer{$buffer}) {
|
||||
weechat::unhook($timer{$buffer});
|
||||
delete $queue{$buffer};
|
||||
}
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
my ($delay, $pipe, $find, $repeat, $file) = parse($_[2]);
|
||||
my ($delay, $pipe, $find, $repeat, $fmt, $file) = parse($_[2]);
|
||||
my $server = weechat::info_get($buffer, 'localvar_server');
|
||||
my ($prio_s, $prio_d) = (
|
||||
weechat::config_get("irc.server.$server.anti_flood_prio_high"),
|
||||
@ -107,7 +113,10 @@ sub cmd_play {
|
||||
|
||||
if ($path and open FH, "<", $path) {
|
||||
my @lines;
|
||||
push @lines, s/[\r\n]*$//r while <FH>;
|
||||
while (<FH>) {
|
||||
$_ = sprintf $_, split ' ', $fmt if $fmt;
|
||||
push @lines, s/[\r\n]*$//r
|
||||
}
|
||||
close FH;
|
||||
for (1 .. $repeat) {
|
||||
push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f" for @lines;
|
||||
|
Loading…
Reference in New Issue
Block a user