Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'zigdon_master'
  • Loading branch information
gedge committed Feb 14, 2012
2 parents 406961f + a022057 commit 988e398
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
5 changes: 5 additions & 0 deletions html/history.html
Expand Up @@ -6,6 +6,11 @@
can also upgrade a running twirssi install by setting can also upgrade a running twirssi install by setting
<code>twirssi_upgrade_beta</code> to true, and using <code>/twirssi_upgrade</code>.</em></li> <code>twirssi_upgrade_beta</code> to true, and using <code>/twirssi_upgrade</code>.</em></li>
</ul></li> </ul></li>
<li><strong>v2.5.2beta</strong><br /><ul>
<li><em>2012-02-14</em> <code>/twitter_user</code> - add -w flag</li>
<li><em>2012-02-09</em> <code>twitter_user_results</code> - new setting</li>
<li><em>2012-02-09</em> use 'since_id' for updates, thus reducing network/dups</li>
</ul></li>
<li><strong>v2.5.1 - 10:00 08-Feb-2012</strong><br /> <li><strong>v2.5.1 - 10:00 08-Feb-2012</strong><br />
<ul><li> <ul><li>
<li><em>2012-02-07</em> Fix: avoid re-reading temporary files (left by debugging)</li> <li><em>2012-02-07</em> Fix: avoid re-reading temporary files (left by debugging)</li>
Expand Down
9 changes: 7 additions & 2 deletions html/using.html
Expand Up @@ -82,8 +82,9 @@ <h3>Other Commands</h3>
all the posts by username</li> all the posts by username</li>
<li><code>/twitter_info &lt;username&gt;:&lt;num&gt;</code> - Show details about <li><code>/twitter_info &lt;username&gt;:&lt;num&gt;</code> - Show details about
a remembered tweet. See twirssi_track_replies variable.</li> a remembered tweet. See twirssi_track_replies variable.</li>
<li><code>/twitter_user &lt;username&gt;</code> - Get the recent timeline for <li><code>/twitter_user [<code>-w</code>] &lt;username&gt;</code> - Get the recent timeline
the username. Also used to obtain tweets so as to retweet them directly.</li> for the username (with <code>-w</code>, send their tweets to a window of the same name).
Also used to obtain tweets so as to retweet them directly.</li>
<li><code>/twitter_dms</code> - Get recent direct messages for the current user.</li> <li><code>/twitter_dms</code> - Get recent direct messages for the current user.</li>
<li><code>/twitter_dms_as &lt;account&gt;</code> - Use <code>/twitter_dms</code> <li><code>/twitter_dms_as &lt;account&gt;</code> - Use <code>/twitter_dms</code>
for &lt;account&gt;.</li> for &lt;account&gt;.</li>
Expand Down Expand Up @@ -188,6 +189,10 @@ <h3>Look-and-feel Settings</h3>
your own (non-classic) retweets in your timeline.</li> your own (non-classic) retweets in your timeline.</li>
<li><code>retweet_classic</code> - Default: Off. When set to On, a retweet <li><code>retweet_classic</code> - Default: Off. When set to On, a retweet
is a full tweet including the text of the original.</li> is a full tweet including the text of the original.</li>
<li><code>twitter_user_results</code> - Default: 200. Limit tweets shown
by <code>/twitter_user</code> or <code>/twitter_follow</code>.
Can be a number (of tweets, e.g. <code>20</code>; or of days, e.g. <code>21d</code>),
or both (e.g. <code>20 21d</code>, most restrictive wins).</li>
</ul> </ul>
<h3>Network and File Settings</h3> <h3>Network and File Settings</h3>
<ul> <ul>
Expand Down
52 changes: 36 additions & 16 deletions twirssi.pl
Expand Up @@ -17,7 +17,7 @@


use vars qw($VERSION %IRSSI); use vars qw($VERSION %IRSSI);


$VERSION = sprintf '%s', q$Version: v2.5.1$ =~ /^\w+:\s+v(\S+)/; $VERSION = sprintf '%s', q$Version: v2.5.2beta2$ =~ /^\w+:\s+v(\S+)/;
%IRSSI = ( %IRSSI = (
authors => 'Dan Boger', authors => 'Dan Boger',
contact => 'zigdon@gmail.com', contact => 'zigdon@gmail.com',
Expand All @@ -26,7 +26,7 @@
. 'Can optionally set your bitlbee /away message to same', . 'Can optionally set your bitlbee /away message to same',
license => 'GNU GPL v2', license => 'GNU GPL v2',
url => 'http://twirssi.com', url => 'http://twirssi.com',
changed => '$Date: 2012-02-07 22:34:25 +0000$', changed => '$Date: 2012-02-14 10:41:21 +0000$',
); );


