Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /twitter_info #20

Closed
wants to merge 13 commits into from
3 changes: 3 additions & 0 deletions html/using.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ <h3>Other Commands</h3>
posts by username, even for people who you do not follow</li>
<li><code>/twitter_del_follow_extra &lt;username&gt;</code> - Stop showing
all the posts by username</li>
<li><code>/twitter_info &lt;username&gt;:&lt;num&gt;</code> - Show infos about
a remembered tweets. Only 100 are remembered for each user, and this can be
completely disabled by changing the twirssi_track_replies variable.</li>
<li><code>/twitter_list_follow_extra</code> - Show the list of all the
usernames in the extra follow loop</li>
<li><code>/twitter_list_subscriptions</code> - List all the existing search
Expand Down
120 changes: 103 additions & 17 deletions twirssi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,73 @@ sub cmd_broadcast {
}
}

sub cmd_info {
my ( $data, $server, $win ) = @_;

$data =~ s/^\s+|\s+$//;
unless ( $data ) {
&notice( ["info"], "Usage: /twitter_info <nick[:num]>" );
return;
}

$data =~ s/[^\w\d\-:]+//g;
my ( $nick_orig, $id ) = split /:/, $data;
my $nick = lc $nick_orig;
unless ( exists $state{ $nick } ) {
&notice( [ "info" ],
"Can't find any tweet from $nick_orig!" );
return;
}

$id = $state{__indexes}{$nick_orig} unless $id;
my $statusid = $state{$nick}[$id];
unless ( $statusid ) {
&notice( [ "info" ],
"Can't find a tweet numbered $id from $nick_orig!" );
return;
}

my $account = $state{__accounts}{$nick}[$id];
my $service = $state{__services}{$nick}[$id];
# my $timestamp = $state{__created_ats}{$nick}[$id];
my $tweet = $state{__tweets}{$nick}[$id];
my $reply_to_id = $state{__reply_to_ids}{$nick}[$id];
my $reply_to_user = $state{__reply_to_users}{$nick}[$id];
my $type = $state{__types}{$nick}[$id];

&notice( [ "info" ], ",---------" );
&notice( [ "info" ], "| nick: $nick_orig" );
&notice( [ "info" ], "| id: $statusid" );
&notice( [ "info" ], "| type: " . ($type ? $type : '<unknown>') );
# &notice( [ "info" ], "| time: " . ($timestamp ? DateTime->from_epoch( epoch => $timestamp ) : '<unknown>') );
&notice( [ "info" ], "| account: " . ($account ? $account : '<unknown>' ) );
&notice( [ "info" ], "| text: " . ($tweet ? $tweet : '<unknown>' ) );

if ( $service ) {
&notice( [ "info" ], "| Service: $service" );
if ( $service eq 'Twitter' ) {
&notice( [ "info" ], "| URL: http://twitter.com/$nick_orig/statuses/$statusid" );
} elsif ( $service eq 'Identica') {
&notice( [ "info" ], "| URL: http://identi.ca/notice/$statusid" );
} else {
&notice( [ "info" ], "| URL: <unknown>" );
}
} else {
&notice( [ "info" ], "| Service: <unknown>" );
&notice( [ "info" ], "| URL: <unknown>" );
}

if ($reply_to_id and $reply_to_user) {
if ( $service eq 'Twitter' ) {
&notice( [ "info" ], "| ReplyTo: http://twitter.com/$reply_to_user/statuses/$reply_to_id" );
} elsif ( $service eq 'Identica') {
&notice( [ "info" ], "| ReplyTo: http://identi.ca/notice/$reply_to_id" );
}
}
&notice( [ "info" ], "`---------" );

}

