Skip to content

Commit

Permalink
Merge pull request oysttyer#117 from oysttyer/bugfix/tco_length-issue116
Browse files Browse the repository at this point in the history
Properly count the length of t.co links
  • Loading branch information
funnelfiasco authored Jun 4, 2017
2 parents dceaba3 + ab98b27 commit c72b40d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions oysttyer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ END
$location ||= 0;
$linelength ||= 140;
$quotelinelength ||= 116;
$tco_length ||= 23; # The number of characters that t.co links require
$dm_text_character_limit ||= 10000;
$oauthbase ||= $apibase || "${http_proto}://api.twitter.com";
# this needs to be AFTER oauthbase so that apibase can set oauthbase.
Expand Down Expand Up @@ -1421,7 +1422,7 @@ END
print $stdout "*** instance already running: $_\n";
exit 1;
}
}
}
unless (unlink($lockf)) {
print $stdout "*** unable to remove stale lock: $!\n";
exit 1;
Expand All @@ -1442,7 +1443,7 @@ END
unless (close(L)) {
print $stdout "*** unable to close lock: $!\n";
kill 15, $child;
}
}
print $stdout "*** detached daemon released. pid = $child\n";
kill 15, $$;
exit 0;
Expand Down Expand Up @@ -3233,7 +3234,7 @@ sub prinput {
my $countmaybe = $2;
$countmaybe =~ s/[^\d]//g if (length($countmaybe));
$countmaybe += 0;

my $my_json_ref = &grabjson($rtsofmeurl, 0, 0, $countmaybe);
&dt_tdisplay($my_json_ref, "rtsofme");
if ($mode eq 're') {
Expand Down Expand Up @@ -3423,7 +3424,7 @@ sub prinput {
# and fall through to edm
}
if (s#^/edm \@?([^\s]+)\s+## && length) {

# Stolen from Floodgap's texapp
my $string = $_;
my $target = $1;
Expand Down Expand Up @@ -6872,7 +6873,7 @@ sub urlshorten {
print $stdout "$cl\n" if ($superverbose);
chomp($rc = `$cl`);
if ($rc =~ m#^https?://#) {
return $rc
return $rc
} else {
print $stdout "ERROR: " . "$rc\n";
return undef
Expand Down Expand Up @@ -7701,7 +7702,7 @@ sub normalizejson {
}
$rt = &destroy_all_tco($rt);
$rt = &fix_geo_api_data($rt);

$i->{'retweeted_status'} = $rt;
$i->{'text'} =
"RT \@$rt->{'user'}->{'screen_name'}" . ': ' . $rt->{'text'};
Expand Down Expand Up @@ -8190,7 +8191,8 @@ sub fastturntotco {
($s =~ s#\b(([a-zA-Z0-9-_]\.)+([a-zA-Z]){2,})\b#((length($w="$1")>45)?$w:"http://$w")#eg);

# now turn all http and https URLs into t.co strings
($s =~ s#\b(https?)://[a-zA-Z0-9-_]+[^\s]*?('|\\|\s|[\.;:,!\?]\s+|[\.;:,!\?]$|$)#\1://t.co/1234567\2#gi);
my $tco_string = 'X' x ( $tco_length - 13 );
($s =~ s#\b(https?)://[a-zA-Z0-9-_]+[^\s]*?('|\\|\s|[\.;:,!\?]\s+|[\.;:,!\?]$|$)#https://t.co/${tco_string}\2#gi);
return $s;
}
# slow t.co converter. this is for future expansion.
Expand Down

0 comments on commit c72b40d

Please sign in to comment.