my $twit; # $twit is current logged-in Net::Twitter object (usually one of %twits) my $twit; # $twit is current logged-in Net::Twitter object (usually one of %twits)
Expand Down Expand Up @@ -109,6 +109,7 @@
[ 'url_args', 'short_url_args', 's', undef ], [ 'url_args', 'short_url_args', 's', undef ],
[ 'window', 'twitter_window', 's', 'twitter' ], [ 'window', 'twitter_window', 's', 'twitter' ],
[ 'debug_win_name', 'twirssi_debug_win_name', 's', '' ], [ 'debug_win_name', 'twirssi_debug_win_name', 's', '' ],
[ 'limit_user_tweets', 'twitter_user_results', 's', '200' ],


[ 'always_shorten', 'twirssi_always_shorten', 'b', 0 ], [ 'always_shorten', 'twirssi_always_shorten', 'b', 0 ],
[ 'avoid_ssl', 'twirssi_avoid_ssl', 'b', 0 ], [ 'avoid_ssl', 'twirssi_avoid_ssl', 'b', 0 ],
Expand Down Expand Up @@ -393,6 +394,7 @@ sub cmd_retweet_to_window {


sub cmd_reload { sub cmd_reload {
if ($settings{force_first} and $settings{poll_store}) { if ($settings{force_first} and $settings{poll_store}) {
&save_state();
&save_polls(); &save_polls();
} }
Irssi::command("script load $IRSSI{name}"); Irssi::command("script load $IRSSI{name}");
Expand Down Expand Up @@ -664,7 +666,7 @@ sub gen_cmd {
return; return;
} }


&$post_ref($data) if $post_ref; &$post_ref($data, $server, $win) if $post_ref;
} }
} }


