multiple tries to generate shitpost

This commit is contained in:
Al Beano 2016-09-03 12:10:43 +01:00
parent 32c3328d2e
commit e1c81a249d
3 changed files with 26 additions and 3 deletions

View File

@ -18,6 +18,11 @@ use MarkovBot::Redis;
use Encode qw(encode decode); use Encode qw(encode decode);
use if (config("rng") eq "mt"), "Math::Random::MT::Perl" => qw(rand); use if (config("rng") eq "mt"), "Math::Random::MT::Perl" => qw(rand);
sub wordsin {
my $str = shift;
return scalar(split(" ", $str));
}
sub said { sub said {
my $self = shift; my $self = shift;
my $msg = shift; my $msg = shift;
@ -47,6 +52,8 @@ sub said {
return; return;
} }
# Cheap autocomplete system
if ($msg->{body} =~ m/^(wew|lad)$/i) { if ($msg->{body} =~ m/^(wew|lad)$/i) {
my $ret; my $ret;
my @o = split("", $msg->{"body"}); my @o = split("", $msg->{"body"});
@ -69,14 +76,25 @@ sub said {
body => "lmao", body => "lmao",
); );
} }
my $chattiness = $redis->get("$redis_prefix:chattiness"); my $chattiness = $redis->get("$redis_prefix:chattiness");
my $rand = rand 100; my $rand = rand 100;
if ($rand < $chattiness) { if ($rand < $chattiness) {
# generate a shitpost # generate a shitpost
my @line = split " ", $msg->{body}; my @line = split " ", $msg->{body};
return unless scalar(@line) > 1; return unless scalar(@line) >= 2;
my $start = int rand $#line;
my $resp = markov( [$line[$start], $line[$start+1]] ); # 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) { if (rand() * 100 < config("insult_chance") && !$resp) {
$resp = config("insult"); $resp = config("insult");
} }

View File

@ -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 # shithead-ng
next generation markov chain irc shitposting bot next generation markov chain irc shitposting bot

View File

@ -5,6 +5,7 @@ command_character: "."
insult: "you're a faggot" insult: "you're a faggot"
insult_chance: 2 # % chance that the bot will use the insult insult_chance: 2 # % chance that the bot will use the insult
# can be 0 to disable insults # can be 0 to disable insults
target_words: 4 # lowest number of words in an 'ideal' response
# #
# Redis Settings # Redis Settings