summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-02-16 22:15:17 -0600
committerJesse Luehrs <doy@tozt.net>2012-02-16 22:20:38 -0600
commit29c6145d6958b3ca42c74db463985dbd02fe0383 (patch)
tree6679c847e395778aaa2c2ee44949eb6046fc3fe6
parent147b1a95197ff89a5587c8b4c8b6bb5553de9372 (diff)
downloadbot-flowdock-irc-29c6145d6958b3ca42c74db463985dbd02fe0383.tar.gz
bot-flowdock-irc-29c6145d6958b3ca42c74db463985dbd02fe0383.zip
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.
-rw-r--r--lib/Bot/Flowdock/IRC.pm21
1 files changed, 20 insertions, 1 deletions
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') {