play.pl: -repeat
This commit is contained in:
parent
851f1f62a7
commit
1158390ac5
@ -5,7 +5,7 @@ no strict 'subs';
|
|||||||
|
|
||||||
my $SCRIPT_NAME = 'play';
|
my $SCRIPT_NAME = 'play';
|
||||||
my $SCRIPT_AUTHOR = 'The Krusty Krab <wowaname@volatile.ch>';
|
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_LICENCE = 'Public domain';
|
||||||
my $SCRIPT_DESC = 'Play ASCII art';
|
my $SCRIPT_DESC = 'Play ASCII art';
|
||||||
our (%queue, %timer);
|
our (%queue, %timer);
|
||||||
@ -36,26 +36,30 @@ if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub parse {
|
sub parse {
|
||||||
my ($input, $delay, $pipe, $find) =
|
my ($input, $delay, $pipe, $find, $repeat) =
|
||||||
(shift, weechat::config_get_plugin('delay'), '/msg *', 0);
|
(shift, weechat::config_get_plugin('delay'), '/msg *', 0, 1);
|
||||||
|
|
||||||
if ($input =~ / *-delay +([0-9]+) /) {
|
if ($input =~ / *-delay +([0-9]+) /) {
|
||||||
$delay = $1;
|
$delay = $1;
|
||||||
$input =~ s/ *-delay +[0-9]+ *//;
|
$input =~ s/-delay +[0-9]+//;
|
||||||
}
|
}
|
||||||
if ($input =~ / *-find /) {
|
if ($input =~ / *-find /) {
|
||||||
$find = 1;
|
$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.
|
# greedy match within quotes so we don't need to escape quotes.
|
||||||
# i don't think we will be affected negatively by this
|
# i don't think we will be affected negatively by this
|
||||||
if ($input =~ / *-pipe +(".+"|[^ ]+) /) {
|
if ($input =~ / *-pipe +(".+"|[^ ]+) /) {
|
||||||
$pipe = $1;
|
$pipe = $1;
|
||||||
$pipe =~ s/^"(.+)"$/$1/ if $pipe =~ /^".+"$/;
|
$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 {
|
sub play {
|
||||||
@ -76,7 +80,7 @@ sub cmd_play {
|
|||||||
return weechat::WEECHAT_RC_OK;
|
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 $server = weechat::info_get($buffer, 'localvar_server');
|
||||||
my ($prio_s, $prio_d) = (
|
my ($prio_s, $prio_d) = (
|
||||||
weechat::config_get("irc.server.$server.anti_flood_prio_high"),
|
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 :
|
if ($path = $path->match and open FH, "<", (($file !~ m"/") ? $path :
|
||||||
weechat::config_get_plugin('dir')."/$file")) {
|
weechat::config_get_plugin('dir')."/$file")) {
|
||||||
while (<FH>) {
|
my @lines;
|
||||||
s/[\r\n]*$//;
|
push @lines, s/[\r\n]*$//r while <FH>;
|
||||||
push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f";
|
|
||||||
}
|
|
||||||
close FH;
|
close FH;
|
||||||
|
for (1 .. $repeat) {
|
||||||
|
push @{ $queue{$buffer} }, "$pipe \x0f$_\x0f" for @lines;
|
||||||
|
}
|
||||||
|
|
||||||
weechat::unhook($timer{$buffer}) if exists $timer{$buffer};
|
weechat::unhook($timer{$buffer}) if exists $timer{$buffer};
|
||||||
$timer{$buffer} =
|
$timer{$buffer} =
|
||||||
|
Loading…
Reference in New Issue
Block a user