+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";
+}
+
+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_default_service", "Twitter" );
+Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
+Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
+Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
+ 'RT $n: "$t" ${-- $c$}' );
+Irssi::settings_add_str( "twirssi", "twirssi_location",
+ ".irssi/scripts/twirssi.pl" );
+Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
+ ".irssi/scripts/twirssi.json" );
+Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
+Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
+Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
+Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
+Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
+Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
+Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
+Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
+
+$last_poll = time - &get_poll_time;