aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-10-26 18:03:42 +1300
committerDavid Phillips <david@sighup.nz>2019-10-26 18:04:53 +1300
commit2f0feee0d3e654d58fa5b7de3d53930783581605 (patch)
treead5dcec423196dfef01a8dfa1378af4a1ba188ae /Plugin
parentbc41a099b3f01c8ad646d2725ea27d99fa37eb87 (diff)
downloadidalius-2f0feee0d3e654d58fa5b7de3d53930783581605.tar.xz
Markov: Retry limited times if message isn't long enough
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Markov.pm30
1 files changed, 18 insertions, 12 deletions
diff --git a/Plugin/Markov.pm b/Plugin/Markov.pm
index 1733372..e29bb45 100644
--- a/Plugin/Markov.pm
+++ b/Plugin/Markov.pm
@@ -74,18 +74,24 @@ sub some
sub do_markov
{
- my $word = $_[0];
- $word = some(keys %markov_data) unless $word;
- my $message = "";
- my $i = 0;
- do {
- $i++;
- $message .= "$word ";
- $word = some(@{$markov_data{$word}});
- } until(not $word or $word eq "" or $i == 1000);
-
- return if scalar(split / /, $message) <= 2;
- return $message;
+ my $tries = 0;
+
+ while ($tries++ < 10) {
+ my $word = $_[0];
+ $word = some(keys %markov_data) unless $word;
+ my $message = "";
+ my $i = 0;
+ do {
+ $i++;
+ $message .= "$word ";
+ $word = some(@{$markov_data{$word}});
+ } until(not $word or $word eq "" or $i == 1000);
+
+ return $message if scalar(split / /, $message) > 2;
+ }
+
+ # fallthrough: didn't form a long enough message in enough tries
+ return;
}
sub markov_cmd