App-bsky
view release on metacpan or search on metacpan
lib/App/bsky.pm view on Meta::CPAN
GetOptionsFromArray( \@args, 'json!' => \my $json, 'cid=s' => \my $cid );
my $res = $bsky->deleteLike($uri);
$res || $res->throw;
$self->say( $json ? JSON::Tiny::to_json($res) : sprintf 'Removed like!' );
}
# TODO
method cmd_likes ( $uri, @args ) {
GetOptionsFromArray( \@args, 'json!' => \my $json );
my @likes;
my $cursor = ();
do {
my $likes = $bsky->at->get( 'app.bsky.feed.getLikes', { uri => $uri, limit => 100, cursor => $cursor } );
push @likes, @{ $likes->{likes} };
$cursor = $likes->{cursor};
} while ($cursor);
if ($json) {
$self->say( JSON::Tiny::to_json \@likes );
}
else {
$self->say(
'%s%s%s%s (%s)',
color('red'), $_->{actor}{handle},
color('reset'), defined $_->{actor}{displayName} ? ' [' . $_->{actor}{displayName} . ']' : '',
$_->{createdAt}
) for @likes;
lib/App/bsky.pm view on Meta::CPAN
method cmd_repost ($uri) {
my $res = $bsky->repost($uri);
$res // return;
$self->say( $res->{uri}->as_string );
}
# TODO
method cmd_reposts ( $uri, @args ) {
GetOptionsFromArray( \@args, 'json!' => \my $json );
my @reposts;
my $cursor = ();
do {
my $reposts = $bsky->at->get( 'app.bsky.feed.getRepostedBy', { uri => $uri, limit => 100, cursor => $cursor } );
push @reposts, @{ $reposts->{repostedBy} };
$cursor = $reposts->{cursor};
} while ($cursor);
if ($json) {
$self->say( JSON::Tiny::to_json \@reposts );
}
else {
$self->say( '%s%s%s%s', color('red'), $_->{handle}, color('reset'), defined $_->{displayName} ? ' [' . $_->{displayName} . ']' : '' )
for @reposts;
}
scalar @reposts;
}
lib/App/bsky.pm view on Meta::CPAN
my $profile = $bsky->getProfile($actor);
my $uri = $profile->{viewer}{following} // return $self->err("You are not following $actor");
$bsky->deleteFollow($uri);
$self->say("Unfollowed $actor");
}
# TODO
method cmd_follows (@args) {
GetOptionsFromArray( \@args, 'json!' => \my $json, 'handle|H=s' => \my $handle );
my @follows;
my $cursor = ();
do {
my $follows = $bsky->at->get( 'app.bsky.graph.getFollows',
{ actor => $handle // $config->{session}{handle}, limit => 100, cursor => $cursor } );
push @follows, @{ $follows->{follows} };
$cursor = $follows->{cursor};
} while ($cursor);
if ($json) {
$self->say( JSON::Tiny::to_json \@follows );
}
else {
for my $follow (@follows) {
$self->say(
sprintf '%s%s%s%s %s%s%s',
color('red'), $follow->{handle}, color('reset'), defined $follow->{displayName} ? ' [' . $follow->{displayName} . ']' : '',
color('blue'), $follow->{did}, color('reset')
);
}
}
return scalar @follows;
}
method cmd_followers (@args) {
GetOptionsFromArray( \@args, 'json!' => \my $json, 'handle|H=s' => \my $handle );
my @followers;
my $cursor = ();
do {
my $followers = $bsky->at->get( 'app.bsky.graph.getFollowers',
{ actor => $handle // $config->{session}{handle}, limit => 100, cursor => $cursor } );
$followers // last;
if ( defined $followers->{followers} ) {
push @followers, @{ $followers->{followers} };
$cursor = $followers->{cursor};
}
} while ($cursor);
if ($json) {
$self->say( JSON::Tiny::to_json [ map {$_} @followers ] );
}
else {
my $len1 = my $len2 = 0;
for (@followers) {
$len1 = length( $_->{handle} ) if length( $_->{handle} ) > $len1;
$len2 = length( $_->{displayName} ) if length( $_->{displayName} ) > $len2;
}
for my $follower (@followers) {
lib/App/bsky.pm view on Meta::CPAN
my $profile = $bsky->getProfile($actor);
my $uri = $profile->{viewer}{blocking} // return $self->err("You are not blocking $actor");
$bsky->deleteBlock($uri);
$self->say("Unblocked $actor");
}
# TODO
method cmd_blocks (@args) {
GetOptionsFromArray( \@args, 'json!' => \my $json );
my @blocks;
my $cursor = ();
do {
my $follows = $bsky->at->get( 'app.bsky.graph.getBlocks', { limit => 100, cursor => $cursor } );
push @blocks, @{ $follows->{blocks} };
$cursor = $follows->{cursor};
} while ($cursor);
if ($json) {
$self->say( JSON::Tiny::to_json \@blocks );
}
else {
for my $follow (@blocks) {
$self->say(
sprintf '%s%s%s%s %s%s%s',
color('red'), $follow->{handle}, color('reset'), defined $follow->{displayName} ? ' [' . $follow->{displayName} . ']' : '',
color('blue'), $follow->{did}, color('reset')
);
lib/App/bsky.pm view on Meta::CPAN
}
method cmd_notifications (@args) {
GetOptionsFromArray( \@args, 'all|a' => \my $all, 'json!' => \my $json );
if ( !$all ) {
my $notification_count = $bsky->at->get('app.bsky.notification.getUnreadCount');
$notification_count || $notification_count->throw;
return $self->say( $json ? '[]' : 'No unread notifications' ) unless $notification_count->{count};
}
my @notes;
my $cursor = ();
do {
my $notes = $bsky->at->get( 'app.bsky.notification.listNotifications', { limit => 100, cursor => $cursor } );
$notes || $notes->throw;
push @notes, @{ $notes->{notifications} };
$cursor = $all && $notes->{cursor} ? $notes->{cursor} : ();
} while ($cursor);
return $self->say( JSON::Tiny::to_json [ map {$_} @notes ] ) if $json;
return $self->say('No notifications.') unless @notes;
for my $note (@notes) {
$self->say(
'%s%s%s%s %s', color('red'), $note->{author}{handle},
color('reset'),
defined $note->{author}{displayName} ? ' [' . $note->{author}{displayName} . ']' : '',
$note->{author}{did}
);
$self->say(
( run in 0.990 second using v1.01-cache-2.11-cpan-437f7b0c052 )