markov chain shitpost generation

This commit is contained in:
Al Beano 2016-07-04 21:03:09 +01:00
parent 26545d3235
commit d0c30f9634
2 changed files with 29 additions and 0 deletions

View File

@ -13,11 +13,15 @@ use MarkovBot::Config;
use MarkovBot::Learning;
use MarkovBot::Ignore;
use MarkovBot::Commands;
use MarkovBot::MarkovChain;
use MarkovBot::Redis;
sub said {
my $self = shift;
my $msg = shift;
my $command_char = quotemeta config "command_character";
my $redis = redis();
my $redis_prefix = config("redis_prefix");
# Ignore PMs and ignored users
return if $msg->{channel} eq 'msg';
@ -38,6 +42,23 @@ sub said {
$self->say( channel => config("irc_channel"), body => $ret ) unless $ret eq "___null___";
}
return;
}
my $chattiness = $redis->get("$redis_prefix:chattiness");
if (rand 100 < $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]] );
$resp = config("insult") unless $resp;
$self->say(
channel => config("irc_channel"),
body => $resp,
);
}
# Learn
@ -45,6 +66,13 @@ sub said {
}
# Set base chattiness value on first run
my $redis = redis();
my $p = config("redis_prefix");
if (!$redis->get("$p:chattiness")) {
$redis->set("$p:chattiness", 10);
}
MarkovBot->new(
server => config("irc_server"),

View File

@ -2,6 +2,7 @@
# General settings
#
command_character: "."
insult: "you're a faggot"
#
# Redis Settings