New upstream release twirssi.pl script
Daniel Echeverry
10 years ago
16 | 16 | |
17 | 17 | use vars qw($VERSION %IRSSI); |
18 | 18 | |
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+)/; | |
20 | 20 | %IRSSI = ( |
21 | 21 | authors => '@zigdon, @gedge', |
22 | 22 | contact => 'zigdon@gmail.com', |
25 | 25 | . 'Can optionally set your bitlbee /away message to same', |
26 | 26 | license => 'GNU GPL v2', |
27 | 27 | url => 'http://twirssi.com', |
28 | changed => '$Date: 2013-06-08 13:30:00 +0000$', | |
28 | changed => '$Date: 2013-09-13 19:49:11 +0000$', | |
29 | 29 | ); |
30 | 30 | |
31 | 31 | my $twit; # $twit is current logged-in Net::Twitter object (usually one of %twits) |
2241 | 2241 | $search = $obj->search( |
2242 | 2242 | { |
2243 | 2243 | 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}, | |
2245 | 2247 | } |
2246 | 2248 | ); |
2247 | 2249 | }; |
2257 | 2259 | print $fh "t:debug %G$username%n Invalid search results when searching", |
2258 | 2260 | " for '$topic'. Aborted.\n"; |
2259 | 2261 | 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 | ||
2263 | 2273 | 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); | |
2265 | 2275 | |
2266 | 2276 | foreach my $t ( reverse @{ $search->{statuses} } ) { |
2267 | 2277 | next if exists $blocks{$username}{ $t->{user}->{screen_name} }; |
2642 | 2652 | if ( $meta{type} eq 'searchid' ) { |
2643 | 2653 | &debug("%G$meta{username}%n Search '$meta{topic}' got id $meta{id}"); |
2644 | 2654 | 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) { | |
2646 | 2657 | $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } = $meta{id}; |
2647 | 2658 | } else { |
2648 | 2659 | &debug("%G$meta{username}%n Search '$meta{topic}' bad id $meta{id}"); |
2650 | 2661 | } |
2651 | 2662 | } elsif ( $meta{type} eq 'last_id') { |
2652 | 2663 | $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; | |
2654 | 2665 | } elsif ( $meta{type} eq 'last_id_fixreplies' ) { |
2655 | 2666 | $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; | |
2657 | 2668 | } |
2658 | 2669 | |
2659 | 2670 | } elsif ($type eq 'tweet' or $type eq 'dm' or $type eq 'reply' or $type eq 'search' or $type eq 'search_once') { # cf theme_register |
2675 | 2686 | |
2676 | 2687 | if ( $meta{type} eq 'search' ) { |
2677 | 2688 | 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) { | |
2679 | 2690 | $state{__last_id}{ $meta{username} }{__search}{ $meta{topic} } = $meta{id}; |
2680 | 2691 | } |
2681 | 2692 | } elsif ( $meta{type} eq 'search_once' ) { |
2771 | 2782 | $first_call = 0; |
2772 | 2783 | $update_is_running = 0; |
2773 | 2784 | } |
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; | |
2774 | 2793 | } |
2775 | 2794 | |
2776 | 2795 | sub write_lines { |