multiple tries to generate shitpost
This commit is contained in:
parent
32c3328d2e
commit
e1c81a249d
24
MarkovBot.pl
24
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");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue