shithead-ng/MarkovBot.pl

59 lines
1.1 KiB
Perl
Raw Normal View History

2016-04-30 23:53:26 +02:00
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use FindBin qw($Bin);
use lib $Bin;
package MarkovBot;
use base qw/Bot::BasicBot/;
use MarkovBot::Config;
use MarkovBot::Learning;
use MarkovBot::Ignore;
use MarkovBot::Commands;
sub said {
my $self = shift;
my $msg = shift;
# Ignore PMs and ignored users
return if $msg->{channel} eq 'msg';
return if isIgnored($msg->{who});
# Intercept commands
if ($msg->{body} =~ m/^\.\w+/) {
my $command = $msg->{body};
my @command = split(" ", $command);
my $bare = $command[0];
$bare =~ s/^\.//;
my %subs = %{getCommandSubs()};
if (defined $subs{$bare}) {
my $ret = $subs{$bare}->(\@command);
$self->say( channel => config("irc_channel"), body => $ret ) unless $ret eq "___null___";
}
}
# Learn
learn $msg->{body};
}
MarkovBot->new(
server => config("irc_server"),
port => config("irc_port"),
channels => [config("irc_channel")],
nick => config("irc_nickname"),
alt_nicks => [config("irc_nickname2")],
username => config("irc_nickname"),
name => config("irc_nickname"),
)->run();