Expand Down Expand Up @@ -1707,7 +1709,11 @@ sub cmd_wipe {


sub cmd_user { sub cmd_user {
my $target = shift; my $target = shift;
my $server = shift;
my $win = shift;
$target =~ s/(?::\d+)?\s*$//; $target =~ s/(?::\d+)?\s*$//;
&cmd_set_window("sender $target $target", $server, $win)
if $target =~ s/^\s*-w\s+// and $target ne '';
&get_updates([ 0, [ &get_updates([ 0, [
[ "$user\@$defservice", { up_user => $target } ], [ "$user\@$defservice", { up_user => $target } ],
], ],
Expand Down Expand Up @@ -2050,15 +2056,14 @@ sub get_tweets {
return if &rate_limited($obj, $username, $fh); return if &rate_limited($obj, $username, $fh);


&debug($fh, "%G$username%n Polling for tweets"); &debug($fh, "%G$username%n Polling for tweets");
my $tweets; my $tweets = [];
my $new_poll_id = 0;
eval { eval {
my %call_attribs = ( page => 1 ); my %call_attribs = ( page => 1 );
$call_attribs{count} = $settings{track_replies} if $settings{track_replies}; $call_attribs{count} = $settings{track_replies} if $settings{track_replies};
# $call_attribs{since_id} = $state{__last_id}{$username}{timeline} $call_attribs{since_id} = $state{__last_id}{$username}{timeline}
# if defined $state{__last_id}{$username}{timeline}; if defined $state{__last_id}{$username}{timeline};
for ( ; $call_attribs{page} < 2 ; $call_attribs{page}++) { for ( ; $call_attribs{page} < 2 ; $call_attribs{page}++) {
&debug($fh, "%G$username%n timeline pg=" . $call_attribs{page}); &debug($fh, "%G$username%n timeline " . join(' ', map { $_ . '=' . $call_attribs{$_} } sort keys %call_attribs));
my $page_tweets = $obj->home_timeline( \%call_attribs ); my $page_tweets = $obj->home_timeline( \%call_attribs );
last if not defined $page_tweets or @$page_tweets == 0; last if not defined $page_tweets or @$page_tweets == 0;
unshift @$tweets, @$page_tweets; unshift @$tweets, @$page_tweets;
Expand All @@ -2071,6 +2076,9 @@ sub get_tweets {
return; return;
} }



=pod
unless ( ref $tweets ) { unless ( ref $tweets ) {
if ( $obj->can("get_error") ) { if ( $obj->can("get_error") ) {
my $error = "Unknown error"; my $error = "Unknown error";
Expand All @@ -2082,15 +2090,22 @@ sub get_tweets {
} else { } else {
&notice([ 'error', $username, $fh], &notice([ 'error', $username, $fh],
"$username: API Error during home_timeline call. Aborted."); "$username: API Error in home_timeline call. Aborted.");
} }
return; return;
} }
print $fh "t:debug %G$username%n got ", scalar(@$tweets), " tweets, first/last: ", =cut
(sort {$a->{id} <=> $b->{id}} @$tweets)[0]->{id}, "/",
(sort {$a->{id} <=> $b->{id}} @$tweets)[$#{$tweets}]->{id}, "\n"; print $fh "t:debug %G$username%n got ", scalar(@$tweets), ' tweets',
(@$tweets ? ', first/last: ' . join('/',
(sort {$a->{id} <=> $b->{id}} @$tweets)[0]->{id},
(sort {$a->{id} <=> $b->{id}} @$tweets)[$#{$tweets}]->{id}
)
: ''),
"\n";


my $new_poll_id = 0;
my @own_ids = (); my @own_ids = ();
foreach my $t ( reverse @$tweets ) { foreach my $t ( reverse @$tweets ) {
my $text = &get_text( $t, $obj ); my $text = &get_text( $t, $obj );
Expand All @@ -2110,10 +2125,9 @@ sub get_tweets {
$new_poll_id = $t->{id} if $new_poll_id < $t->{id}; $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
} }
&debug($fh, "%G$username%n skip own " . join(', ', @own_ids) . "\n") if @own_ids; &debug($fh, "%G$username%n skip own " . join(', ', @own_ids) . "\n") if @own_ids;
printf $fh "t:last_id id:%s ac:%s id_type:timeline\n", $new_poll_id, $username; printf $fh "t:last_id id:%s ac:%s id_type:timeline\n", $new_poll_id, $username if $new_poll_id;


&debug($fh, "%G$username%n Polling for replies since " . $state{__last_id}{$username}{reply}); &debug($fh, "%G$username%n Polling for replies since " . $state{__last_id}{$username}{reply});
$new_poll_id = 0;
eval { eval {
if ( $state{__last_id}{$username}{reply} ) { if ( $state{__last_id}{$username}{reply} ) {
$tweets = $obj->replies( { since_id => $state{__last_id}{$username}{reply} } ) $tweets = $obj->replies( { since_id => $state{__last_id}{$username}{reply} } )
Expand All @@ -2128,6 +2142,7 @@ sub get_tweets {
return; return;
} }


$new_poll_id = 0;
foreach my $t ( reverse @$tweets ) { foreach my $t ( reverse @$tweets ) {
next if exists $friends{$username}{ $t->{user}{screen_name} }; next if exists $friends{$username}{ $t->{user}{screen_name} };


Expand All @@ -2141,7 +2156,7 @@ sub get_tweets {
$t->{id}, $username, $ign, &get_reply_to($t), $t->{user}{screen_name}, $t->{id}, $username, $ign, &get_reply_to($t), $t->{user}{screen_name},
&encode_for_file($t->{created_at}), $text; &encode_for_file($t->{created_at}), $text;
} }
printf $fh "t:last_id id:%s ac:%s id_type:reply\n", $new_poll_id, $username; printf $fh "t:last_id id:%s ac:%s id_type:reply\n", $new_poll_id, $username if $new_poll_id;
return 1; return 1;
} }


Expand Down Expand Up @@ -2178,7 +2193,7 @@ sub do_dms {
&encode_for_file($t->{created_at}), $text; &encode_for_file($t->{created_at}), $text;
$new_poll_id = $t->{id} if $new_poll_id < $t->{id}; $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
} }
printf $fh "t:last_id id:%s ac:%s id_type:dm\n", $new_poll_id, $username; printf $fh "t:last_id id:%s ac:%s id_type:dm\n", $new_poll_id, $username if $new_poll_id;
return 1; return 1;
} }


Expand Down Expand Up @@ -2297,6 +2312,8 @@ sub get_timeline {
if ($is_update) { if ($is_update) {
$arg_ref->{since_id} = $last_id if $last_id; $arg_ref->{since_id} = $last_id if $last_id;
$arg_ref->{include_rts} = 1 if $settings{retweet_show}; $arg_ref->{include_rts} = 1 if $settings{retweet_show};
} elsif ($settings{limit_user_tweets} and $settings{limit_user_tweets} =~ /\b(\d+)\b/) {
$arg_ref->{count} = $1;
} }
eval { eval {
$tweets = $obj->user_timeline($arg_ref); $tweets = $obj->user_timeline($arg_ref);
Expand All @@ -2313,7 +2330,9 @@ sub get_timeline {
return 1; return 1;
} }


my $not_before = time - $1*86400 if not $is_update and $settings{limit_user_tweets} and $settings{limit_user_tweets} =~ /\b(\d+)d\b/;
foreach my $t ( reverse @$tweets ) { foreach my $t ( reverse @$tweets ) {
next if defined $not_before and &date_to_epoch($t->{created_at}) < $not_before;
my $text = &get_text( $t, $obj ); my $text = &get_text( $t, $obj );
my $reply = &tweet_or_reply($obj, $t, $username, $cache, $fh); my $reply = &tweet_or_reply($obj, $t, $username, $cache, $fh);
printf $fh "t:%s id:%s ac:%s %snick:%s created_at:%s %s\n", printf $fh "t:%s id:%s ac:%s %snick:%s created_at:%s %s\n",
Expand Down Expand Up @@ -3784,6 +3803,7 @@ sub read_json {
&notice( ["tweet", "$user\@$defservice"], &notice( ["tweet", "$user\@$defservice"],
"Following $_[0]" ); "Following $_[0]" );
$nicks{ $_[0] } = time; $nicks{ $_[0] } = time;
&cmd_user(@_);
}, },
sub { sub {
&cmd_set_window("sender $_[0] $_[0]", $_[1], $_[2]) &cmd_set_window("sender $_[0] $_[0]", $_[1], $_[2])
Expand Down

0 comments on commit 988e398

Please sign in to comment.