78 lines
No EOL
2.4 KiB
Perl
78 lines
No EOL
2.4 KiB
Perl
package Bot::BasicBot::Pluggable::Module::MineCraftIRC;
|
|
|
|
use base 'Bot::BasicBot::Pluggable::Module';
|
|
use v5.10; # need perl 5.10 for this module, we use named captures
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Data::Dumper;
|
|
|
|
sub init {
|
|
my ($self) = @_;
|
|
$self->config({
|
|
MC_Speak => "<%U>%B",
|
|
MC_Join => "<%U> has joined the server.",
|
|
MC_Quit => "<%U> has quit the game.",
|
|
MC_Bot => "dirkocraft",
|
|
MC_Channel => "Minecraft",
|
|
});
|
|
|
|
my $userre = qr/(?<user>[\w\d_-]{1,16})/; # this may need to be changed as i find limits of the game's names
|
|
my $messre = qr/(?<body>.*)/;
|
|
|
|
$self->set(MC_Speak => "<%U>%B");
|
|
my $bodyre = $self->get("MC_Speak");
|
|
my $joinre = $self->get("MC_Join");
|
|
my $quitre = $self->get("MC_Quit");
|
|
|
|
# replace the %U and %B, may add more ass neccessary
|
|
for ($bodyre, $joinre, $quitre)
|
|
{
|
|
print "'$_' -> '";
|
|
s/%U/$userre/g;
|
|
s/%B/$messre/g;
|
|
|
|
print "$_'\n";
|
|
}
|
|
|
|
|
|
$self->set(bodyre => $bodyre); # always reset it on init
|
|
$self->set(joinre => $joinre); # always reset it on init
|
|
$self->set(quitre => $quitre); # always reset it on init
|
|
|
|
}
|
|
|
|
# override seen, so that we can prevent other modules from seeing this, this is on purpose since we're working on a bridge
|
|
sub seen {
|
|
my ($self, $message) = @_;
|
|
|
|
my $bot = $self->bot(); # get the bot so we can do this
|
|
|
|
if ($message->{who} eq $self->get("MC_Bot")) { # it's our bot
|
|
|
|
if ($message->{body} =~ $self->get("quitre")) { # a user has quit
|
|
my $newmsg = {who => $+{user}, channel => $self->get("MC_Channel")};
|
|
$bot->dispatch(chanpart=>$newmsg);
|
|
return 1; # return a non-null non-replyable value
|
|
}
|
|
elsif ($message->{body} =~ $self->get("joinre")) { # a user has joined
|
|
my $newmsg = {who => $+{user}, channel => $self->get("MC_Channel")};
|
|
$bot->dispatch(chanjoin=>$newmsg);
|
|
return 1;
|
|
}
|
|
elsif ($message->{body} =~ $self->get("bodyre")) { # a user has joined
|
|
print STDERR "MATCHED MESSAGE\n";
|
|
print STDERR Dumper(\%+);
|
|
my $newmsg = {who => $+{user}, channel => $self->get("MC_Channel"), body => $+{body},
|
|
raw_nick => $+{user}.'@minecraft.example.com', address => undef};
|
|
|
|
# we always act like we aren't addressed, i don't feel like recreating this at the moment
|
|
$bot->dispatch_priorities(said => $newmsg);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return; # we didn't see anything we need to interrupt
|
|
}
|
|
|
|
1; |