sub cmd_reply {
my ( $data, $server, $win ) = @_;

Expand Down Expand Up @@ -1139,6 +1206,20 @@ sub load_friends {
return ( $added, $removed );
}

sub get_reply_to {
# extract reply-to-information from tweets
my $t = shift;

if ($t->{in_reply_to_screen_name}
and $t->{in_reply_to_status_id}) {
return sprintf 'reply_to_user:%s reply_to_id:%s ',
$t->{in_reply_to_screen_name},
$t->{in_reply_to_status_id};
} else {
return '';
}
}

sub get_updates {
print scalar localtime, " - get_updates starting" if &debug;

Expand Down Expand Up @@ -1323,8 +1404,8 @@ sub do_updates {
next
if $t->{user}{screen_name} eq $username
and not $settings{own_tweets};
printf $fh "id:%s account:%s nick:%s type:%s %s\n",
$t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
printf $fh "id:%s account:%s %snick:%s type:%s %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{user}{screen_name}, $reply, $text;
$new_poll_id = $t->{id} if $new_poll_id < $t->{id};
}
printf $fh "id:%s account:%s type:last_id timeline\n",
Expand Down Expand Up @@ -1355,8 +1436,8 @@ sub do_updates {
if exists $friends{ $t->{user}{screen_name} };

my $text = &get_text( $t, $obj );
printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
$t->{id}, $username, $t->{user}{screen_name}, $text;
printf $fh "id:%s account:%s %snick:%s type:tweet %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{user}{screen_name}, $text;
$new_poll_id = $t->{id} if $new_poll_id < $t->{id};
}
printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
Expand All @@ -1382,8 +1463,8 @@ sub do_updates {
foreach my $t ( reverse @$tweets ) {
my $text = decode_entities( $t->{text} );
$text =~ s/[\n\r]/ /g;
printf $fh "id:%s account:%s nick:%s type:dm %s\n",
$t->{id}, $username, $t->{sender_screen_name}, $text;
printf $fh "id:%s account:%s %snick:%s type:dm %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{sender_screen_name}, $text;
$new_poll_id = $t->{id} if $new_poll_id < $t->{id};
}
printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
Expand Down Expand Up @@ -1422,8 +1503,8 @@ sub do_updates {

foreach my $t ( reverse @{ $search->{results} } ) {
my $text = &get_text( $t, $obj );
printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
$t->{id}, $username, $t->{from_user}, $topic, $text;
printf $fh "id:%s account:%s %snick:%s type:search topic:%s %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{from_user}, $topic, $text;
$new_poll_id = $t->{id}
if not $new_poll_id
or $t->{id} < $new_poll_id;
Expand Down Expand Up @@ -1464,8 +1545,8 @@ sub do_updates {

my $text = &get_text( $t, $obj );
printf $fh
"id:%s account:%s nick:%s type:search_once topic:%s %s\n",
$t->{id}, $username, $t->{from_user}, $topic, $text;
"id:%s account:%s %snick:%s type:search_once topic:%s %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{from_user}, $topic, $text;
}
}
}
Expand Down Expand Up @@ -1525,14 +1606,14 @@ sub get_timeline {

if ($context) {
my $ctext = &get_text( $context, $obj );
printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
$context->{id}, $username,
printf $fh "id:%s account:%s %snick:%s type:tweet %s\n",
$context->{id}, $username, &get_reply_to($context),
$context->{user}{screen_name}, $ctext;
$reply = "reply";
}
}
printf $fh "id:%s account:%s nick:%s type:%s %s\n",
$t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
printf $fh "id:%s account:%s %snick:%s type:%s %s\n",
$t->{id}, $username, &get_reply_to($t), $t->{user}{screen_name}, $reply, $text;
$last_id = $t->{id} if $last_id < $t->{id};
}
printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
Expand Down Expand Up @@ -1570,16 +1651,17 @@ sub monitor_child {
my $hilight = 0;
my %meta;

foreach my $key (qw/id account nick type topic/) {
foreach my $key (qw/id account reply_to_user reply_to_id nick type topic/) {
if (s/^$key:((?:\S|\\ )+)\s*//) {
$meta{$key} = $1;
$meta{$key} =~ s/%20/ /g;
}
}

# avoid internal breakage by sneaky nicknames
# to be added: created_ats
next if ($meta{nick} and $meta{nick} =~
/^__(indexes|windows|searches|fixreplies|tweets|last_tweet|last_id)$/);
/^__(indexes|windows|searches|fixreplies|tweets|last_tweet|last_id|accounts|services|reply_to_users|reply_to_ids|types)$/);

if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
$fix_replies_index{ $meta{account} } = $meta{id};
Expand Down Expand Up @@ -1617,6 +1699,9 @@ sub monitor_child {
$state{ lc $meta{nick} }[$marker] = $meta{id};
$state{__indexes}{ $meta{nick} } = $marker;
$state{__tweets}{ lc $meta{nick} }[$marker] = $_;
foreach my $key (qw/account service reply_to_id reply_to_user type/) { # created_at
$state{"__${key}s"}{ lc $meta{nick} }[$marker] = $meta{$key};
}
$marker = ":$marker";
}

Expand Down Expand Up @@ -1935,7 +2020,7 @@ sub sig_complete {

if (
$linestart =~
m{^/twitter_delete\s*$|^/(?:retweet|twitter_reply)(?:_as)?\s*$}
m{^/twitter_(?:delete|info)\s*$|^/(?:retweet|twitter_reply)(?:_as)?\s*$}
or ( $settings{use_reply_aliases}
and $linestart =~ /^\/reply(?:_as)?\s*$/ )
)
Expand Down Expand Up @@ -2276,6 +2361,7 @@ sub window_to_account {
Irssi::command_bind( "retweet", "cmd_retweet" );
Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
Irssi::command_bind( "twitter_broadcast", "cmd_broadcast" );
Irssi::command_bind( "twitter_info", "cmd_info" );
Irssi::command_bind( "twitter_reply", "cmd_reply" );
Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
Irssi::command_bind( "twitter_login", "cmd_login" );
Expand Down