Codebase list irssi-scripts / 00bd3cd
New upstream release twirssi.pl script Daniel Echeverry 10 years ago
1 changed file(s) with 30 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1616
1717 use vars qw($VERSION %IRSSI);
1818
19 $VERSION = sprintf '%s', q$Version: v2.6.0$ =~ /^\w+:\s+v(\S+)/;
19 $VERSION = sprintf '%s', q$Version: v2.6.2$ =~ /^\w+:\s+v(\S+)/;
2020 %IRSSI = (
2121 authors => '@zigdon, @gedge',
2222 contact => 'zigdon@gmail.com',
2525 . 'Can optionally set your bitlbee /away message to same',
2626 license => 'GNU GPL v2',
2727 url => 'http://twirssi.com',
28 changed => '$Date: 2013-06-08 13:30:00 +0000$',
28 changed => '$Date: 2013-09-13 19:49:11 +0000$',
2929 );
3030
3131 my $twit; # $twit is current logged-in Net::Twitter object (usually one of %twits)
22412241 $search = $obj->search(
22422242 {
22432243 q => $topic,
2244 since_id => $state{__last_id}{$username}{__search}{$topic}
2244 since_id => $state{__last_id}{$username}{__search}{$topic} eq '9223372036854775807'
2245 ? 0
2246 : $state{__last_id}{$username}{__search}{$topic},
22452247 }
22462248 );
22472249 };
22572259 print $fh "t:debug %G$username%n Invalid search results when searching",
22582260 " for '$topic'. Aborted.\n";
22592261 return;
2260 }
2261
2262 $state{__last_id}{$username}{__search}{$topic} = $search->{search_metadata}->{max_id};
2262 } elsif ( $search->{search_metadata}->{max_id} eq '9223372036854775807' ) {
2263 &debug($fh, "%G$username%n Error: search max_id = MAX_INT64");
2264 $state{__last_id}{$username}{__search}{$topic} = 0;
2265 foreach my $t ( reverse @{ $search->{statuses} } ) {
2266 $state{__last_id}{$username}{__search}{$topic} = $t->{id}
2267 if cmp_id($t->{id}, $state{__last_id}{$username}{__search}{$topic}) > 0;
2268 }
2269 } else {
2270 $state{__last_id}{$username}{__search}{$topic} = $search->{search_metadata}->{max_id};
2271 }
2272
22632273 printf $fh "t:searchid id:%s ac:%s topic:%s\n",
2264 $search->{search_metadata}->{max_id}, $username, &encode_for_file($topic);
2274 $state{__last_id}{$username}{__search}{$topic}, $username, &encode_for_file($topic);
22652275
22662276 foreach my $t ( reverse @{ $search->{statuses} } ) {
22672277 next if exists $blocks{$username}{ $t->{user}->{screen_name} };
26422652 if ( $meta{type} eq 'searchid' ) {
26432653 &debug("%G$meta{username}%n Search '$meta{topic}' got id $meta{id}");
26442654 if (not exists $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} }
2645 or $meta{id} >= $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } ) {
2655 or $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } eq '9223372036854775807'
2656 or cmp_id($meta{id}, $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} }) > 0) {
26462657 $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } = $meta{id};
26472658 } else {
26482659 &debug("%G$meta{username}%n Search '$meta{topic}' bad id $meta{id}");
26502661 }
26512662 } elsif ( $meta{type} eq 'last_id') {
26522663 $state{__last_id}{ $meta{username} }{ $meta{id_type} } = $meta{id}
2653 if $state{__last_id}{ $meta{username} }{ $meta{id_type} } < $meta{id};
2664 if cmp_id($meta{id}, $state{__last_id}{ $meta{username} }{ $meta{id_type} }) > 0;
26542665 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
26552666 $state{__last_id}{ $meta{username} }{__extras}{ $meta{id_type} } = $meta{id}
2656 if $state{__last_id}{ $meta{username} }{__extras}{ $meta{id_type} } < $meta{id};
2667 if cmp_id($meta{id}, $state{__last_id}{ $meta{username} }{__extras}{ $meta{id_type} }) > 0;
26572668 }
26582669
26592670 } elsif ($type eq 'tweet' or $type eq 'dm' or $type eq 'reply' or $type eq 'search' or $type eq 'search_once') { # cf theme_register
26752686
26762687 if ( $meta{type} eq 'search' ) {
26772688 if ( exists $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} }
2678 and $meta{id} > $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } ) {
2689 and cmp_id($meta{id}, $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} }) > 0) {
26792690 $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } = $meta{id};
26802691 }
26812692 } elsif ( $meta{type} eq 'search_once' ) {
27712782 $first_call = 0;
27722783 $update_is_running = 0;
27732784 }
2785 }
2786
2787 sub cmp_id {
2788 my $id1 = shift;
2789 my $id2 = shift;
2790 return -1 if length $id1 < length $id2;
2791 return 1 if length $id1 > length $id2;
2792 return $id1 cmp $id2;
27742793 }
27752794
27762795 sub write_lines {