From 29c6145d6958b3ca42c74db463985dbd02fe0383 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 16 Feb 2012 22:15:17 -0600 Subject: more accurate method for filtering out echos it's not great, because it requires us passing in the bot account's actual email, since there's no way to query for "who are we?" in the current api. best we can do for now though. --- lib/Bot/Flowdock/IRC.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Bot/Flowdock/IRC.pm b/lib/Bot/Flowdock/IRC.pm index e0e80ea..fb9c1ea 100644 --- a/lib/Bot/Flowdock/IRC.pm +++ b/lib/Bot/Flowdock/IRC.pm @@ -12,10 +12,19 @@ extends 'Bot::BasicBot'; sub FOREIGNBUILDARGS { my $class = shift; my (%args) = @_; - delete $args{$_} for qw(token key organization flow); + delete $args{$_} for qw(email token key organization flow); return %args; } +# XXX require this for now so that we can tell which account is the bot +# (to allow us to filter those out so we don't get echos) +# ideally, there would be a better way to detect this +has email => ( + is => 'ro', + isa => 'Str', + required => 1, +); + has token => ( is => 'ro', isa => 'Str', @@ -76,6 +85,11 @@ has _id_map => ( }, ); +has _my_id => ( + is => 'rw', + isa => 'Int', +); + sub connected { my $self = shift; @@ -86,6 +100,9 @@ sub connected { for my $user (@{ $flow->body->{users} }) { $self->_set_name_for_id($user->{id}, $user->{nick}); + if ($user->{email} eq $self->email) { + $self->_my_id($user->{id}); + } } } @@ -97,6 +114,8 @@ sub tick { last unless $event; + next if $event->{user} == $self->_my_id; + my $type = $event->{event}; if ($type eq 'message' || $type eq 'line') { -- cgit v1.2.3