shithead-ng/MarkovBot.pl

60 lines
1.2 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;
2016-07-04 19:41:12 +02:00
my $command_char = config "command_character";
2016-04-30 23:53:26 +02:00
# Ignore PMs and ignored users
return if $msg->{channel} eq 'msg';
return if isIgnored($msg->{who});
# Intercept commands
2016-07-04 19:41:12 +02:00
if ($msg->{body} =~ m/^$command_char.+/) {
2016-04-30 23:53:26 +02:00
my $command = $msg->{body};
my @command = split(" ", $command);
my $bare = $command[0];
2016-07-04 19:41:12 +02:00
$bare =~ s/^$command_char//;
2016-04-30 23:53:26 +02:00
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();