play.pl: -repeat

This commit is contained in:
wowaname 2016-10-02 21:53:44 +00:00
parent 851f1f62a7
commit 1158390ac5
1 changed files with 17 additions and 12 deletions

View File

@ -5,7 +5,7 @@ no strict 'subs';
my $SCRIPT_NAME = 'play';
my $SCRIPT_AUTHOR = 'The Krusty Krab <wowaname@volatile.ch>';
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 (<FH>) {
s/[\r\n]*$//;
push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f";
}
my @lines;
push @lines, s/[\r\n]*$//r while <FH>;
close FH;
for (1 .. $repeat) {
push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f" for @lines;
}
weechat::unhook($timer{$buffer}) if exists $timer{$buffer};
$timer{$buffer} =