From e1c81a249de8a939aed8ab4d0ea55d5acde6313c Mon Sep 17 00:00:00 2001 From: Al Beano Date: Sat, 3 Sep 2016 12:10:43 +0100 Subject: [PATCH] multiple tries to generate shitpost --- MarkovBot.pl | 24 +++++++++++++++++++++--- README.md | 4 ++++ config.default.yml | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/MarkovBot.pl b/MarkovBot.pl index 35edfd2..e3c7fe6 100644 --- a/MarkovBot.pl +++ b/MarkovBot.pl @@ -18,6 +18,11 @@ use MarkovBot::Redis; use Encode qw(encode decode); use if (config("rng") eq "mt"), "Math::Random::MT::Perl" => qw(rand); +sub wordsin { + my $str = shift; + return scalar(split(" ", $str)); +} + sub said { my $self = shift; my $msg = shift; @@ -47,6 +52,8 @@ sub said { return; } + + # Cheap autocomplete system if ($msg->{body} =~ m/^(wew|lad)$/i) { my $ret; my @o = split("", $msg->{"body"}); @@ -69,14 +76,25 @@ sub said { body => "lmao", ); } + my $chattiness = $redis->get("$redis_prefix:chattiness"); my $rand = rand 100; if ($rand < $chattiness) { # generate a shitpost my @line = split " ", $msg->{body}; - return unless scalar(@line) > 1; - my $start = int rand $#line; - my $resp = markov( [$line[$start], $line[$start+1]] ); + return unless scalar(@line) >= 2; + + # Generate the best shitpost we can + my $resp; + for (1..20) { + my $start = int rand $#line; + my $post = markov( [$line[$start], $line[$start+1]] ); + $post = "" if !$post; + $resp = $post if !$resp; + last if wordsin($post) >= config("target_words"); + $resp = $post if wordsin($post) > wordsin($resp); + } + if (rand() * 100 < config("insult_chance") && !$resp) { $resp = config("insult"); } diff --git a/README.md b/README.md index 7de3ce6..8279b4c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +## important + +shithead-ng has a new config option: target_words. Please see config.default.yml and update your config.yml accordingly. Without this parameter, shithead-ng will not work! + # shithead-ng next generation markov chain irc shitposting bot diff --git a/config.default.yml b/config.default.yml index be889e3..27d874b 100644 --- a/config.default.yml +++ b/config.default.yml @@ -5,6 +5,7 @@ command_character: "." insult: "you're a faggot" insult_chance: 2 # % chance that the bot will use the insult # can be 0 to disable insults +target_words: 4 # lowest number of words in an 'ideal' response # # Redis Settings