+sub shorten {
+ my $data = shift;
+
+ my $provider = Irssi::settings_get_str("short_url_provider");
+ if (
+ (
+ Irssi::settings_get_bool("twirssi_always_shorten")
+ or &too_long( $data, 1 )
+ )
+ and $provider
+ )
+ {
+ my @args;
+ if ( $provider eq 'Bitly' ) {
+ @args[ 1, 2 ] = split ',',
+ Irssi::settings_get_str("short_url_args"), 2;
+ unless ( @args == 3 ) {
+ &ccrap(
+ "WWW::Shorten::Bitly requires a username and API key.",
+ "Set short_url_args to username,API_key or change your",
+ "short_url_provider."
+ );
+ return $data;
+ }
+ }
+
+ foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
+ eval {
+ $args[0] = $url;
+ my $short = makeashorterlink(@args);
+ if ($short) {
+ $data =~ s/\Q$url/$short/g;
+ } else {
+ ¬ice("Failed to shorten $url!");
+ }
+ };
+ }
+ }
+
+ return $data;
+}
+
+sub normalize_username {
+ my $user = shift;
+
+ my ( $username, $service ) = split /\@/, $user, 2;
+ if ($service) {
+ $service = ucfirst lc $service;
+ } else {
+ $service =
+ ucfirst lc Irssi::settings_get_str("twirssi_default_service");
+ unless ( exists $twits{"$username\@$service"} ) {
+ $service = undef;
+ foreach my $t ( sort keys %twits ) {
+ next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
+ $service = $1;
+ last;
+ }
+
+ unless ($service) {
+ ¬ice("Can't find a logged in user '$user'");
+ }
+ }
+ }
+
+ return "$username\@$service";
+}
+