+ if (
+ $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
+ or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
+ and $linestart =~ /^\/reply(?:_as)?\s*$/ )
+ )
+ { # /twitter_reply gets a nick:num
+ $word =~ s/^@//;
+ @$complist = map { "$_:$id_map{__indexes}{$_}" }
+ sort { $nicks{$b} <=> $nicks{$a} }
+ grep /^\Q$word/i,
+ keys %{ $id_map{__indexes} };
+ }
+
+ if ( $linestart =~ /^\/twitter_unfriend\s*$/ )
+ { # /twitter_unfriend gets a nick
+ $word =~ s/^@//;
+ push @$complist, grep /^\Q$word/i,
+ sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
+ }
+
+ # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
+ # arg to dm)
+ if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
+ my $prefix = $word =~ s/^@//;
+ $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
+ push @$complist, grep /^\Q$word/i,
+ sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
+ @$complist = map { "\@$_" } @$complist if $prefix;
+ }
+}
+
+sub event_send_text {
+ my ( $line, $server, $win ) = @_;
+ my $awin = Irssi::active_win();
+
+ # if the window where we got our text was the twitter window, and the user
+ # wants to be lazy, tweet away!
+ if ( ( $awin->get_active_name() eq $window->{name} )
+ and Irssi::settings_get_bool("tweet_window_input") )
+ {
+ &cmd_tweet( $line, $server, $win );
+ }
+}
+
+sub get_poll_time {
+ my $poll = Irssi::settings_get_int("twitter_poll_interval");
+ return $poll if $poll >= 60;
+ return 60;
+}
+
+sub hilight {
+ my $text = shift;
+
+ if ( Irssi::settings_get_str("twirssi_nick_color") ) {
+ my $c = Irssi::settings_get_str("twirssi_nick_color");
+ $c = $irssi_to_mirc_colors{$c};
+ $text =~ s/(^|\W)\@([-\w]+)/$1\cC$c\@$2\cO/g if $c;
+ }
+ if ( Irssi::settings_get_str("twirssi_topic_color") ) {
+ my $c = Irssi::settings_get_str("twirssi_topic_color");
+ $c = $irssi_to_mirc_colors{$c};
+ $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
+ }
+ $text =~ s/[\n\r]/ /g;
+
+ return $text;
+}
+
+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 decode "utf8", $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 decode "utf8", $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";