forked from GunioRobot/wubot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a plugin to capture firefox bookmarks
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package App::Wubot::Plugin::FirefoxBookmarks; | ||
use Moose; | ||
|
||
# VERSION | ||
|
||
use YAML::XS; | ||
|
||
use App::Wubot::Logger; | ||
use App::Wubot::SQLite; | ||
|
||
with 'App::Wubot::Plugin::Roles::Cache'; | ||
with 'App::Wubot::Plugin::Roles::Plugin'; | ||
|
||
|
||
sub check { | ||
my ( $self, $inputs ) = @_; | ||
|
||
my $config = $inputs->{config}; | ||
my $cache = $inputs->{cache}; | ||
|
||
my $db = $config->{database}; | ||
|
||
unless ( $db ) { | ||
$self->logger->logdie( "ERROR: no database found in config" ); | ||
} | ||
|
||
unless ( -r $db ) { | ||
$self->logger->logdie( "ERROR: database does not exist: $db" ); | ||
} | ||
|
||
my $sqlite = App::Wubot::SQLite->new( { file => $db } ); | ||
|
||
my @react; | ||
|
||
$sqlite->select( { tablename => 'moz_bookmarks LEFT JOIN moz_places ON moz_bookmarks.fk = moz_places.id', | ||
schema => {}, | ||
callback => sub { | ||
my $entry = shift; | ||
|
||
return unless $entry->{url}; | ||
return unless $entry->{url} =~ m|^http|g; | ||
|
||
# if we've already seen this item, move along | ||
if ( $self->cache_is_seen( $cache, $entry->{url} ) ) { | ||
$self->logger->trace( "Already seen: ", $entry->{url} ); | ||
|
||
# touch cache time on this subject | ||
$self->cache_mark_seen( $cache, $entry->{url} ); | ||
|
||
return; | ||
} | ||
|
||
# keep track of this item so we don't fetch it again | ||
$self->cache_mark_seen( $cache, $entry->{url} ); | ||
|
||
my $react; | ||
|
||
$react->{link} = $entry->{url}; | ||
$react->{subject} = $entry->{title}; | ||
|
||
push @react, $react; | ||
}, | ||
} ); | ||
|
||
$self->cache_expire( $cache ); | ||
|
||
return { cache => $cache, react => \@react }; | ||
} | ||
|
||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
App::Wubot::Plugin::FirefoxBookmarks - monitor for new firefox bookmarks | ||
=head1 DESCRIPTION | ||
This plugin connects to the firefox 'places' sqlite database and | ||
retrieves the bookmarks. It caches bookmarks that have previously | ||
been seen, so only new bookmarks trigger event messages. | ||
This plugin uses the wubot caching mechanism, so that messages are | ||
only sent when a new URL is found in your bookmarks. | ||
=head1 SUBROUTINES/METHODS | ||
=over 8 | ||
=item check( $inputs ) | ||
The standard monitor check() method. | ||
=back |