+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\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 $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;
+}
+
+Irssi::signal_add( "send text", "event_send_text" );
+
+Irssi::theme_register(
+ [
+ 'twirssi_tweet', '[$0%B@$1%n$2] $3',
+ 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
+ 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
+ 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
+ 'twirssi_error', 'ERROR: $0',
+ ]
+);
+
+Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
+Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
+Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
+Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
+Irssi::settings_add_str( "twirssi", "short_url_args", undef );
+Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
+Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
+Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
+Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );