From 1158390ac59f93a7015ff9dc39b3e394370c7450 Mon Sep 17 00:00:00 2001 From: wowaname Date: Sun, 2 Oct 2016 21:53:44 +0000 Subject: [PATCH] play.pl: -repeat --- scripts/play.pl | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/play.pl b/scripts/play.pl index 2705a92..ce42e7c 100644 --- a/scripts/play.pl +++ b/scripts/play.pl @@ -5,7 +5,7 @@ no strict 'subs'; my $SCRIPT_NAME = 'play'; my $SCRIPT_AUTHOR = 'The Krusty Krab '; -my $SCRIPT_VERSION = '1.0'; +my $SCRIPT_VERSION = '1.1'; my $SCRIPT_LICENCE = 'Public domain'; my $SCRIPT_DESC = 'Play ASCII art'; our (%queue, %timer); @@ -36,26 +36,30 @@ if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION, } sub parse { - my ($input, $delay, $pipe, $find) = - (shift, weechat::config_get_plugin('delay'), '/msg *', 0); + my ($input, $delay, $pipe, $find, $repeat) = + (shift, weechat::config_get_plugin('delay'), '/msg *', 0, 1); if ($input =~ / *-delay +([0-9]+) /) { $delay = $1; - $input =~ s/ *-delay +[0-9]+ *//; + $input =~ s/-delay +[0-9]+//; } if ($input =~ / *-find /) { $find = 1; - $input =~ s/ *-find *//; + $input =~ s/-find//; + } + 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 +(".+"|[^ ]+) /) { $pipe = $1; $pipe =~ s/^"(.+)"$/$1/ if $pipe =~ /^".+"$/; - $input =~ s/ *-pipe +(?:".+"|[^ ]+) *//; + $input =~ s/-pipe +(?:".+"|[^ ]+)//; } - return ($delay, $pipe, $find, $input); + return ($delay, $pipe, $find, $repeat, $input =~ s/^ +| +$//r); } sub play { @@ -76,7 +80,7 @@ sub cmd_play { return weechat::WEECHAT_RC_OK; } - my ($delay, $pipe, $find, $file) = parse($_[2]); + my ($delay, $pipe, $find, $repeat, $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"), @@ -98,11 +102,12 @@ sub cmd_play { if ($path = $path->match and open FH, "<", (($file !~ m"/") ? $path : weechat::config_get_plugin('dir')."/$file")) { - while () { - s/[\r\n]*$//; - push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f"; - } + my @lines; + push @lines, s/[\r\n]*$//r while ; close FH; + for (1 .. $repeat) { + push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f" for @lines; + } weechat::unhook($timer{$buffer}) if exists $timer{$buffer}; $timer{$buffer} =