| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use open ':std', ':encoding(UTF-8)'; |
| 6 |
|
| 7 |
use Mastodon::Listener; |
| 8 |
|
| 9 |
my $access_token = shift |
| 10 |
or die "You must pass an access token as the first argument\n"; |
| 11 |
|
| 12 |
my $listener = Mastodon::Listener->new( |
| 13 |
url => 'https://botsin.space/api/v1/streaming/public', |
| 14 |
access_token => $ARGV[0], |
| 15 |
coerce_entities => 1, |
| 16 |
); |
| 17 |
|
| 18 |
$listener->on( error => sub { |
| 19 |
my ( undef, undef, $msg ) = @_; |
| 20 |
warn $msg; |
| 21 |
}); |
| 22 |
|
| 23 |
$listener->on( update => sub { |
| 24 |
my ( undef, $status ) = @_; |
| 25 |
printf "%s said: %s\n\n", |
| 26 |
$status->account->display_name, |
| 27 |
$status->content; |
| 28 |
}); |
| 29 |
|
| 30 |
$listener->start; |