adding seen code

This commit is contained in:
Ryan Voots 2011-06-21 23:41:08 -04:00
parent ff39c6d01c
commit ee667b15d9
2 changed files with 32 additions and 3 deletions

View file

@ -70,7 +70,7 @@ sub optipeep {
my $l = length($input);
print "CHECKING $input $peep\n";
#print "CHECKING $input $peep\n";
my $min = [length($peep)*10, $peep]; # set maxes
for my $p (0..length($peep)-length($input)) {
@ -85,6 +85,15 @@ sub optipeep {
return $min
}
sub get_seen {
my ($self, $user) = @_;
my $seen = $self->bot->module("Seen");
my $out = $seen->told("seen ".$user);
return $out;
}
sub get_player_pos {
my ($user) = @_;
@ -109,7 +118,7 @@ sub get_player_pos {
my @peeps = keys %{$playerstate->{players}};
my $peep = reduce {$a->[0] > $b->[0] ? $b : $a} map {optipeep($_, $user)} @peeps;
print Dumper($peep);
#print Dumper($peep);
$user = $peep->[1] if ($peep->[0] < 5); # don't set it if it's too large
if (exists($playerstate->{players}{lc $user})) { # we know where that user was
@ -175,6 +184,7 @@ sub told {
sub fallback {
my ( $self, $mess ) = @_;
my $seen = $self->bot->module("Seen");
my $body = $mess->{body} || "";
my $is_priv = !defined $mess->{channel} || $mess->{channel} eq 'msg';
@ -185,11 +195,28 @@ sub fallback {
$user = $1;
}
#23:05:18 < dirkocraft> [XmasPteradactyl disconnected]
#23:05:21 < dirkocraft> [CaveScavenger disconnected]
if ($mess->{who} =~ /^dirkocraft\d*$/ && $body =~ /\[(\S+) disconnected\]/) {
$seen->update_seen($1, "Minecraft", "losing the game");
}
elsif ($mess->{who} =~ /^dirkocraft\d*$/ && $body =~ /\[(\S+) connected\]/) {
$seen->update_seen($1, "Minecraft", "winning the game")
}
else {
$seen->update_seen($user, "Minecraft", "saying '".$body."'"); # update people!
}
if ($body =~ /^!coords\s+(.*)/i) { # TODO ok this isn't robust, but it'll work for now
$user = $1;
$body = "!coords"; # rewrite the body
};
if ($body =~ /^!seen\s+(.*)/i) { # TODO ok this isn't robust, but it'll work for now
$user = $1;
$body = "!seen"; # rewrite the body
};
# request starts with "my", so we'll look for
# a valid factoid for "$mess->{who}'s $object".
$body =~ s/^my /$mess->{who}'s /;
@ -237,6 +264,7 @@ sub fallback {
$factoid =~ s/\$who/$mess->{who}/ig;
$factoid =~ s/\$coords/get_player_pos($user)/eig;
$factoid =~ s/\$seen/get_seen($self,$user)/eig;
if ($factoid =~ /\$alert\$/i && $mess->{channel} =~ /dirkocraft$/i) { # if we see $ALERT$ and we're in the main channel
$mess->{channel} = "#dirkocraft-alert";

View file

@ -21,6 +21,7 @@ my $bot = Bot::BasicBot::Pluggable->new(
);
my $info = $bot->load("DirkMod");
my $seen = $bot->load("Seen");
$info->set(user_require_question => 0);
$info->set(user_passive_answer => 1);
$info->set(user_allow_searching =>1);