diff options
28 files changed, 3206 insertions, 2 deletions
@@ -206,9 +206,8 @@ svn/ .hydrogen .icedtea/ .inkscape/ -.irssi/config,* +.irssi/config.* .irssi/logs/ -.irssi/scripts/autorun/ .irssi/away.log .iscan_preference .jackdrc diff --git a/.irssi/scripts/autorun/bitlbee_blist.pl b/.irssi/scripts/autorun/bitlbee_blist.pl new file mode 120000 index 0000000..a0fff54 --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_blist.pl @@ -0,0 +1 @@ +../bitlbee_blist.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/bitlbee_join_notice.pl b/.irssi/scripts/autorun/bitlbee_join_notice.pl new file mode 120000 index 0000000..c4c5afc --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_join_notice.pl @@ -0,0 +1 @@ +../bitlbee_join_notice.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/bitlbee_nick_change.pl b/.irssi/scripts/autorun/bitlbee_nick_change.pl new file mode 120000 index 0000000..773c4c4 --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_nick_change.pl @@ -0,0 +1 @@ +../bitlbee_nick_change.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/bitlbee_tab_completion.pl b/.irssi/scripts/autorun/bitlbee_tab_completion.pl new file mode 120000 index 0000000..caca874 --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_tab_completion.pl @@ -0,0 +1 @@ +../bitlbee_tab_completion.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/bitlbee_timestamp.pl b/.irssi/scripts/autorun/bitlbee_timestamp.pl new file mode 120000 index 0000000..54360ae --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_timestamp.pl @@ -0,0 +1 @@ +../bitlbee_timestamp.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/bitlbee_typing_notice.pl b/.irssi/scripts/autorun/bitlbee_typing_notice.pl new file mode 120000 index 0000000..9c4da39 --- /dev/null +++ b/.irssi/scripts/autorun/bitlbee_typing_notice.pl @@ -0,0 +1 @@ +../bitlbee_typing_notice.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/extaway.pl b/.irssi/scripts/autorun/extaway.pl new file mode 120000 index 0000000..9ad9ba0 --- /dev/null +++ b/.irssi/scripts/autorun/extaway.pl @@ -0,0 +1 @@ +../extaway.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/irccomplete.pl b/.irssi/scripts/autorun/irccomplete.pl new file mode 120000 index 0000000..2fe4b47 --- /dev/null +++ b/.irssi/scripts/autorun/irccomplete.pl @@ -0,0 +1 @@ +../irccomplete.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/lastfm.pl b/.irssi/scripts/autorun/lastfm.pl new file mode 120000 index 0000000..a663918 --- /dev/null +++ b/.irssi/scripts/autorun/lastfm.pl @@ -0,0 +1 @@ +../lastfm.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/ls.pl b/.irssi/scripts/autorun/ls.pl new file mode 120000 index 0000000..e878d30 --- /dev/null +++ b/.irssi/scripts/autorun/ls.pl @@ -0,0 +1 @@ +../ls.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/nicklist.pl b/.irssi/scripts/autorun/nicklist.pl new file mode 120000 index 0000000..53812ea --- /dev/null +++ b/.irssi/scripts/autorun/nicklist.pl @@ -0,0 +1 @@ +../nicklist.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/nickserv.pl b/.irssi/scripts/autorun/nickserv.pl new file mode 120000 index 0000000..c3fef2b --- /dev/null +++ b/.irssi/scripts/autorun/nickserv.pl @@ -0,0 +1 @@ +../nickserv.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/scriptassist.pl b/.irssi/scripts/autorun/scriptassist.pl new file mode 120000 index 0000000..f192fad --- /dev/null +++ b/.irssi/scripts/autorun/scriptassist.pl @@ -0,0 +1 @@ +/usr/share/irssi/scripts/scriptassist.pl
\ No newline at end of file diff --git a/.irssi/scripts/autorun/tmux_away.pl b/.irssi/scripts/autorun/tmux_away.pl new file mode 120000 index 0000000..70df40e --- /dev/null +++ b/.irssi/scripts/autorun/tmux_away.pl @@ -0,0 +1 @@ +../tmux_away.pl
\ No newline at end of file diff --git a/.irssi/scripts/bitlbee_blist.pl b/.irssi/scripts/bitlbee_blist.pl new file mode 100644 index 0000000..179b539 --- /dev/null +++ b/.irssi/scripts/bitlbee_blist.pl @@ -0,0 +1,61 @@ +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = '0.4'; +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal', + contact => 'tijmen.ruizendaal@gmail.com', + name => 'bitlbee_blist', + description => '/blist <all|online|offline|away> <word>, greps <word> from blist for bitlbee', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee', + changed => '2006-10-27', +); + +my $bitlbee_server_tag = "localhost"; +my $bitlbee_channel = "&bitlbee"; +my ($list, $word); + +get_channel(); + +Irssi::signal_add_last 'channel sync' => sub { + my( $channel ) = @_; + if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){ + $bitlbee_server_tag = $channel->{server}->{tag}; + $bitlbee_channel = $channel->{name}; + } +}; + +sub get_channel { + my @channels = Irssi::channels(); + foreach my $channel(@channels) { + if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") { + $bitlbee_channel = $channel->{name}; + $bitlbee_server_tag = $channel->{server}->{tag}; + return 1; + } + } + return 0; +} + +sub blist { + my ($args, $server, $winit) = @_; + ($list, $word) = split(/ /, $args, 2); + if (Irssi::active_win->{'active'}->{'name'} eq $bitlbee_channel) { + Irssi::active_win()->command("msg $bitlbee_channel blist $list"); + Irssi::signal_add('event privmsg', 'grep'); + } else { + print "Only use in $bitlbee_channel."; + } +} + +sub grep { + my ($server, $data, $nick, $address) = @_; + my ($target, $text) = split(/ :/, $data, 2); + if ($text =~ /$word/ && $target =~ /$bitlbee_channel/){ + ##do nothing + } else {Irssi::signal_stop();} + if ($text =~ /buddies/ && $target =~/$bitlbee_channel/){Irssi::signal_remove('event privmsg', 'grep');} +} + +Irssi::command_bind('blist','blist'); diff --git a/.irssi/scripts/bitlbee_join_notice.pl b/.irssi/scripts/bitlbee_join_notice.pl new file mode 100644 index 0000000..6644895 --- /dev/null +++ b/.irssi/scripts/bitlbee_join_notice.pl @@ -0,0 +1,108 @@ +# CHANGELOG: +# +# 2010-08-10 (version 1.3) +# * new bitlbee server detection +# +# 2004-11-28: +# * adds join message to query +# +# /statusbar window add join_notice +# use Data::Dumper; + +#use strict; +use Irssi::TextUI; +#use Irssi::Themes; +use Data::Dumper; + +use vars qw($VERSION %IRSSI); + +$VERSION = '1.3'; +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal', + contact => 'tijmen.ruizendaal@gmail.com', + name => 'BitlBee_join_notice', + description => '1. Adds an item to the status bar wich shows [joined: <nicks>] when someone is joining &bitlbee. 2. Shows join messages in the query. (For bitlbee v3.0+)', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee', + changed => '2010-08-10' +); +my %timers; +my $bitlbee_server; # server object +my @control_channels; # mostly: &bitlbee, &facebook etc. +init(); + +sub init { # if script is loaded after connect + my @servers = Irssi::servers(); + foreach my $server(@servers) { + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + my @channels = $server->channels(); + foreach my $channel(@channels) { + if( $channel->{mode} =~ /C/ ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } + } + } + } +} +# if connect after script is loaded +Irssi::signal_add_last('event 005' => sub { + my( $server ) = @_; + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + } +}); +# if new control channel is synced after script is loaded +Irssi::signal_add_last('channel sync' => sub { + my( $channel ) = @_; + if( $channel->{mode} =~ /C/ && $channel->{server}->{tag} eq $bitlbee_server->{tag} ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } +}); + +# BEGIN bitlbee_join_notice.pl + +my %online; + +sub event_join { + my ($server, $channel, $nick, $address) = @_; + $channel =~ s/^://g; + if ( (grep $_ eq $channel, @control_channels) && $server->{tag} eq $bitlbee_server->{tag}){ + $online{$nick} = 1; + Irssi::timeout_remove($timers{$nick}); + delete($timers{$nick}); + $timers{$nick} = Irssi::timeout_add_once(7000, 'empty', $nick); + Irssi::statusbar_items_redraw('join_notice'); + my $window = Irssi::window_find_item($nick); + if($window){ + $window->printformat(Irssi::MSGLEVEL_JOINS, 'join', $nick, $address, $channel); + } + } +} +sub join_notice { + my ($item, $get_size_only) = @_; + my $line; + foreach my $key (keys(%online) ){ + $line = $line." ".$key; + } + if ($line ne "" ){ + $item->default_handler($get_size_only, "{sb joined:$line}", undef, 1); + $line = ""; + } else { + $item->default_handler($get_size_only, "", undef, 1); + } +} +sub empty { + my $nick = shift; + delete($online{$nick}); + Irssi::timeout_remove($timers{$nick}); + delete($timers{$nick}); + Irssi::statusbar_items_redraw('join_notice'); +} + +Irssi::signal_add('event join', 'event_join' ); +Irssi::statusbar_item_register('join_notice', undef, 'join_notice'); +Irssi::statusbars_recreate_items(); +Irssi::theme_register([ 'join', '{channick_hilight $0} {chanhost $1} has joined {channel $2}', ]); + +# END bitlbee_join_notice.pl diff --git a/.irssi/scripts/bitlbee_nick_change.pl b/.irssi/scripts/bitlbee_nick_change.pl new file mode 100644 index 0000000..93a01b9 --- /dev/null +++ b/.irssi/scripts/bitlbee_nick_change.pl @@ -0,0 +1,72 @@ +use strict; +use Data::Dumper; +use vars qw($VERSION %IRSSI); + +$VERSION = '1.3'; +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal', + contact => 'tijmen.ruizendaal@gmail.com', + name => 'BitlBee_nick_change', + description => 'Shows an IM nickchange in an Irssi way. (in a query and in the bitlbee channel). (For bitlbee 3.0+)', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee', + changed => '2010-07-28' +); + +my $bitlbee_server; # server object +my @control_channels; # mostly: &bitlbee, &facebook etc. +init(); + +sub init { # if script is loaded after connect + my @servers = Irssi::servers(); + foreach my $server(@servers) { + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + my @channels = $server->channels(); + foreach my $channel(@channels) { + if( $channel->{mode} =~ /C/ ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } + } + } + } +} +# if connect after script is loaded +Irssi::signal_add_last('event 005' => sub { + my( $server ) = @_; + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + } +}); +# if new control channel is synced after script is loaded +Irssi::signal_add_last('channel sync' => sub { + my( $channel ) = @_; + if( $channel->{mode} =~ /C/ && $channel->{server}->{tag} eq $bitlbee_server->{tag} ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } +}); + +# BEGIN bitlbee_nick_change.pl + +sub event_notice { + my ($server, $msg, $nick, $address, $target) = @_; + if( $server->{tag} eq $bitlbee_server->{tag} && $msg =~ /.*Changed name to.*/ ){ + my $friendly_name = $msg; + $friendly_name =~ s/.*Changed name to `(.*)'.*/$1/; + my $window = $server->window_find_item($nick); + if ($window) { + $window->printformat(MSGLEVEL_CRAP, 'nick_change', $nick, $address, 'changed name to `'.$friendly_name.'`'); + Irssi::signal_stop(); + } else { + # TODO find control channel where this user is located and display the notice there + #my $window = $server->window_find_item($bitlbee_channel); + #$window->printformat(MSGLEVEL_CRAP, 'nick_change', $nick, $address, 'changed name to `'.$friendly_name.'`'); + #Irssi::signal_stop(); + } + } +}; + +Irssi::signal_add_last('message irc notice', 'event_notice'); +Irssi::theme_register(['nick_change', '{channick_hilight $0} [$1] $2']); + +# END bitbee_nick_change.pl diff --git a/.irssi/scripts/bitlbee_tab_completion.pl b/.irssi/scripts/bitlbee_tab_completion.pl new file mode 100644 index 0000000..8d19128 --- /dev/null +++ b/.irssi/scripts/bitlbee_tab_completion.pl @@ -0,0 +1,88 @@ +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = '1.3'; + +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal & Wilmer van der Gaast', + contact => 'tijmen.ruizendaal@gmail.com', + name => 'BitlBee_tab_completion', + description => 'Intelligent Tab-completion for BitlBee commands.', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee', + changed => '2009-08-11', +); + +my $root_nick = 'root'; +my $bitlbee_channel = '&bitlbee'; +my $bitlbee_server_tag = 'localhost'; +my $get_completions = 0; + +my @commands; + +Irssi::signal_add_last 'channel sync' => sub { + my( $channel ) = @_; + if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){ + $bitlbee_server_tag = $channel->{server}->{tag}; + $bitlbee_channel = $channel->{name}; + request_completions(); + } +}; + +if (get_channel()) { + request_completions(); +} + +sub request_completions { + $get_completions = 1; + Irssi::server_find_tag($bitlbee_server_tag)->send_raw( 'COMPLETIONS' ); +} + +sub get_channel { + my @channels = Irssi::channels(); + foreach my $channel(@channels) { + if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") { + $bitlbee_channel = $channel->{name}; + $bitlbee_server_tag = $channel->{server}->{tag}; + return 1; + } + } + return 0; +} + +sub irc_notice { + return unless $get_completions; + my( $server, $msg, $from, $address, $target ) = @_; + + if( $msg =~ s/^COMPLETIONS // ) { + $root_nick = $from; + if( $msg eq 'OK' ) { + @commands = (); + } + elsif( $msg eq 'END' ) { + $get_completions = 0; + } + @commands = ( @commands, $msg ); + + Irssi::signal_stop(); + } +} + +sub complete_word { + my ($complist, $window, $word, $linestart, $want_space) = @_; + my $channel = $window->get_active_name(); + if ($channel eq $bitlbee_channel or $channel eq $root_nick or $linestart =~ /^\/(msg|query) \Q$root_nick\E */i){ + $linestart =~ s/^\/(msg|query) \Q$root_nick\E *//i; + $linestart =~ s/^\Q$root_nick\E[:,] *//i; + foreach my $command(@commands) { + if ($command =~ /^$word/i) { + push @$complist, $command; + } + } + } +} + + +Irssi::signal_add_last('complete word', 'complete_word'); +Irssi::signal_add_first('message irc notice', 'irc_notice'); + diff --git a/.irssi/scripts/bitlbee_timestamp.pl b/.irssi/scripts/bitlbee_timestamp.pl new file mode 100644 index 0000000..7957d57 --- /dev/null +++ b/.irssi/scripts/bitlbee_timestamp.pl @@ -0,0 +1,105 @@ +use strict; +use Data::Dumper; +use vars qw($VERSION %IRSSI); +use DateTime; + +$VERSION = '0.5'; +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal', + contact => 'tijmen.ruizendaal@gmail.com', + name => 'bitlbee_timestamp', + description => 'Replace Irssi\'s timestamps with those sent by BitlBee', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee', + changed => '2010-05-01', +); + +my $tf = Irssi::settings_get_str('timestamp_format'); + +my $bitlbee_server; # server object +my @control_channels; # mostly: &bitlbee, &facebook etc. +init(); + +sub init { # if script is loaded after connect + my @servers = Irssi::servers(); + foreach my $server(@servers) { + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + my @channels = $server->channels(); + foreach my $channel(@channels) { + if( $channel->{mode} =~ /C/ ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } + } + } + } +} +# if connect after script is loaded +Irssi::signal_add_last('event 005' => sub { + my( $server ) = @_; + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + } +}); +# if new control channel is synced after script is loaded +Irssi::signal_add_last('channel sync' => sub { + my( $channel ) = @_; + if( $channel->{mode} =~ /C/ && $channel->{server}->{tag} eq $bitlbee_server->{tag} ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } +}); + +my $prev_date = ''; + +sub privmsg { + my ($server, $data, $nick, $address) = @_; + + # What we need to match: ^B[^B^B^B2010-03-21 16:33:41^B]^B + + if( $server->{tag} eq $bitlbee_server->{tag} ){ + + my ($target, $text) = split(/ :/, $data, 2); + + #if( $text =~ /^B[^B^B^B[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}^B]^B/ ){ + + if( $text =~ /\x02\[\x02\x02\x02.*\x02\]\x02/ ){ + my $window; + my $timestamp = $text; + my $time; + my $date; + $timestamp =~ s/.*\x02\[\x02\x02\x02(.*?)\x02\]\x02.*/$1/g; + $text =~ s/\x02\[\x02\x02\x02(.*?)\x02\]\x02 //g; + + ($date, $time) = split(/ /, $timestamp); + if( !$time ){ # the timestamp doesn't have a date + $time = $date; + # use today as date + $date = DateTime->now->ymd; + } + + if( $date ne $prev_date ){ + if( $target =~ /#|&/ ){ # find channel window based on target + $window = Irssi::window_find_item($target); + } else { # find query window based on nick + $window = Irssi::window_find_item($nick); + } + if( $window != undef ){ + my($year, $month, $day) = split(/-/, $date); + my $dt = DateTime->new(year => $year, month => $month, day => $day); + my $formatted_date = $day.' '.$dt->month_abbr.' '.$year; + + $window->print('Day changed to '.$formatted_date, MSGLEVEL_NEVER); + } + } + $prev_date = $date; + + Irssi::settings_set_str('timestamp_format', $time); + Irssi::signal_continue($server, $target . ' :' . $text, $nick, $address); + my $escaped = $tf; + $escaped =~ s/%/%%/g; + Irssi::settings_set_str('timestamp_format', $tf); + } + } +} + +Irssi::signal_add('event privmsg', 'privmsg'); diff --git a/.irssi/scripts/bitlbee_typing_notice.pl b/.irssi/scripts/bitlbee_typing_notice.pl new file mode 100644 index 0000000..50fe47c --- /dev/null +++ b/.irssi/scripts/bitlbee_typing_notice.pl @@ -0,0 +1,319 @@ +# INSTALLATION +# [&bitlbee] set typing_notice true +# <@root> typing_notice = `true' +# AND +# /statusbar window add typing_notice +# +# SETTINGS +# [bitlbee] +# bitlbee_send_typing = ON +# -> send typing messages to buddies +# bitlbee_typing_allwin = OFF +# -> show typing notifications in all windows +# +# +# Changelog: +# +# 2010-08-09 (version 1.7.1) +# * Multiple control channels supported by checking chanmodes +# +# 2010-07-27 (version 1.7) +# * Using new server detection for latest BitlBee support +# +# 2010-07-26 (version 1.6.3) +# * Removed checking if nicks exists in &bitlbee channel, this because BitlBee +# can be used without control channel from this date +# +# 2007-03-03 (version 1.6.2) +# * Fix: timers weren't deleted correctly. This resulted in huge mem usage. +# +# 2006-11-02 (version 1.6.1) +# * Sending typing works again. +# +# 2006-10-27 (version 1.6) +# * 'channel sync' re-implemented. +# * bitlbee_send_typing was a string setting, It's a boolean now, like it should. +# +# 2006-10-24 (version 1.5) +# * Sending notices to online users only. ( removed this again at 2010-07-26, see above ) +# * Using the new get_channel function; +# +# 2005-12-15 (version 1.42): +# * Fixed small bug with typing notices disappearing under certain circumstances +# in channels +# * Fixed bug that caused outgoing notifications not to work +# * root cares not about our typing status. +# +# 2005-12-04 (version 1.41): +# * Implemented stale states in statusbar (shows "(stale)" for OSCAR connections) +# * Introduced bitlbee_typing_allwin (default OFF). Set this to ON to make +# typing notifications visible in all windows. +# +# 2005-12-03 (version 1.4): +# * Major code cleanups and rewrites for bitlbee 1.0 with the updated typing +# scheme. TYPING 0, TYPING 1, and TYPING 2 are now supported from the server. +# * Stale states (where user has typed in text but has stopped typing) are now +# recognized. +# * Bug where user thinks you are still typing if you close the window after +# typing something and then erasing it quickly.. fixed. +# * If a user signs off while they are still typing, the notification is removed +# This update by Matt "f0rked" Sparks +# +# 2005-08-26: +# Some fixes for AIM, Thanks to Dracula. +# +# 2005-08-16: +# AIM supported, for sending notices, using CTCP TYPING 0. (Use the AIM patch from Hanji http://get.bitlbee.org/patches/) +# +# 2004-10-31: +# Sends typing notice to the bitlbee server when typing a message in irssi. bitlbee > 0.92 +# +# 2004-06-11: +# shows [typing: ] in &bitlbee with multiple users. +# +use strict; +use Irssi::TextUI; +use Data::Dumper; + +use vars qw($VERSION %IRSSI); + +$VERSION = '1.7.1'; +%IRSSI = ( + authors => 'Tijmen "timing" Ruizendaal, Matt "f0rked" Sparks', + contact => 'tijmen.ruizendaal@gmail.com, root@f0rked.com', + name => 'BitlBee_typing_notice', + description => '1. Adds an item to the status bar wich shows [typing] when someone is typing a message on the supported IM-networks 2. Sends typing notices to the supported IM networks (the other way arround). (For bitlbee 3.0+)', + license => 'GPLv2', + url => 'http://the-timing.nl/stuff/irssi-bitlbee, http://f0rked.com', + changed => '2010-08-09', +); + +my $bitlbee_server; # server object +my @control_channels; # mostly: &bitlbee, &facebook etc. +init(); + +sub init { # if script is loaded after connect + my @servers = Irssi::servers(); + foreach my $server(@servers) { + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + my @channels = $server->channels(); + foreach my $channel(@channels) { + if( $channel->{mode} =~ /C/ ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } + } + } + } +} +# if connect after script is loaded +Irssi::signal_add_last('event 005' => sub { + my( $server ) = @_; + if( $server->isupport('NETWORK') eq 'BitlBee' ){ + $bitlbee_server = $server; + } +}); +# if new control channel is synced after script is loaded +Irssi::signal_add_last('channel sync' => sub { + my( $channel ) = @_; + if( $channel->{mode} =~ /C/ && $channel->{server}->{tag} eq $bitlbee_server->{tag} ){ + push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels); + } +}); + +# How often to check if we are typing, or on msn, +# how long to keep the typing notice up, or check +# if the other user is still typing... +my $KEEP_TYPING_TIMEOUT = 1; +my $STOP_TYPING_TIMEOUT = 7; + +my %timer_tag; + +my %typing; +my %tag; +my $line; +my %out_typing; +my $lastkey; +my $keylog_active = 1; +my $command_char = Irssi::settings_get_str('cmdchars'); # mostly: / +my $to_char = Irssi::settings_get_str("completion_char"); # mostly: : + +sub event_ctcp_msg { + my ($server, $msg, $from, $address) = @_; + return if $server->{tag} ne $bitlbee_server->{tag}; + if ( my($type) = $msg =~ "TYPING ([0-9])" ){ + Irssi::signal_stop(); + if( $type == 0 ){ + unset_typing($from); + } elsif( $type == 1 ){ + $typing{$from}=1; + if( $address !~ /\@login\.oscar\.aol\.com/ and $address !~ /\@YAHOO/ and $address !~ /\@login\.icq\.com/ ){ + Irssi::timeout_remove($tag{$from}); + delete($tag{$from}); + $tag{$from}=Irssi::timeout_add_once($STOP_TYPING_TIMEOUT*1000,"unset_typing",$from); + } + redraw($from); + } elsif( $type == 2 ){ + stale_typing($from); + } + } +} + +sub unset_typing { + my($from,$no_redraw)=@_; + delete $typing{$from} if $typing{$from}; + Irssi::timeout_remove($tag{$from}); + delete($tag{$from}); + redraw($from) if !$no_redraw; +} + +sub stale_typing { + my($from)=@_; + $typing{$from}=2; + redraw($from); +} + +sub redraw { + my($from)=@_; + my $window = Irssi::active_win(); + my $name = $window->get_active_name(); + + # only redraw if current window equals to the typing person, is a control channel or if allwin is set + if( $from eq $name || (grep $_ eq $name, @control_channels) || Irssi::settings_get_bool("bitlbee_typing_allwin") ){ + Irssi::statusbar_items_redraw('typing_notice'); + } +} + +sub event_msg { + my ($server,$data,$from,$address,$target) = @_; + return if $server->{tag} ne $bitlbee_server->{tag}; + my $channel=Irssi::active_win()->get_active_name(); + unset_typing $from, "no redraw"; + unset_typing $channel; +} + +sub event_quit { + my $server = shift; + return if $server->{tag} ne $bitlbee_server->{tag}; + my $nick = shift; + unset_typing $nick; +} + +sub typing_notice { + my ($item, $get_size_only) = @_; + my $window = Irssi::active_win(); + my $channel = $window->get_active_name(); + + if (exists($typing{$channel})) { + my $append=$typing{$channel}==2 ? " (stale)" : ""; + $item->default_handler($get_size_only, "{sb typing$append}", 0, 1); + } else { + $item->default_handler($get_size_only, "", 0, 1); + Irssi::timeout_remove($tag{$channel}); + delete($tag{$channel}); + } + # we check for correct windows again, because the statusbar item is redrawn after window change too. + if( (grep $_ eq $channel, @control_channels) || Irssi::settings_get_bool("bitlbee_typing_allwin")) { + foreach my $key (keys(%typing)) { + $line .= " ".$key; + if ($typing{$key}==2) { $line .= " (stale)"; } + } + if ($line ne "") { + $item->default_handler($get_size_only, "{sb typing:$line}", 0, 1); + $line = ""; + } + } +} + +sub window_change { + Irssi::statusbar_items_redraw('typing_notice'); + my $win = !Irssi::active_win() ? undef : Irssi::active_win()->{active}; + if (ref $win && ($win->{server}->{tag} eq $bitlbee_server->{tag})) { + if (!$keylog_active) { + $keylog_active = 1; + Irssi::signal_add_last('gui key pressed', 'key_pressed'); + } + } else { + if ($keylog_active) { + $keylog_active = 0; + Irssi::signal_remove('gui key pressed', 'key_pressed'); + } + } +} + +sub key_pressed { + return if !Irssi::settings_get_bool("bitlbee_send_typing"); + my $key = shift; + if ($key != 9 && $key != 10 && $lastkey != 27 && $key != 27 + && $lastkey != 91 && $key != 126 && $key != 127) + { + my $server = Irssi::active_server(); + my $window = Irssi::active_win(); + my $nick = $window->get_active_name(); + + if ($server->{tag} eq $bitlbee_server->{tag} && $nick ne "(status)" && $nick ne "root") { + if( grep $_ eq $nick, @control_channels ){ # send typing if in control channel + my $input = Irssi::parse_special("\$L"); + my ($first_word) = split(/ /,$input); + if ($input !~ /^$command_char.*/ && $first_word =~ s/$to_char$//){ + send_typing($first_word); + } + } else { # or any other channels / query + my $input = Irssi::parse_special("\$L"); + if ($input !~ /^$command_char.*/ && length($input) > 0){ + send_typing($nick); + } + } + } + } + $lastkey = $key; +} + +sub out_empty { + my ($a) = @_; + my($nick,$tag)=@{$a}; + delete($out_typing{$nick}); + Irssi::timeout_remove($timer_tag{$nick}); + delete($timer_tag{$nick}); + $bitlbee_server->command("^CTCP $nick TYPING 0"); +} + +sub send_typing { + my $nick = shift; + if (!exists($out_typing{$nick}) || time - $out_typing{$nick} > $KEEP_TYPING_TIMEOUT) { + $bitlbee_server->command("^CTCP $nick TYPING 1"); + $out_typing{$nick} = time; + ### Reset 'stop-typing' timer + Irssi::timeout_remove($timer_tag{$nick}); + delete($timer_tag{$nick}); + + ### create new timer + $timer_tag{$nick} = Irssi::timeout_add_once($STOP_TYPING_TIMEOUT*1000, 'out_empty', ["$nick", $bitlbee_server->{tag}]); + } +} + +#README: Delete the old bitlbee_send_typing string from ~/.irssi/config. A boolean is better. + +sub db_typing { + print "Detected channels: "; + print Dumper(@control_channels); + print "Detected server tag: ".$bitlbee_server->{tag}; + print "Tag: ".Dumper(%tag); + print "Timer Tag: ".Dumper(%timer_tag); + print "Typing: ".Dumper(%typing); + print "Out Typing: ".Dumper(%out_typing); +} + +Irssi::command_bind('db_typing','db_typing'); + +Irssi::settings_add_bool("bitlbee","bitlbee_send_typing",1); +Irssi::settings_add_bool("bitlbee","bitlbee_typing_allwin",0); + +Irssi::signal_add("ctcp msg", "event_ctcp_msg"); +Irssi::signal_add("message private", "event_msg"); +Irssi::signal_add("message public", "event_msg"); +Irssi::signal_add("message quit", "event_quit"); +Irssi::signal_add_last('window changed', 'window_change'); +Irssi::signal_add_last('gui key pressed', 'key_pressed'); +Irssi::statusbar_item_register('typing_notice', undef, 'typing_notice'); +Irssi::statusbars_recreate_items(); diff --git a/.irssi/scripts/extaway.pl b/.irssi/scripts/extaway.pl new file mode 100644 index 0000000..78e8392 --- /dev/null +++ b/.irssi/scripts/extaway.pl @@ -0,0 +1,194 @@ +# Away Manager +# +# This script allows you to have different automated +# actions on away +# +# - sets your nick, using a base and a keyword +# - in example: Crazy_Away +# - insert an away reason +# - say on all channels that your away +# +# This is my first IRSSI script, but I'll try to make it +# better soon. +# If you have ideas to improve it, or make it more efficient, +# contact me at crazycat@c-p-f.org + +use Irssi; +use Irssi::Irc; +use strict; + +use vars qw($VERSION %IRSSI); + +$VERSION = '1.0'; +%IRSSI = ( + authors => 'CrazyCat', + contact => 'crazycat@c-p-f.org', + name => 'ExtAway', + description => 'Extended Away & Back programm', + license => 'GNU GPLv2 or later', + changed => '$Date: 2005/01/12 03:04:01$' +); + +my $xa_confile = Irssi::get_irssi_dir()."/xa.config"; +my %infos = (); +my ($oldnick, $t_away); + +sub init { + # verifying if settings file exists + if (!(open xa_settings, "<$xa_confile")) { + putlog("No config file: /xahelp for help"); + return 0; + }; + # reading the config file + while (my $line = <xa_settings>) { + $line =~ s/\n//; + my ($xa_key,$xa_val) = split(/:/, $line); + $xa_key =~ tr/[A-Z]/[a-z]/; + if ($xa_val ne "") { + $infos{$xa_key} = $xa_val; + } + } + close xa_settings; +} + +sub xa_go { + # Main procedure to go away + my($data,$server,$channel) = @_; + my $xa_nick = ""; + my $xa_reason = ""; + if ($server->{usermode_away}) { + # oooops! already marged as away + &putlog("You're allready marqued as away ($server->{away_reason})"); + return 0; + } + $oldnick = $server->{nick}; + $t_away = time(); + my $t_data = split(/ /, $data); + if ($t_data < 2) { + # away called with just a keyword + $xa_nick = $data; + $xa_nick =~ tr/[A-Z]/[a-z]/; + $xa_reason = $infos{$xa_nick}; + } else { + # this is a new reason + ($xa_nick, $xa_reason) = $data =~ /^(\S+) (.*)/; + &xa_add($xa_nick, $xa_reason); + } + if ($xa_reason eq "") { + putlog("Sorry, <$xa_nick> is not defined"); + } else { + my $nick = "$infos{'bnick'}$xa_nick"; + foreach my $server (Irssi::servers) { + $server->command("AWAY $xa_reason"); + $server->command("NICK $nick"); + foreach my $chan ($server->channels) { + $server->command("DESCRIBE $chan->{name} is away [Reason: $xa_reason]"); + } + } + } +} + +sub xa_back { + # the way to be back + my($data,$server,$channel) = @_; + if (!$server->{usermode_away}) { + &putlog("You're not marqued as away"); + return 0; + } + my $delay = time() - $t_away; + my $f_delay = f_delay($delay); + foreach my $server (Irssi::servers) { + foreach my $chan ($server->channels) { + $server->command("DESCRIBE $chan->{name} is back from [$server->{away_reason}] - $f_delay away"); + } + $server->command("AWAY"); + $server->command("NICK $oldnick"); + } +} + +sub putlog { + # procedure to write in status window + my ($window) = Irssi::active_win(); + Irssi::print("[$IRSSI{'name'}] @_", MSGLEVEL_CLIENTNOTICE); + +} + +sub f_delay { + # formatting the away time + my $seconds = shift; + my ($hours, $minutes, $formated); + if ($seconds > 3600) { + $hours = int($seconds / 3600); + $formated .= $hours."h:"; + $seconds = $seconds - ($hours * 3600); + } + if ($seconds > 60) { + $minutes = int($seconds / 60); + $formated .= $minutes."m:"; + $seconds = $seconds - ($minutes * 60); + } + $formated .= $seconds."s"; + return $formated; +} + +sub xa_add { + # Adding the keyword and the reason in the config file + # may create double entries... + my($kw, $reason) = @_; + if(!(open xa_settings, ">>$xa_confile")) { + &putlog("Unable to open file $xa_confile"); + } + print xa_settings "$kw:$reason\n"; + close xa_settings; + $infos{$kw} = $reason; +} + +sub xa_save { + # save the temp infos (might correct the double entries) + my ($data,$server,$channel) = @_; + if(!(open xa_settings, ">$xa_confile")) { + &putlog("Unable to create file $xa_confile"); + } + print xa_settings "bnick:$infos{'bnick'}\n"; + while (my ($kw, $line) = each %infos) { + if ($kw ne "bnick") { + print xa_settings "$kw:$infos{$kw}\n"; + } + } + close xa_settings; +} + +sub xa_nick { + # The way to add the base nick + my ($data,$server,$channel) = @_; + if ($data eq "") { + putlog("You must define your base_nick") + } + $infos{'bnick'} = $data; + &xa_save; +} + +sub xa_help { + &putlog("Help for $IRSSI{name} : $IRSSI{description}"); + &putlog(" Setting your base nick: /xanick <base_nick>"); + &putlog(" Going away: /aw <keyword> [reason]"); + &putlog(" if keyword exists in the base, reason is automatically displayed"); + &putlog(" if keyword is a new one, you MUST give a reason"); + &putlog(" -- Nota: your away nick will be <base_nick><keyword> --"); + &putlog(" Coming back from away: /back"); + &putlog(" Saving all datas: /xasave (take care, setting your base_nick will save all your datas)"); +} +# +# main +# +&init(); +if ($infos{'bnick'} eq "") { + &putlog("Please, give a base nick with /xanick <base_nick>"); + &putlog("Use /xahelp to get some help"); +} +Irssi::command_bind("aw", "xa_go"); +Irssi::command_bind("back", "xa_back"); +Irssi::command_bind("xahelp", "xa_help"); +Irssi::command_bind("xanick", "xa_nick"); +Irssi::command_bind("xasave", "xa_save"); + diff --git a/.irssi/scripts/irccomplete.pl b/.irssi/scripts/irccomplete.pl new file mode 100644 index 0000000..bac2de1 --- /dev/null +++ b/.irssi/scripts/irccomplete.pl @@ -0,0 +1,210 @@ +# TAB complete words from dictionary +# for irssi 0.7.99 by Timo Sirainen +# Greatly modified by Erkki Seppälä to build dictionary of said words + +use Irssi; + +use vars qw($VERSION %IRSSI); +$VERSION = "0.1"; +%IRSSI = ( + authors => "Erkki Seppälä", + contact => "flux\@inside.org", + name => "IRC Completion", + description => "Adds words from IRC to your tab-completion list, plus fixes typos", + license => "Public Domain", + url => "http://xulfad.inside.org/~flux/software/irssi/", + changed => "Thu Feb 7 22:45:55 EET 2002" +); + + +my @wordHistory; +my %words; +my %permanent; + +my $wordChars = join("", ('a'..'z', '0'..'9', 'öä')); +my $maxWords = 5000; +my $minWordLength = 4; +my $maxWordLength = 80; +my $maxTypoLength = 10; +my $permanentThreshold = 1; + +my %typoWords; +my $correctWordCounter = 1; +my %correctWordsByIndex; +my %correctWordsByWord; + +# by word +sub addCorrectWord { + my $index = $correctWordsByWord{$_[0]} or 0; + if ($index > 0) { + ++$correctWordsByIndex{$index}->[1]; + return $index; + } else { + $correctWordsByIndex{$correctWordCounter} = [$_[0], 1]; + $correctWordsByWord{$_[0]} = $correctWordCounter; + ++$correctWordCounter; + return $correctWordCounter - 1; + } +}; + +# by word +sub delCorrectWord { + my ($word) = @_; + my $index = $correctWordsByWord{$word}; + if (--$correctWordsByIndex{$index}->[1] == 0) { + delete $correctWordsByWord{$correctWordsByIndex{$index}->[0]}; + delete $correctWordsByIndex{$index}; + } +} + +sub sig_complete { + my ($complist, $window, $word, $linestart, $want_space) = @_; + + $word =~ s/([^a-zA-Z0-9])/\\\1/g; + + @$complist = reverse (@$complist, grep(/^$word/, (keys %permanent, keys %words))); + + if (exists $typoWords{$word}) { + my $correctWord = $correctWordsByIndex{$typoWords{$word}->[0]}->[0]; + @$complist = (@complist, $correctWord); + } + + my %m = map { ($_ => $n++); } @$complist; + @$complist = (); + foreach my $key (sort keys %m) { + $m2{$m{$key}}=$key; + } + foreach my $key (reverse sort keys %m2) { + push @$complist, $m2{$key}; + } +} + +# $word, $removes +sub generate_drops { + my ($word, $changes) = @_; + my @list; + for (my $c = 0; $c < length($word) - 1; ++$c) { + my $misWord = substr($word, 0, $c) . substr($word, $c + 1); + if ($changes > 1) { + push @list, generate_drops($misWord, $changes - 1); + } else { + push @list, $misWord; + } + } + return @list; +} + +sub generate_translations { + my ($word, $changes) = @_; + my @list; + for (my $c = 1; $c < length($word); ++$c) { + my $misWord = substr($word, 0, $c - 1) . substr($word, $c, 1) . substr($word, $c - 1, 1) . substr($word, $c + 1); + if ($changes > 1) { + push @list, generate_drops($misWord, $changes - 1); + } else { + push @list, $misWord; + } + } + return @list; +} + +# $word +sub generate_typos { + my $maxTypoLength = Irssi::settings_get_int('irccomplete_maximum_typo_length'); + my ($word) = @_; + + if (length($word) > $maxTypoLength) { + return (); + } else { + return (generate_drops($word, 1), generate_translations($word)); + } +} + +sub sig_message { + my ($server, $message) = @_; + my $maxWords = Irssi::settings_get_int('irccomplete_words'); + my $minWordLength = Irssi::settings_get_int('irccomplete_minimum_length'); + my $maxWordLength = Irssi::settings_get_int('irccomplete_maximum_length'); + my $wordChars = Irssi::settings_get_str("irccomplete_word_characters"); + my $permanentThreshold = Irssi::settings_get_int('irccomplete_permanent_percent'); + foreach my $word (split(/[^$wordChars]/, $message)) { + if (length($word) >= $minWordLength && length($word) <= $maxWordLength) { + if (++$words{$word} > $permanentThreshold / 100.0 * $maxWords) { + if (++$permanent{$word} == 1) { + #Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'irccomplete_permanent', $word); + Irssi::print "Added $word to the list of permanent words"; + } + } + push @wordHistory, $word; + my $wordIndex = addCorrectWord($word); + foreach my $misword (generate_typos($word, 1)) { + if (!exists $typoWords{$misword}) { + $typoWords{$misword} = [$wordIndex, 1]; + } else { + ++$typoWords{$misword}->[1]; + } + } + while (@wordHistory > $maxWords) { + my $word = shift @wordHistory; + if (--$words{$word} == 0) { + delete $words{$word}; + } + foreach my $misword (generate_typos($word, 1)) { + if (--$typoWords{$misword}->[1] == 0) { + delete $typoWords{$misword}; + } + } + delCorrectWord($word); + } + } + } + + + return 1; +} + +sub cmd_typowords { + Irssi::print (scalar(@wordHistory) . " words, " . + scalar(keys %typoWords) . " typowords, " . + scalar(keys %correctWordsByWord) . "x" . scalar(keys %correctWordsByIndex) . " correct words"); + my $line = ""; + + foreach my $word (keys %typoWords) { + $line .= $word . "|" . $typoWords{$word}->[0] . " "; + } + Irssi::print "$line"; + $line = ""; + + foreach my $index (keys %correctWordsByIndex) { + $line .= $index . ":[" . join("|", @{$correctWordsByIndex{$index}}) . "] "; + } + Irssi::print "$line"; + $line = ""; + + foreach my $word (keys %correctWordsByWord) { + $line .= $word . ":" . $correctWordsByWord{$word} . " "; + } + Irssi::print "$line"; + $line = ""; + + return 1; +}; + +Irssi::theme_register(['irccomplete_permanent', 'Added $1 to the list of permanent words']); + +Irssi::settings_add_str("misc", "irccomplete_word_characters", $wordChars); +Irssi::settings_add_int("misc", "irccomplete_words", $maxWords); +Irssi::settings_add_int("misc", "irccomplete_minimum_length", $minWordLength); +Irssi::settings_add_int("misc", "irccomplete_maximum_length", $maxWordLength); +Irssi::settings_add_int("misc", "irccomplete_maximum_typo_length", $maxTypoLength); +Irssi::settings_add_int("misc", "irccomplete_permanent_percent", $permanentThreshold); + +foreach my $sig ("message public", "message private", + "message own_public", "message own_private", + "message topic") { +#foreach my $sig ("message own_public", "message own_private") { + Irssi::signal_add($sig, "sig_message"); +} +Irssi::signal_add_last('complete word', 'sig_complete'); + +Irssi::command_bind("irccomplete_typowords", "cmd_typowords"); diff --git a/.irssi/scripts/lastfm.pl b/.irssi/scripts/lastfm.pl new file mode 100644 index 0000000..4ff2105 --- /dev/null +++ b/.irssi/scripts/lastfm.pl @@ -0,0 +1,447 @@ +# vim: set expandtab: +use vars qw($VERSION %IRSSI); +$VERSION = "5.8"; +%IRSSI = ( + authors => "Simon 'simmel' Lundström", + contact => 'simmel@(freenode|quakenet|efnet) http://last.fm/user/darksoy', + name => "lastfm", + date => "20110125", + description => 'A now-playing-script which uses Last.fm', + license => "BSD", + url => "http://soy.se/code/", +); +# USAGE +# For details on how to use each setting, scroll down to the SETTINGS section. + +# QUICK START +# * First of all, you need the libwww/LWP package installed. The package in +# your package system is probably called something with libwww and perl and/or +# p5 in it. +# * /set lastfm_user to the username that you are using on Last.fm +# * Show with /np or %np<TAB> what song "lastfm_user" last scrobbled to Last.fm via /say. If "lastfm_use_action" is set, it uses /me. +# * To see what another user on Last.fm is playing is also possible via /np <username> or %np(<username>). +# The now-playing message is configurable via via "lastfm_output" (and lastfm_output_tab_complete when using %np, if not set it will use lastfm_output by default.). "lastfm_strftime" can be used to configure the display of date and time when the song was scrobbled. + +# SETTINGS +# NOTE: Do not set these options here, use /set <option> <value> in irssi! +# These are just defaults and descriptions on what the options do. + +# The username which you are using on Last.fm +Irssi::settings_add_str("lastfm", "lastfm_user", ""); + +# The output that you want to use. +# The substitution variables are: +# %artist = Self explanatory +# %album = Self explanatory +# %name = Name of song* +# %url = URL to song on Last.fm +# %player = Player we are using to submit to Last.fm with. See setting "lastfm_get_player" below +# %user = User that is playing, when /np <username> or %np(<username> is used +# If "lastfm_output_tab_complete" is not defined, "lastfm_output" will be used instead. +# Something bothered me for a long time and when something really starts to itch +# I tend to want to do something about it. I'm /np:ing away displaying all sorts +# of tracks to my friends until I get to a track which has no album information +# on Last.fm and the output becomes really ugly "np: Kraftwerk-Aerodynamik +# (Alex Gopher/Etienne de Crecy dynamik mix) ()". What's with that last ()!? Oh, +# right we are using "np: %artist-%name (%album)" as "lastfm_output". Wouldn't +# it be really cool if lastfm.pl knew when certain information from Last.fm +# didn't exist and didn't display it? So thought I, so that's why I created a +# conditional. It works that you have to put your tag (%album e.g.) within %() +# e.g. "np: %artist-%name%( (%album))" and everything between %( and ) only gets +# displayed if the tag inside actually exists! Cool, huh!? + +# *) Name is used instead of, the more logical IMO, track since that is what Last.fm reports in their .xml file that we parse. +Irssi::settings_add_str("lastfm", "lastfm_output", '%(%user is )np: %artist-%name'); +Irssi::settings_add_str("lastfm", "lastfm_output_tab_complete", ''); + +# If we should use /me instead of /say +Irssi::settings_add_bool("lastfm", "lastfm_use_action", 0); + +# If we should make the subtitution variable %player available which is very slow to fetch but nice to have. +Irssi::settings_add_bool("lastfm", "lastfm_get_player", 0); + +# Changelog#{{{ + +# 5.8 -- Tue Jan 25 16:11:29 CET 2011 +# * Ignore a closure warning + +# 5.7 -- Mon Jan 24 16:39:06 CET 2011 +# * Fixed a bug where we forked when we still waited for a reply from last.fm + +# 5.6 -- Sun Jul 18 13:16:38 CEST 2010 +# * Made substitution variable %user available when /np <username> or +# %np(<username>) is used. +# * Made some checks a bit more strict. + +# 5.5 -- Mon Jul 12 19:04:26 CEST 2010 +# * Rewrote the whole error handling +# * Fixed a bug where the error messages would be said and not printed. +# * Fixed some minor bugs and removed some unneeded code. + +# 5.4 -- Wed May 26 17:04:08 CEST 2010 +# * Last.fm updated their profile HTML so that the %player macro didn't work. +# Thanks to Keith Ward for mentioning this and suggesting a fix. +# * A minor fix which removes some debug messages when error reporting. + +# 5.3 -- +# * I used POSIX::_exit() but I never did "use POSIX;". Leo Green, mortiis and +# rissy reported this problem, thanks! This is an issue when you have a newer +# version of Perl installed (>5.10) + +# 5.2 -- Mon Nov 16 08:25:20 CET 2009 +# * When you remove a subroutine you should remove all calls to it.. + +# 5.1 -- Wed Nov 11 09:39:54 CET 2009 +# * Ok, I admit that using undocumented features in an API is bad, but come +# on.. Anyway, fixed now, everything should work as it should and should +# never break again (flw)... + +# 5.0 -- Mon Nov 9 08:34:48 CET 2009 +# * Fixed a warning reported by mm_mannen and did a yet another clean up + +# 4.9 -- Sat Nov 7 18:10:17 CET 2009 +# * Last.fm changed how their API behaved and that broke my code because +# I'm a fool and I don't want to use an XML-lib because of your sake (so you +# won't have to install yet another Perl-module). Thanks to supertobbe and +# mm_mannen who saw and reported this! +# * Fixed so that lastfm_get_player works again and made it say that it +# doesn't work next time Last.fm changes their HTML. +# * Removed the date support in lastfm_output and lastfm_output_tab_complete +# since I use the API another way now. +# * Removed cache. It was broken at times and I can't be arsed to debug it. +# It's not that much faster but the complexity gets bigger. If someone REALLY +# needs this, give me a shout. +# * Removed, rewrote and cleaned up some parts of the script. + +# 4.8 -- Sun May 10 10:11:29 CEST 2009 +# * Fixed a bug with the cache ('There are only two hard things in +# Computer Science: cache invalidation and naming things' -Phil Karlton) +# * Started using HTML::Entities for decoding all sorts of HTML-chars, it's +# included in libwww anyway. + +# 4.7 -- Tue Apr 8 13:37:11 CEST 2009 +# * Start using LWP::UserAgent instead of LWP::Simple and got rid of the idea to +# start using my own HTTP-lib (it was finished, but..). I'm getting old ; P +# * Made so that everything is cached and checks if the Last-Modified date when +# getting information from Last.fm. +# * Fixed some documentation bugs. + +# 4.6 -- Wed Mar 18 19:45:11 CET 2009 +# * Fixed an changed behavour in irssi-trunk with the error handling (which I should replace anyway!). +# * Added %player substitute variable that shows what application you are using to scrobble with. This is very slow, so I made it an option, "lastfm_get_player". +# * Fixed print_raw once and for all (famous last words..) so now debug output looks really neat. +# * Added an quick start which should help get going faster +# * Fixed an issue where %np(lastfmusername) would not work. +# * Fixed error mesages for %np(lastfmusername) +# * Fixed an problem with irssi-svn where die's message have changed. Thanks tto jnpplf for reporting this. + +# 4.5 -- Wed 1 Oct 2008 20:03:47 CEST +# * Removed a debug output +# * Fixed some datacorruption, references in Perl is hard! = ( + +# 4.4 -- Wed 1 Oct 2008 16:34:34 CEST +# * Changed so that all the tab-commands use % instead of $ so that it's consistent through out the script. +# * Ripped out my sprintf crap and made it more sane. You should use %artist, %album, etc in your nowplaying-setting now. Since sprintf is nolonger used I renamed that setting too. +# * Made everything that you can set in "lastfm_output" tabable so now you can do %artist<TAB>. +# %() in "lastfm_output" really works. It really didn't before. +# * Fixed some issues with the date probably not working, but should now. +# * Made the script check if Last.fm's scrobbler server is alive and kicking before we blame them. + +# 4.3 -- Mon 21 Jul 2008 08:46:36 CEST +# * Seem like I misunderstood the protocol. The date/time is only sent when we have scrobbled the track, not when we started to listen to it. + +# 4.2 -- Tue 15 Jul 2008 15:40:08 CEST +# Yay! Three new version within a day! (No, I'm not bored at work) +# * Made /np username and $np(username) make username the prefix of np: yadayada or whatever your lastfm_sprintf or lastfm_sprintf_tab_complete is. + +# 4.1 -- Tue 15 Jul 2008 15:23:03 CEST +# Well, that version lasted long! +# * Fixed a bug with /np not working. +# * Fixed an issue where debug info would be printed even if lastfm_debug was off. + +# 4.0 -- Tue 15 Jul 2008 10:17:51 CEST +# * Fixing a sprintfng-bug which didn't display time if album was not set. +# * Rewrote the whole script to use Last.fm's API which is very accurate. There is no need for $np! and /np! now, so I'm removing them. +# * Cleaned up abit. + +# 3.9 -- Fri 11 Jul 2008 21:49:20 CEST +# * Fixing a few bugs noticed by supertobbe + +# 3.8 -- Fri 11 Jul 2008 18:21:52 CEST +# * Shaped up error handling and now all error messages are shown. +# * Added a user configurable debug mode, good for sending in bugs and weird behaviour. +# * Minor cleanup + +# 3.7 -- Thu 22 May 2008 10:33:55 CEST +# * Fixed so that /np! and $np! fetches the album title too. This is horribly slow and takes approx. 6s on very fast connection. Last.fm isnt very fast I'm afraid and this is not a good way to do it. +# * Cleaned up a few places. Started to look at the error handling and it seems to be alot of work. + +# 3.6 -- Tue Nov 13 15:22:37 CET 2007 +# * Fixed encoding so that it always the data into the charset that you have specified in "term_charset" which irssi also uses. + +# 3.5 -- Mon Nov 12 11:50:46 CET 2007 +# * Fixed the regex for parsing Recently Listened Tracks so that it works when listening with the Lastfm client. + +# 3.4 -- Fri Nov 9 00:23:40 CET 2007 +# * Added /np lastfmusername + +# 3.3 -- Tue Nov 6 01:54:59 CET 2007 +# * Finally added conditional sprintf-syntax! Let's say you want to use 'np: %s-%s (%s)' as "lastfm_sprintf". If you use /np it works out fine and displays 'np: Boards of Canada-Energy Warning (Geogaddi)' but what if you use /np! then it displays 'np: Boards of Canada-Energy Warning ()' since /np! can't get the album information. Doesn't that look ugly? Meet conditional sprintf. Now set your "lastfm_sprintf" to 'np: %s-%s%( (%s))'. ' (%s)' will only be printed if we get a third value, the album name in this case. Smart, huh? Big thanks to rindolf, apeiron and Khisanth from #perl@freenode for help with scoping with global variables. +# * Also added "lastfm_sprintf_tab_complete" which makes, if set, $np<TAB> use a different sprintf pattern than /np. Will default back to "lastfm_sprintf". + +# 3.2 -- Wed Oct 24 23:07:01 CEST 2007 +# * I don't like dependencies and I really wonder why I lastfm depended on DateTime. I remember now that it was morning and I was really tired when I coded it. Anyway, it's removed now along with Socket and URI::Escape. I'll try to remove the dependency for libwww later on. + +# 3.1 -- Sun Oct 21 22:52:36 CEST 2007 +# * Added /np! and $np! to use the "lastfm_be_accurate_and_slow" method without having to change the setting. + +# 3.0 -- Fri Oct 19 14:26:03 CEST 2007 +# * Created a new setting "lastfm_be_accurate_and_slow" which makes lastfm.pl parse your profile page to check what song you are playing right now. But be warned, this is slow and horrible (like my code! ; ). But it works until Last.fm makes this data available through their Web Services. This disables the album and "scrobbled at" features of "lastfm_sprintf" so you have to adapt it if you don't want it to look weird. I'm working on a new implementation of printf which allows for conditions but it took more time than I thought and time is something that I don't have much of ='( + +# 2.5 -- Tue Oct 9 11:29:56 CEST 2007 +# * Fixed the encoding issue by converting from Last.fms UTF-8 into Perls internal encoding. With $np<TAB> output will be looking UTF-8-in-latin1 if you don't have an UTF-8 enabled Terminal, but it will display correctly after you have sent it. + +# 2.4 -- Mon Oct 8 16:08:09 CEST 2007 +# * Fixed an error in error reporting ; P Bug noticed by supertobbe = * +# * I should make an more generic and better error reporting. + +# 2.3 -- Sat Oct 6 16:38:34 CEST 2007 +# * Made /np a nonblocking operation. Irssi's fork handling is REALLY messy. Thanks to tss and tommie for inspiring me in their scripts. $np cannot be made nonblocking, I'm afraid (patches welcome). +# * Cleaned up abit. + +# 2.2 -- Sat Aug 18 02:20:44 CEST 2007 +# * Now you can use $np(darksoy) to see what I play (or someone else for that matter ; ). + +# 2.1 -- Tue Jul 17 12:50:18 CEST 2007 +# * Now you can use $np or $nowplaying as a tab-completion too, but a warning here, this is a blocking action so irssi won't respond or be usable until it is finished or the timeout is hit. +# * Abstracted it abit more so that it can be used in more ways, ex. for the reason above. + +# 2.0 -- Fri Jun 29 10:38:32 CEST 2007 +# * Now you can show the time that the song was submitted in lastfm_sprintf. Added lastfm_strftime to configure how the date is presented. +# * Added $lastfm and $lfm as tab-completions to your own Last.fm profile URL. Ripoff of Jured's guts.pl (http://juerd.nl/irssi/) + +# 1.5 -- Sat May 12 03:30:24 CEST 2007 +# * Started using XML instead because we get more info from it, like album (but it's often wrong). + +# 1.0 -- Thu Apr 12 16:57:26 CEST 2007 +# * Got fedup with no good Last.fm-based now playing scripts around. + +# THANKS +# Random individuals on #perl@freenode, could namedrop icke, +# }}} + +# TODO +# You tell me! + +# Move along now, there's nothing here to see. + +sub DEBUG { + Irssi::settings_add_bool("lastfm", "lastfm_debug", 0); + Irssi::settings_get_bool("lastfm_debug"); +}; + +use strict; +use warnings; +no warnings 'closure'; +use Data::Dumper; +use Encode; +use HTML::Entities; +use Irssi; +use LWP::UserAgent; +use POSIX; + +my $pipe_tag; +my $waiting_for_reply; +my $api_key = "eba9632ddc908a8fd7ad1200d771beb7"; +my $fields = "(artist|name|album|url|player|user)"; +my $ua = LWP::UserAgent->new(agent => "lastfm.pl/$VERSION", timeout => 10); + +sub lastfm_nowplaying { + my ($content, $url, $response, $tag, $value, %data); + my ($user_shifted, $is_tabbed, $nowplaying, $witem) = @_; + my $user = $user_shifted || Irssi::settings_get_str("lastfm_user"); + $nowplaying ||= ((Irssi::settings_get_str("lastfm_output_tab_complete") ne "" && $is_tabbed) ? Irssi::settings_get_str("lastfm_output_tab_complete") : Irssi::settings_get_str("lastfm_output")); + + my $command_message = ($is_tabbed) ? '%%np(username)' : '/np username'; + if ($user eq '') { + return "ERROR: You must /set lastfm_user to a username on Last.fm or use $command_message"; + } + + if ($nowplaying =~ /^%(lastfm|lfm)$/) { + return "http://last.fm/user/$user/"; + } + elsif ($nowplaying =~ /^%user$/) { + return $user; + } + + $data{'user'} = $user if ($user_shifted); + + $url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$user&api_key=$api_key&limit=1"; + print Dumper "Checking for scrobbles at: $url" if DEBUG; + $response = $ua->get($url); + $content = $response->content; + + # TODO This should work, untested (fail more Last.fm! ; ) + if ($content =~ m!<lfm status="failed">.*<error .*?>([^<]+)!s) { + return "ERROR: $1"; + } + my @data = split('\n', $content); + + if (!grep(m!<track nowplaying="true">!, @data)) { + print Dumper \$response if DEBUG; + print Dumper \$content if DEBUG; + return "ERROR: You are not playing anything according to Last.fm. Check http://www.last.fm/user/$user and see if they turn up there, otherwise restart your scrobbler."; + } + + my $regex = qr!<$fields.*?(?:uts="(.*?)">.*?|>(.*?))</\1>!; + + foreach my $data (@data) { + if ($data =~ m!</track>!) { + last; + } + elsif ($data =~ /$regex/) { + ($tag, $value) = ($1, (defined($2) ? $2 : $3)); + print Dumper \$tag, \$value, \$data if DEBUG; + $data{$tag} = $value; + } + } + + if (Irssi::settings_get_bool("lastfm_get_player")) { + $url = "http://www.last.fm/user/$user"; + $content = $ua->get($url)->content; + if ($content =~ m!<span class="source">(.*?)</span>!) { + $_ = $1; + s/<[^>]*>//mgs; + $data{'player'} = $_; + } + else { + print "Couldn't find the player even though lastfm_get_player was set" if DEBUG; + } + } + + print Dumper \%data if DEBUG; + print Dumper "Output pattern before: $nowplaying" if DEBUG; + $nowplaying =~ s/(%\((.*?%(\w+).?)\))/($data{$3} ? $2 : "")/ge; + print Dumper "Output pattern after: $nowplaying" if DEBUG; + $nowplaying =~ s/%$fields/$data{$1}/ge; + decode_entities($nowplaying); + Encode::from_to($nowplaying, "utf-8", Irssi::settings_get_str("term_charset")); + return $nowplaying; +} + +sub lastfm_blocking { + my ($witem, $user) = @_; + my $nowplaying = lastfm_nowplaying($user, undef, undef, $witem); + lastfm_print($witem, $nowplaying); +} + +sub lastfm_forky { + my ($witem, $user) = @_; + if ($waiting_for_reply) { + lastfm_print(Irssi::active_win(), "We are still waiting for Last.fm to return our results"); + return; + } + # pipe is used to get the reply from child + my ($rh, $wh); + pipe($rh, $wh); + + # non-blocking host lookups with fork()ing + my $pid = fork(); + if (!defined($pid)) { + Irssi::print("Can't fork() - aborting"); + close($rh); + close($wh); + return; + } + + $waiting_for_reply = 1; + + if ($pid > 0) { + # parent, wait for reply + close($wh); + Irssi::pidwait_add($pid); + $pipe_tag = Irssi::input_add(fileno($rh), INPUT_READ, \&pipe_input, [$witem, $rh]); + return; + } + + my $text; + eval { + # child, do the lookup + $text = lastfm_nowplaying($user); + }; + + if (!$text) { + $text = "ERROR: Error message: $!"; + } + + eval { + # write the reply + print($wh $text); + close($wh); + }; + POSIX::_exit(1); +} + + +sub pipe_input { + my ($witem, $rh) = @{$_[0]}; + my $text = <$rh>; + close($rh); + + Irssi::input_remove($pipe_tag); + $pipe_tag = -1; + undef $waiting_for_reply; + + lastfm_print($witem, $text); +} + +sub lastfm_print { + my ($witem, $text, $tabbed) = @_; + # Fugly error handling + if ($text =~ s/^ERROR: //) { + Irssi::active_win()->print($text); + return; + } + + if ($tabbed) { + return $text; + } + elsif (defined $witem->{type} && $witem->{type} =~ /^QUERY|CHANNEL$/) { + if (Irssi::settings_get_bool("lastfm_use_action")) { + $witem->command("me $text"); + } + else { + $witem->command("say $text"); + } + } + else { + Irssi::active_win()->print($text); + } +} + +Irssi::command_bind('np', sub { + my ($data, $server, $witem) = @_; + $data =~ s/ .*//; + $data ||= 0; + if (DEBUG) { + lastfm_blocking($witem, $data); + } + else { + lastfm_forky($witem, $data); + } + }, 'lastfm'); + +Irssi::signal_add_last 'complete word' => sub { + my ($complist, $window, $word, $linestart, $want_space) = @_; + my $is_tabbed = 1; + my $tab_fields = $fields; + $tab_fields =~ s/\(/(nowplaying|np|lastfm|lfm|/; + if ($word =~ /(\%(?:$tab_fields))\(?(\w+)?\)?/) { + my ($nowplaying, $user) = ($1, $3); + undef $nowplaying if ($nowplaying =~ /nowplaying|np/); + $nowplaying = lastfm_nowplaying($user, $is_tabbed, $nowplaying); + if (lastfm_print(Irssi::active_win(), $nowplaying, 1)) { + push @$complist, "$nowplaying"; + } + } +}; diff --git a/.irssi/scripts/ls.pl b/.irssi/scripts/ls.pl new file mode 100644 index 0000000..6481081 --- /dev/null +++ b/.irssi/scripts/ls.pl @@ -0,0 +1,40 @@ +use vars qw($VERSION %IRSSI); + +use Irssi 20020120; +$VERSION = "0.02"; +%IRSSI = ( + authors => "c0ffee", + contact => "c0ffee\@penguin-breeder.org", + name => "List nicks in channel", + description => "Use /ls <regex> to show all nicks (including ident\@host) matching regex in the current channel", + license => "Public Domain", + url => "http://www.penguin-breeder.org/irssi/", + changed => "Fri Sep 06 15:36 CEST 2002", +); + + +sub cmd_ls { + my ($data, $server, $channel) = @_; + my @nicks; + my $n; + my $nick; + + if ($channel->{type} ne "CHANNEL") { + + Irssi::print("Your are not on a channel"); + return; + + } + + @nicks = $channel->nicks(); + + foreach $nick (@nicks) { + + $n = $nick->{nick} . "!" . $nick->{host}; + + $channel->print("$n") if $n =~ /$data/i; + + } +} + +Irssi::command_bind('ls','cmd_ls'); diff --git a/.irssi/scripts/nicklist.pl b/.irssi/scripts/nicklist.pl new file mode 100644 index 0000000..0ef687a --- /dev/null +++ b/.irssi/scripts/nicklist.pl @@ -0,0 +1,805 @@ +# This script adds a nicklist to the right of irssi +# for documentation: see http://wouter.coekaerts.be/site/irssi/nicklist + +# Copyright (C) 2002-2007 Wouter Coekaerts <coekie@irssi.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +use Irssi; +use strict; +use IO::Handle; # for (auto)flush +use Fcntl; # for sysopen +use vars qw($VERSION %IRSSI); +$VERSION = '0.4.6+'; +%IRSSI = ( + authors => 'Wouter Coekaerts', + contact => 'coekie@irssi.org', + name => 'nicklist', + description => 'draws a nicklist to another terminal, or at the right of your irssi in the same terminal', + license => 'GPLv2+', + url => 'http://wouter.coekaerts.be/irssi', + changed => '$LastChangedDate$' +); + +sub cmd_help { + print ( <<EOF +Commands: +NICKLIST HELP +NICKLIST SCROLL <nr of lines> +NICKLIST SCREEN +NICKLIST FIFO +NICKLIST OFF +NICKLIST UPDATE + +For help see: http://wouter.coekaerts.be/site/irssi/nicklist + +in short: + +1. FIFO MODE +- in irssi: /NICKLIST FIFO (only the first time, to create the fifo) +- in a shell, in a window where you want the nicklist: cat ~/.irssi/nicklistfifo +- back in irssi: + /SET nicklist_heigth <height of nicklist> + /SET nicklist_width <width of nicklist> + /NICKLIST FIFO + +2. SCREEN MODE +- start irssi inside screen ("screen irssi") +- /NICKLIST SCREEN +EOF + ); +} + +my $prev_lines = 0; # number of lines in previous written nicklist +my $scroll_pos = 0; # scrolling position +my $cursor_line; # line the cursor is currently on +my ($OFF, $SCREEN, $FIFO) = (0,1,2); # modes +my $mode = $OFF; # current mode +my $need_redraw = 0; # nicklist needs redrawing +my $screen_resizing = 0; # terminal is being resized +my $active_channel; # (REC) + +my @nicklist=(); # array of hashes, containing the internal nicklist of the active channel + # nick => realnick + # modeflag => '@', '%', '+', or other mode char + # modepos => number representing the position in which to sort nicks with that mode + # status => (not used yet...) + #my ($STATUS_NORMAL, $STATUS_JOINING, $STATUS_PARTING, $STATUS_QUITING, $STATUS_KICKED, $STATUS_SPLIT) = (0,1,2,3,4,5); + # text => text to be printed + # cmp => text used to compare (sort) nicks + + +# 'cached' settings +my ($screen_prefix, $irssi_width, %prefix_mode, @prefix_status, $height, $nicklist_width, $check_friends, @prefix_friends); + +sub read_settings { + ($screen_prefix = Irssi::settings_get_str('nicklist_screen_prefix')) =~ s/\\e/\033/g; + + ($prefix_mode{'@'} = Irssi::settings_get_str('nicklist_prefix_mode_op')) =~ s/\\e/\033/g; + ($prefix_mode{'%'} = Irssi::settings_get_str('nicklist_prefix_mode_halfop')) =~ s/\\e/\033/g; + ($prefix_mode{'+'} = Irssi::settings_get_str('nicklist_prefix_mode_voice')) =~ s/\\e/\033/g; + ($prefix_mode{' '} = Irssi::settings_get_str('nicklist_prefix_mode_normal')) =~ s/\\e/\033/g; + + (my $prefix_mode_other = Irssi::settings_get_str('nicklist_prefix_mode_other')) =~ s/\\e/\033/g; + foreach my $p (split (/ /, $prefix_mode_other)) { + next if $p eq ''; + if ($p !~ /(.)=(.*)/) { + Irssi::print("Could not parse nicklist_prefix_mode_other part '$p'. Expected space separated list of <mode character>=<prefix>"); + last; + } else { + $prefix_mode{$1} = $2; + } + } + + (my $prefix_friends = Irssi::settings_get_str('nicklist_prefix_friends')) =~ s/\\e/\033/g; + foreach my $p (split (/ /, $prefix_friends)) { + next if $p eq ''; + if ($p !~ /(.+?)=(.*)/) { + Irssi::print("Could not parse nicklist_prefix_friends part '$p'. Expected space separated list of <flags>=<prefix>"); + last; + } else { + push @prefix_friends, {'flags' => $1, 'prefix' => $2}; + } + } + + $check_friends = ($prefix_friends ne ''); + + if ($mode != $SCREEN) { + $height = Irssi::settings_get_int('nicklist_height'); + } + my $new_nicklist_width = Irssi::settings_get_int('nicklist_width'); + if ($new_nicklist_width != $nicklist_width && $mode == $SCREEN) { + sig_terminal_resized(); + } + $nicklist_width = $new_nicklist_width; +} + +sub update { + read_settings(); + make_nicklist(); +} + +################## +##### OUTPUT ##### +################## + +### off ### + +sub cmd_off { + if ($mode == $SCREEN) { + screen_stop(); + } elsif ($mode == $FIFO) { + fifo_stop(); + } +} + +### fifo ### + +sub cmd_fifo_start { + read_settings(); + my $path = Irssi::settings_get_str('nicklist_fifo_path'); + unless (-p $path) { # not a pipe + if (-e _) { # but a something else + die "$0: $path exists and is not a pipe, please remove it\n"; + } else { + require POSIX; + POSIX::mkfifo($path, 0666) or die "can\'t mkfifo $path: $!"; + Irssi::print("Fifo created. Start reading it (\"cat $path\") and try again."); + return; + } + } + if (!sysopen(FIFO, $path, O_WRONLY | O_NONBLOCK)) { # or die "can't write $path: $!"; + Irssi::print("Couldn\'t write to the fifo ($!). Please start reading the fifo (\"cat $path\") and try again."); + return; + } + FIFO->autoflush(1); + print FIFO "\033[2J\033[1;1H"; # erase screen & jump to 0,0 + $cursor_line = 0; + if ($mode == $SCREEN) { + screen_stop(); + } + $mode = $FIFO; + make_nicklist(); +} + +sub fifo_stop { + close FIFO; + $mode = $OFF; + Irssi::print("Fifo closed."); +} + +### screen ### + +sub cmd_screen_start { + if (!defined($ENV{'STY'})) { + Irssi::print 'screen not detected, screen mode only works inside screen'; + return; + } + read_settings(); + if ($mode == $SCREEN) {return;} + if ($mode == $FIFO) { + fifo_stop(); + } + $mode = $SCREEN; + Irssi::signal_add_last('gui print text finished', \&sig_gui_print_text_finished); + Irssi::signal_add_last('gui page scrolled', \&sig_page_scrolled); + Irssi::signal_add('terminal resized', \&sig_terminal_resized); + screen_size(); + make_nicklist(); +} + +sub screen_stop { + $mode = $OFF; + Irssi::signal_remove('gui print text finished', \&sig_gui_print_text_finished); + Irssi::signal_remove('gui page scrolled', \&sig_page_scrolled); + Irssi::signal_remove('terminal resized', \&sig_terminal_resized); + system 'screen -x '.$ENV{'STY'}.' -X fit'; +} + +sub screen_size { + if ($mode != $SCREEN) { + return; + } + $screen_resizing = 1; + # fit screen + system 'screen -x '.$ENV{'STY'}.' -X fit'; + # we wait a second to make sure the fit command was processed + Irssi::timeout_add_once(1000, \&screen_size_real, []); +} + +sub screen_size_real { + # get size (from perldoc -q size) + my ($winsize, $row, $col, $xpixel, $ypixel); + eval 'use Term::ReadKey; ($col, $row, $xpixel, $ypixel) = GetTerminalSize'; + # require Term::ReadKey 'GetTerminalSize'; + # ($col, $row, $xpixel, $ypixel) = Term::ReadKey::GetTerminalSize; + #}; + if ($@) { # no Term::ReadKey, try the ugly way + eval { + require 'sys/ioctl.ph'; + # without this reloading doesn't work. workaround for some unknown bug + do 'asm/ioctls.ph'; + }; + + # ugly way not working, let's try something uglier, the dg-hack(tm) (constant for linux only?) + if($@) { no strict 'refs'; *TIOCGWINSZ = sub { return 0x5413 } } + + unless (defined &TIOCGWINSZ) { + die "Term::ReadKey not found, and ioctl 'workaround' failed. Install the Term::ReadKey perl module to use screen mode.\n"; + } + open(TTY, "+</dev/tty") or die "No tty: $!"; + unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) { + die "Term::ReadKey not found, and ioctl 'workaround' failed ($!). Install the Term::ReadKey perl module to use screen mode.\n"; + } + close(TTY); + ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize); + } + + # set screen width + $irssi_width = $col-$nicklist_width-1; + $height = $row-1; + + system 'screen -x '.$ENV{'STY'}.' -X width -w ' . $irssi_width; + # wait another second for the resizing, and then redraw. + Irssi::timeout_add_once(1000,sub {$screen_resizing = 0; redraw()}, []); +} + +sub sig_terminal_resized { + if ($screen_resizing) { + return; + } + $screen_resizing = 1; + Irssi::timeout_add_once(1000,\&screen_size,[]); +} + + +### both ### + +sub nicklist_write_start { + if ($mode == $SCREEN) { + print STDERR "\033P\033[s\033\\"; # save cursor + } +} + +sub nicklist_write_end { + if ($mode == $SCREEN) { + print STDERR "\033P\033[u\033\\"; # restore cursor + } +} + +sub nicklist_write_line { + my ($line, $data) = @_; + if ($mode == $SCREEN) { + print STDERR "\033P\033[" . ($line+1) . ';'. ($irssi_width+1) .'H'. $screen_prefix . $data . "\033\\"; + } elsif ($mode == $FIFO) { + $data = "\033[m$data"; # reset color + if ($line == $cursor_line+1) { + $data = "\n$data"; # next line + } elsif ($line == $cursor_line) { + $data = "\033[1G".$data; # back to beginning of line + } else { + $data = "\033[".($line+1).";0H".$data; # jump + } + $cursor_line=$line; + print(FIFO $data) or fifo_stop(); + } +} + +sub calc_prefix_friends { + my ($nick) = @_; + + return '' unless $check_friends + && $nick->{'host'} + && is_friend($active_channel->{'server'}->{'chatnet'}, $active_channel->{'name'}, $nick->{'nick'}, $nick->{'host'}); + + my $flags = get_flags($active_channel->{'server'}->{'chatnet'}, $active_channel->{'name'}, $nick->{'nick'}, $nick->{'host'}); + + my $prefix; + foreach my $prefix_friend (@prefix_friends) { + if ($prefix_friend->{'flags'} eq 'noflag') { + if ($flags eq '') { + $prefix = $prefix_friend->{'prefix'}; + last; + } + } elsif (check_modes($flags, $prefix_friend->{'flags'})) { + $prefix = $prefix_friend->{'prefix'}; + } + } + + return $prefix ? $prefix : ''; +} + +# recalc the text of the nicklist item +sub calc_text { + my ($nick) = @_; + my $tmp = $nicklist_width-3; + (my $text = $nick->{'nick'}) =~ s/^(.{$tmp})..+$/$1\033[34m~/; # strip nick if too long + + my $prefix_mode = $prefix_mode{$nick->{'modeflag'}}; + if (! defined($prefix_mode) ) { + $prefix_mode = $nick->{'modeflag'}; + } + + my $prefix_friends = calc_prefix_friends($nick); + + $nick->{'text'} = + $prefix_mode . + $prefix_friends . + $text . + (' ' x ($nicklist_width-length($nick->{'nick'})-1)) . + "\033[m"; # reset + $nick->{'cmp'} = $nick->{'modepos'}.lc($nick->{'nick'}); +} + +# redraw the given nick (nr) if it is visible +sub redraw_nick_nr { + my ($nr) = @_; + my $line = $nr - $scroll_pos; + if ($line >= 0 && $line < $height) { + nicklist_write_line($line, $nicklist[$nr]->{'text'}); + } +} + +# nick was inserted, redraw area if necessary +sub draw_insert_nick_nr { + my ($nr) = @_; + my $line = $nr - $scroll_pos; + if ($line < 0) { # nick is inserted above visible area + $scroll_pos++; # 'scroll' down :) + } elsif ($line < $height) { # line is visible + if ($mode == $SCREEN) { + need_redraw(); + } elsif ($mode == $FIFO) { + my $data = "\033[m\033[L". $nicklist[$nr]->{'text'}; # reset color & insert line & write nick + if ($line == $cursor_line) { + $data = "\033[1G".$data; # back to beginning of line + } else { + $data = "\033[".($line+1).";1H".$data; # jump + } + $cursor_line=$line; + print(FIFO $data) or fifo_stop(); + if ($prev_lines < $height) { + $prev_lines++; # the nicklist has one line more + } + } + } +} + +sub draw_remove_nick_nr { + my ($nr) = @_; + my $line = $nr - $scroll_pos; + if ($line < 0) { # nick removed above visible area + $scroll_pos--; # 'scroll' up :) + } elsif ($line < $height) { # line is visible + if ($mode == $SCREEN) { + need_redraw(); + } elsif ($mode == $FIFO) { + #my $data = "\033[m\033[L[i$line]". $nicklist[$nr]->{'text'}; # reset color & insert line & write nick + my $data = "\033[M"; # delete line + if ($line != $cursor_line) { + $data = "\033[".($line+1)."d".$data; # jump + } + $cursor_line=$line; + print(FIFO $data) or fifo_stop(); + if (@nicklist-$scroll_pos >= $height) { + redraw_nick_nr($scroll_pos+$height-1); + } + } + } +} + +# redraw the whole nicklist +sub redraw { + $need_redraw = 0; + #make_nicklist(); + nicklist_write_start(); + my $line = 0; + ### draw nicklist ### + for (my $i=$scroll_pos;$line < $height && $i < @nicklist; $i++) { + nicklist_write_line($line++, $nicklist[$i]->{'text'}); + } + + ### clean up other lines ### + my $real_lines = $line; + while($line < $prev_lines) { + nicklist_write_line($line++,' ' x $nicklist_width); + } + $prev_lines = $real_lines; + nicklist_write_end(); +} + +# redraw (with little delay to avoid redrawing to much) +sub need_redraw { + if(!$need_redraw) { + $need_redraw = 1; + Irssi::timeout_add_once(10,\&redraw,[]); + } +} + +sub sig_page_scrolled { + $prev_lines = $height; # we'll need to redraw everything if he scrolled up + need_redraw; +} + +# redraw (with delay) if the window is visible (only in screen mode) +sub sig_gui_print_text_finished { + if ($need_redraw) { # there's already a redraw 'queued' + return; + } + my $window = @_[0]; + if ($window->{'refnum'} == Irssi::active_win->{'refnum'} || Irssi::settings_get_str('nicklist_screen_split_windows') eq '*') { + need_redraw; + return; + } + foreach my $win (split(/[ ,]/, Irssi::settings_get_str('nicklist_screen_split_windows'))) { + if ($window->{'refnum'} == $win || $window->{'name'} eq $win) { + need_redraw; + return; + } + } +} + +################### +##### FRIENDS ##### +################### + +# checks if $has_modes is in $need_modes, copied from trigger.pl +sub check_modes { + my ($has_modes, $need_modes) = @_; + my $matches; + my $switch = 1; # if a '-' if found, will be 0 (meaning the modes should not be set) + foreach my $need_mode (split /&/,$need_modes) { + $matches = 0; + foreach my $char (split //,$need_mode) { + if ($char eq '-') { + $switch = 0; + } elsif ($char eq '+') { + $switch = 1; + } elsif ((index($has_modes,$char) != -1) == $switch) { + $matches = 1; + last; + } + } + if (!$matches) { + return 0; + } + } + return 1; +} + +# get someones flags from people.pl or friends(_shasta).pl, copied from trigger.pl +sub get_flags { + my ($chatnet, $channel, $nick, $address) = @_; + my $flags; + no strict 'refs'; + if (defined %{ 'Irssi::Script::people::' }) { + if (defined ($channel)) { + $flags = (&{ 'Irssi::Script::people::find_local_flags' }($chatnet,$channel,$nick,$address)); + } else { + $flags = (&{ 'Irssi::Script::people::find_global_flags' }($chatnet,$nick,$address)); + } + $flags = join('',keys(%{$flags})); + } else { + my $shasta; + if (defined %{ 'Irssi::Script::friends_shasta::' }) { + $shasta = 'friends_shasta'; + } elsif (defined &{ 'Irssi::Script::friends::get_idx' }) { + $shasta = 'friends'; + } + if (!$shasta) { + return undef; + } + my $idx = (&{ 'Irssi::Script::'.$shasta.'::get_idx' }($nick,$address)); + if ($idx == -1) { + return ''; + } + $flags = (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,undef)); + if ($channel) { + $flags .= (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,$channel)); + } + } + return $flags; +} + +sub is_friend { + my ($chatnet, $channel, $nick, $address) = @_; + no strict 'refs'; + if (defined %{ 'Irssi::Script::people::' }) { + return (() != &{'Irssi::Script::people::find_users'}($chatnet, $nick, $address)); + my $flags; + if (defined ($channel)) { + $flags = (&{ 'Irssi::Script::people::find_local_flags' }($chatnet,$channel,$nick,$address)); + } else { + $flags = (&{ 'Irssi::Script::people::find_global_flags' }($chatnet,$nick,$address)); + } + return ($flags ne ''); # TODO: test this + } else { + my $shasta; + if (defined %{ 'Irssi::Script::friends_shasta::' }) { + $shasta = 'friends_shasta'; + } elsif (defined &{ 'Irssi::Script::friends::get_idx' }) { + $shasta = 'friends'; + } + if (!$shasta) { + return undef; + } + my $idx = (&{ 'Irssi::Script::'.$shasta.'::get_idx' }($nick,$address)); + return ($idx != -1); + } +} + +#################### +##### NICKLIST ##### +#################### + +# returns the position of the given nick(as string) in the (internal) nicklist +sub find_nick { + my ($nick) = @_; + for (my $i=0;$i < @nicklist; $i++) { + if ($nicklist[$i]->{'nick'} eq $nick) { + return $i; + } + } + return -1; +} + +# find position where nick should be inserted into the list +sub find_insert_pos { + my ($cmp)= @_; + for (my $i=0;$i < @nicklist; $i++) { + if ($nicklist[$i]->{'cmp'} gt $cmp) { + return $i; + } + } + return scalar(@nicklist); #last +} + +# make the (internal) nicklist (@nicklist) +sub make_nicklist { + @nicklist = (); + $scroll_pos = 0; + + ### get & check channel ### + my $channel = Irssi::active_win->{active}; + + if (!$channel || (ref($channel) ne 'Irssi::Irc::Channel' && ref($channel) ne 'Irssi::Silc::Channel') || $channel->{'type'} ne 'CHANNEL' || ($channel->{chat_type} ne 'SILC' && !$channel->{'names_got'}) ) { + $active_channel = undef; + # no nicklist + } else { + $active_channel = $channel; + ### make nicklist ### + foreach my $nick ($channel->nicks()) { + my $thisnick = {'nick' => $nick->{'nick'}}; + recalc_nick($thisnick, $nick); + push @nicklist, $thisnick; + } + @nicklist = sort {$a->{'cmp'} cmp $b->{'cmp'}} @nicklist; + } + need_redraw(); +} + +# insert nick(as hash) into nicklist +# pre: cmp has to be calculated +sub insert_nick { + my ($nick) = @_; + my $nr = find_insert_pos($nick->{'cmp'}); + splice @nicklist, $nr, 0, $nick; + draw_insert_nick_nr($nr); +} + +# remove nick(as nr) from nicklist +sub remove_nick { + my ($nr) = @_; + splice @nicklist, $nr, 1; + draw_remove_nick_nr($nr); +} + +# update the mode and cmp of a nick, based on a nickrec from irssi +sub recalc_nick { + my ($nick, $nickrec) = @_; + if (! $nickrec) { + $nickrec = $active_channel->nick_find($nick->{'nick'}); + } + + my $nickflags = $active_channel->{'server'}->get_nick_flags() . ' '; + + my $flag = ( + $nickrec->{'op'} ? '@' : + $nickrec->{'halfop'} ? '%' : + $nickrec->{'voice'} ? '+' : + ' ' + ); + + if ($nickrec->{'other'} && index($nickflags, $nick->{'other'}) < index($nickflags, $flag)) { + $flag = chr($nickrec->{'other'}); + } + + $nick->{'modepos'} = index($nickflags, $flag); + $nick->{'modeflag'} = $flag; + + $nick->{'host'} = $nickrec->{'host'}; + calc_text($nick); +} + +################### +##### ACTIONS ##### +################### + +# scroll the nicklist, arg = number of lines to scroll, positive = down, negative = up +sub cmd_scroll { + if (!$active_channel) { # not a channel active + return; + } + my @nicks=Irssi::active_win->{active}->nicks; + my $nick_count = scalar(@nicks)+0; + my $channel = Irssi::active_win->{active}; + if (!$channel || $channel->{type} ne 'CHANNEL' || !$channel->{names_got} || $nick_count <= $height) { + return; + } + $scroll_pos += @_[0]; + + if ($scroll_pos > $nick_count - $height) { + $scroll_pos = $nick_count - $height; + } + if ($scroll_pos <= 0) { + $scroll_pos = 0; + } + need_redraw(); +} + +sub is_active_channel { + my ($server,$channel) = @_; # (channel as string) + return ($server && $server->{'tag'} eq $active_channel->{'server'}->{'tag'} && $server->channel_find($channel) && $active_channel && $server->channel_find($channel)->{'name'} eq $active_channel->{'name'}); +} + +sub sig_channel_wholist { # this is actualy a little late, when the names are received would be better + my ($channel) = @_; + if (Irssi::active_win->{'active'} && Irssi::active_win->{'active'}->{'name'} eq $channel->{'name'}) { # the channel joined is active + make_nicklist + } +} + +sub sig_join { + my ($server,$channel,$nick,$address) = @_; + if (!is_active_channel($server,$channel)) { + return; + } + my $newnick = {'nick' => $nick}; + recalc_nick($newnick); + insert_nick($newnick); +} + +sub sig_kick { + my ($server, $channel, $nick, $kicker, $address, $reason) = @_; + if (!is_active_channel($server,$channel)) { + return; + } + my $nr = find_nick($nick); + if ($nr == -1) { + Irssi::print("nicklist warning: $nick was kicked from $channel, but not found in nicklist"); + } else { + remove_nick($nr); + } +} + +sub sig_part { + my ($server,$channel,$nick,$address, $reason) = @_; + if (!is_active_channel($server,$channel)) { + return; + } + my $nr = find_nick($nick); + if ($nr == -1) { + Irssi::print("nicklist warning: $nick has parted $channel, but was not found in nicklist"); + } else { + remove_nick($nr); + } + +} + +sub sig_quit { + my ($server,$nick,$address, $reason) = @_; + if ($server->{'tag'} ne $active_channel->{'server'}->{'tag'}) { + return; + } + my $nr = find_nick($nick); + if ($nr != -1) { + remove_nick($nr); + } +} + +sub sig_nick { + my ($server, $newnick, $oldnick, $address) = @_; + if ($server->{'tag'} ne $active_channel->{'server'}->{'tag'}) { + return; + } + my $nr = find_nick($oldnick); + if ($nr != -1) { # if nick was found (nickchange is in current channel) + my $nick = $nicklist[$nr]; + remove_nick($nr); + $nick->{'nick'} = $newnick; + calc_text($nick); + insert_nick($nick); + } +} + +sub sig_mode { + my ($channel, $nick, $setby, $mode, $type) = @_; # (nick and channel as rec) + if ($channel->{'server'}->{'tag'} ne $active_channel->{'server'}->{'tag'} || $channel->{'name'} ne $active_channel->{'name'}) { + return; + } + my $nr = find_nick($nick->{'nick'}); + if ($nr == -1) { + Irssi::print("nicklist warning: $nick->{'nick'} had mode set on $channel->{'name'}, but was not found in nicklist"); + } else { + my $nicklist_item = $nicklist[$nr]; + remove_nick($nr); + recalc_nick($nicklist_item, $nick); + insert_nick($nicklist_item); + } +} + +##### command binds ##### +Irssi::command_bind 'nicklist' => sub { + my ( $data, $server, $item ) = @_; + $data =~ s/\s+$//g; + Irssi::command_runsub ('nicklist', $data, $server, $item ) ; +}; +Irssi::signal_add_first 'default command nicklist' => sub { + # gets triggered if called with unknown subcommand + cmd_help(); +}; +Irssi::command_bind('nicklist update',\&update); +Irssi::command_bind('nicklist help',\&cmd_help); +Irssi::command_bind('nicklist scroll',\&cmd_scroll); +Irssi::command_bind('nicklist fifo',\&cmd_fifo_start); +Irssi::command_bind('nicklist screen',\&cmd_screen_start); +Irssi::command_bind('nicklist screensize',\&screen_size); +Irssi::command_bind('nicklist off',\&cmd_off); + +##### signals ##### +Irssi::signal_add_last('window item changed', \&make_nicklist); +Irssi::signal_add_last('window changed', \&make_nicklist); +Irssi::signal_add_last('channel wholist', \&sig_channel_wholist); +Irssi::signal_add_first('message join', \&sig_join); # first, to be before ignores +Irssi::signal_add_first('message part', \&sig_part); +Irssi::signal_add_first('message kick', \&sig_kick); +Irssi::signal_add_first('message quit', \&sig_quit); +Irssi::signal_add_first('message nick', \&sig_nick); +Irssi::signal_add_first('message own_nick', \&sig_nick); +Irssi::signal_add_first('nick mode changed', \&sig_mode); + +Irssi::signal_add('setup changed', \&read_settings); + +##### settings ##### +Irssi::settings_add_str('nicklist', 'nicklist_screen_prefix', '\e[m '); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_mode_op', '\e[32m@\e[39m'); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_mode_halfop', '\e[34m%\e[39m'); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_mode_voice', '\e[33m+\e[39m'); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_mode_normal', ' '); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_mode_other', '&=\e[31m&\e[39m ~=\e[35m~\e[39m'); +Irssi::settings_add_str('nicklist', 'nicklist_prefix_friends', 'o=\e[32m v=\e[33m noflag=\e[1m'); + +Irssi::settings_add_int('nicklist', 'nicklist_width',11); +Irssi::settings_add_int('nicklist', 'nicklist_height',24); +Irssi::settings_add_str('nicklist', 'nicklist_fifo_path', Irssi::get_irssi_dir . '/nicklistfifo'); +Irssi::settings_add_str('nicklist', 'nicklist_screen_split_windows', ''); +Irssi::settings_add_str('nicklist', 'nicklist_automode', ''); + +read_settings(); +if (uc(Irssi::settings_get_str('nicklist_automode')) eq 'SCREEN') { + cmd_screen_start(); +} elsif (uc(Irssi::settings_get_str('nicklist_automode')) eq 'FIFO') { + cmd_fifo_start(); +} diff --git a/.irssi/scripts/nickserv.pl b/.irssi/scripts/nickserv.pl new file mode 100644 index 0000000..54250b9 --- /dev/null +++ b/.irssi/scripts/nickserv.pl @@ -0,0 +1,563 @@ +#!/usr/bin/perl -w + +## Bugreports and Licence disclaimer. +# +# For bugreports and other improvements contact Geert Hauwaerts <geert@irssi.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this script; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +## + +use strict; +use Irssi; +use vars qw($VERSION %IRSSI); + +$VERSION = "1.8"; + +%IRSSI = ( + authors => 'Geert Hauwaerts', + contact => 'geert@irssi.org', + name => 'nickserv.pl', + description => 'This script will authorize you into NickServ.', + license => 'GNU General Public License', + url => 'http://irssi.hauwaerts.be/nickserv.pl', + changed => 'Fri Jun 6 12:03:04 CEST 2008', +); + +my @nickservnet = (); +my $nickservnet_file = "nickserv.networks"; + +my @nickservauth = (); +my $nickservauth_file = "nickserv.auth"; + +my $irssidir = Irssi::get_irssi_dir(); + +my $help = <<EOF; + +Usage: (all on one line) +/NICKSERV [addnet <ircnet> <services\@host>] + [addnick <ircnet> <nickname> <password>] + [delnet <ircnet>] + [delnick <ircnet> <nick>] + [help listnet listnick] + +addnet: Add a new network into the NickServ list. +addnick: Add a new nickname into the NickServ list. +delnet: Delete a network from the NickServ list. +delnick: Delete a nickname from the NickServ list. +listnet: Display the contents of the NickServ network list. +listnick: Display the contents of the NickServ nickname list. +help: Display this useful little helptext. + +Examples: (all on one line) +/NICKSERV addnet Freenode NickServ\@services. +/NICKSERV addnick Freenode Geert mypass + +/NICKSERV delnet Freenode +/NICKSERV delnick Freenode Geert + +Note: This script doesn't allow wildcards into the NickServ hostname. You must use the full services\@host. + Both /NICKSERV and /NS are valid commands. +EOF + +Irssi::theme_register([ + 'nickserv_usage_network', '%R>>%n %_NickServ:%_ Insufficient parameters: Usage "%_/NICKSERV addnet ircnet services@host%_".', + 'nickserv_usage_nickname', '%R>>%n %_NickServ:%_ Insufficient parameters: Usage "%_/NICKSERV addnick ircnet nickname password%_".', + 'nickserv_delusage', '%R>>%n %_NickServ:%_ Insufficient parameters: Usage "%_/NICKSERV delnet ircnet%_".', + 'nickserv_delnickusage', '%R>>%n %_NickServ:%_ Insufficient parameters: Usage "%_/NICKSERV delnick ircnet nickname%_".', + 'nickserv_delled', '%R>>%n %_NickServ:%_ Deleted %_$0%_ and his nicknames from the NickServ ircnet list.', + 'nickserv_delled_nick', '%R>>%n %_NickServ:%_ Deleted %_$1%_ from the NickServ list on $0.', + 'nickserv_nfound', '%R>>%n %_NickServ:%_ The NickServ ircnet %_$0%_ could not be found.', + 'nickserv_nfound_nick', '%R>>%n %_NickServ:%_ The NickServ nickname %_$0%_ could not be found on $1.', + 'nickserv_usage', '%R>>%n %_NickServ:%_ Insufficient parameters: Use "%_/NICKSERV help%_" for further instructions.', + 'nickserv_no_net', '%R>>%n %_NickServ:%_ Unknown Irssi ircnet %_$0%_.', + 'nickserv_wrong_host', '%R>>%n %_NickServ:%_ Malformed services hostname %_$0%_.', + 'already_loaded_network', '%R>>%n %_NickServ:%_ The ircnet %_$0%_ already exists in the NickServ ircnet list, please remove it first.', + 'nickserv_loaded_nick', '%R>>%n %_NickServ:%_ The nickname %_$0%_ already exists in the NickServ authlist on %_$1%_, please remove it first.', + 'nickserv_not_loaded_net', '%R>>%n %_NickServ:%_ The ircnet %_$0%_ doesn\'t exists in the NickServ ircnet list, please add it first.', + 'saved_nickname', '%R>>%n %_NickServ:%_ Added nickname %_$1%_ on %_$0%_.', + 'network_print', '$[!-2]0 $[20]1 $2', + 'password_request', '%R>>%n %_NickServ:%_ Auth Request from NickServ on %_$0%_.', + 'password_accepted', '%R>>%n %_NickServ:%_ Password accepted on %_$0%_.', + 'password_wrong', '%R>>%n %_NickServ:%_ Password denied on %_$0%_. Please change the password.', + 'network_info', '%_ # Ircnet Services hostname%_', + 'network_empty', '%R>>%n %_NickServ:%_ Your NickServ ircnet list is empty.', + 'nickname_print', '$[!-2]0 $[20]1 $[18]2 $3', + 'nickname_info', '%_ # Ircnet Nickname Password%_', + 'nickname_empty', '%R>>%n %_NickServ:%_ Your NickServ authlist is empty.', + 'nickserv_help', '$0', + 'saved_network', '%R>>%n %_NickServ:%_ Added services mask "%_$1%_" on %_$0%_.', + 'nickserv_loaded', '%R>>%n %_Scriptinfo:%_ Loaded $0 version $1 by $2.' +]); + +sub load_nickservnet { + + my ($file) = @_; + + @nickservnet = (); + + if (-e $file) { + local *F; + open(F, "<$file"); + local $/ = "\n"; + + while (<F>) { + chop; + my $new_nsnet = new_nickserv_network(split("\t")); + + if (($new_nsnet->{name} ne "") && ($new_nsnet->{host} ne "")) { + push(@nickservnet, $new_nsnet); + } + } + + close(F); + } +} + +sub save_nickservnet { + + my ($file) = @_; + + return unless scalar @nickservnet; # there's nothing to save + + if (-e $file) { + local *F; + open(F, ">$file"); + + for (my $n = 0; $n < @nickservnet; ++$n) { + print(F join("\t", $nickservnet[$n]->{name}, $nickservnet[$n]->{host}) . "\n"); + } + + close(F); + } else { + create_network_file($file); + save_nickservnet($file); + } +} + +sub create_network_file { + + my ($file) = @_; + + open(F, ">$file") or die "Can't create $file. Reason: $!"; +} + +sub new_nickserv_network { + + my $nsnet = {}; + + $nsnet->{name} = shift; + $nsnet->{host} = shift; + + return $nsnet; +} + +sub load_nickservnick { + + my ($file) = @_; + + @nickservauth = (); + + if (-e $file) { + local *F; + open(F, "<$file"); + local $/ = "\n"; + + while (<F>) { + chop; + my $new_nsnick = new_nickserv_nick(split("\t")); + + if (($new_nsnick->{ircnet} ne "") && ($new_nsnick->{nick} ne "") && ($new_nsnick->{pass} ne "")) { + push(@nickservauth, $new_nsnick); + } + } + + close(F); + } +} + +sub save_nickservnick { + + my ($file) = @_; + + return unless scalar @nickservauth; # there's nothing to save + + if (-e $file) { + local *F; + open(F, ">$file"); + + for (my $n = 0; $n < @nickservauth; ++$n) { + print(F join("\t", $nickservauth[$n]->{ircnet}, $nickservauth[$n]->{nick}, $nickservauth[$n]->{pass}) . "\n"); + } + + close(F); + } else { + create_nick_file($file); + save_nickservnick($file); + } +} + +sub create_nick_file { + + my ($file) = @_; + + my $umask = umask 0077; # save old umask + open(F, ">$file") or die "Can't create $file. Reason: $!"; + umask $umask; +} + +sub new_nickserv_nick { + + my $nsnick = {}; + + $nsnick->{ircnet} = shift; + $nsnick->{nick} = shift; + $nsnick->{pass} = shift; + + return $nsnick; +} + +sub add_nickname { + + my ($network, $nickname, $password) = split(" ", @_[0], 3); + my ($correct_network, $correct_nickname, $correct_password); + + if ($network eq "" || $nickname eq "" || $password eq "") { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_usage_nickname'); + return; + } + + if ($network) { + if (!already_loaded_net($network)) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_not_loaded_net', $network); + return; + } else { + $correct_network = 1; + } + } + + if ($nickname) { + if (already_loaded_nick($nickname, $network)) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_loaded_nick', $nickname, $network); + return; + } else { + $correct_nickname = 1; + } + } + + if ($correct_network && $correct_nickname) { + push(@nickservauth, new_nickserv_nick($network, $nickname, $password)); + save_nickservnick("$irssidir/$nickservauth_file"); + + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'saved_nickname', $network, $nickname); + } +} + +sub add_network { + + my ($network, $hostname) = split(" ", @_[0], 2); + my ($correct_net, $correct_host); + + if ($network eq "" || $hostname eq "") { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_usage_network'); + return; + } + + if ($network) { + my ($ircnet) = Irssi::chatnet_find($network); + + if (!$ircnet) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_no_net', $network); + return; + } elsif (already_loaded_net($network)) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'already_loaded_network', $network); + return; + } else { + $correct_net = 1; + } + } + + if ($hostname) { + if ($hostname !~ /^[.+a-zA-Z0-9_-]{1,9}@[.+a-zA-Z0-9_-]{1,}$/) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_wrong_host', $hostname); + return; + } else { + $correct_host = 1; + } + } + + if ($correct_net && $correct_host) { + push(@nickservnet, new_nickserv_network($network, $hostname)); + save_nickservnet("$irssidir/$nickservnet_file"); + + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'saved_network', $network, $hostname); + } +} + +sub already_loaded_net { + + my ($ircnet) = @_; + my $loaded = check_loaded_net($ircnet); + + if ($loaded > -1) { + return 1; + } + + return 0; +} + +sub check_loaded_net { + + my ($ircnet) = @_; + + $ircnet = lc($ircnet); + + for (my $loaded = 0; $loaded < @nickservnet; ++$loaded) { + return $loaded if (lc($nickservnet[$loaded]->{name}) eq $ircnet); + } + + return -1; +} + +sub already_loaded_nick { + + my ($nickname, $network) = @_; + my $loaded = check_loaded_nick($nickname, $network); + + if ($loaded > -1) { + return 1; + } + + return 0 +} + +sub check_loaded_nick { + + my ($nickname, $network) = @_; + + $nickname = lc($nickname); + $network = lc($network); + + for (my $loaded = 0; $loaded < @nickservauth; ++$loaded) { + return $loaded if (lc($nickservauth[$loaded]->{nick}) eq $nickname && lc ($nickservauth[$loaded]->{ircnet}) eq $network); + } + + return -1; +} + +sub list_net { + + if (@nickservnet == 0) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'network_empty'); + } else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'network_info'); + + for (my $n = 0; $n < @nickservnet ; ++$n) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'network_print', $n, $nickservnet[$n]->{name}, $nickservnet[$n]->{host}); + } + } +} + +sub list_nick { + + if (@nickservauth == 0) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickname_empty'); + } else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickname_info'); + + for (my $n = 0; $n < @nickservauth ; ++$n) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickname_print', $n, $nickservauth[$n]->{ircnet}, $nickservauth[$n]->{nick}, "*" x length($nickservauth[$n]->{pass})); + } + } +} + +sub nickserv_notice { + + my ($server, $data, $nick, $address) = @_; + my ($target, $text) = $data =~ /^(\S*)\s:(.*)/; + + if (is_nickserv($server->{tag}, $address)) { + if ($text =~ /^If this is your nickname, type \/msg NickServ/ || $text =~ /^This nickname is registered and protected. If it is your/ || $text =~ /This nickname is registered\. Please choose a different nickname,/ || $text =~ /^This nickname is registered. Please choose a different nickname/) { + my $password = get_password($server->{tag}, $server->{nick}); + + if ($password == -1) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_nfound_nick', $server->{nick}, $server->{tag}); + Irssi::signal_stop(); + return; + } + + Irssi::signal_stop(); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + $server->command("^MSG NickServ IDENTIFY $password"); + } elsif ($text =~ /If this is your nickname, type \/NickServ/) { + my $password = get_password($server->{tag}, $server->{nick}); + + if ($password == -1) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_nfound_nick', $server->{nick}, $server->{tag}); + Irssi::signal_stop(); + return; + } + + Irssi::signal_stop(); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + $server->command("^QUOTE NickServ :IDENTIFY $password"); + } elsif ($text =~ /If this is your nickname, type \/msg NS/) { + my $password = get_password($server->{tag}, $server->{nick}); + + if ($password == -1) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_nfound_nick', $server->{nick}, $server->{tag}); + Irssi::signal_stop(); + return; + } + + Irssi::signal_stop(); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_request', $server->{tag}); + $server->command("^MSG NS IDENTIFY $password"); + } elsif ($text =~ /If you do not (.*) within one minute, you will be disconnected/) { + Irssi::signal_stop(); + } elsif ($text =~ /^This nickname is owned by someone else/) { + Irssi::signal_stop(); + } elsif ($text =~ /^nick, type (.*) Otherwise,/) { + Irssi::signal_stop(); + } elsif ($text =~ /^please choose a different nick./) { + Irssi::signal_stop(); + } elsif ($text =~ /^You have already identified/ || $text =~ /^This nick is already identified./) { + Irssi::signal_stop(); + } elsif ($text =~ /^Password accepted - you are now recognized/) { + Irssi::signal_stop(); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_accepted', $server->{tag}); + } elsif ($text =~ /^Password Incorrect/ || $text =~ /^Password incorrect./) { + Irssi::signal_stop(); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'password_wrong', $server->{tag}); + } + } +} + +sub is_nickserv { + + my ($net, $host) = @_; + + for (my $loaded = 0; $loaded < @nickservnet; ++$loaded) { + return 1 if (lc($nickservnet[$loaded]->{name}) eq lc($net) && lc($nickservnet[$loaded]->{host}) eq lc($host)); + } + return 0; +} + +sub get_password { + + my ($ircnet, $nick) = @_; + + for (my $loaded = 0; $loaded < @nickservauth; ++$loaded) { + return $nickservauth[$loaded]->{pass} if (lc($nickservauth[$loaded]->{ircnet}) eq lc($ircnet) && lc($nickservauth[$loaded]->{nick}) eq lc($nick)); + } + + return -1; +} + +sub del_network { + + my ($ircnet) = split(" ", @_[0], 1); + my ($ircnetindex); + + if ($ircnet eq "") { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_delusage'); + return; + } + + for (my $index = 0; $index < @nickservnet; ++$index) { + if (lc($nickservnet[$index]->{name}) eq lc($ircnet)) { + $ircnetindex = 1; + } + } + + if ($ircnetindex) { + @nickservnet = grep {lc($_->{name}) ne lc($ircnet)} @nickservnet; + @nickservauth = grep {lc($_->{ircnet}) ne lc($ircnet)} @nickservauth; + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_delled', $ircnet); + save_nickservnet("$irssidir/$nickservnet_file"); + save_nickservnick("$irssidir/$nickservauth_file"); + } else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_nfound', $ircnet); + } +} + +sub del_nickname { + + my ($ircnet, $nickname) = split(" ", @_[0], 2); + my ($nickindex); + + if ($ircnet eq "" || $nickname eq "") { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_delnickusage'); + return; + } + + for (my $index = 0; $index < @nickservauth; ++$index) { + if (lc($nickservauth[$index]->{ircnet}) eq lc($ircnet) && lc($nickservauth[$index]->{nick}) eq lc($nickname)) { + $nickindex = splice(@nickservauth, $index, 1); + } + } + + if ($nickindex) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_delled_nick', $ircnet, $nickname); + save_nickservnick("$irssidir/$nickservauth_file"); + } else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_nfound_nick', $ircnet, $nickname); + } +} + +sub nickserv_runsub { + + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; + + if ($data) { + Irssi::command_runsub('nickserv', $data, $server, $item); + } else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_usage'); + } +} + +load_nickservnet("$irssidir/$nickservnet_file"); +load_nickservnick("$irssidir/$nickservauth_file"); + +Irssi::command_bind('nickserv', 'nickserv_runsub'); +Irssi::command_bind('ns', 'nickserv_runsub'); + +Irssi::command_bind('nickserv addnet', 'add_network'); +Irssi::command_bind('ns addnet', 'add_network'); + +Irssi::command_bind('nickserv addnick', 'add_nickname'); +Irssi::command_bind('ns addnick', 'add_nickname'); + +Irssi::command_bind('nickserv listnet', 'list_net'); +Irssi::command_bind('ns listnet', 'list_net'); + +Irssi::command_bind('nickserv listnick', 'list_nick'); +Irssi::command_bind('ns listnick', 'list_nick'); + +Irssi::command_bind('nickserv delnet', 'del_network'); +Irssi::command_bind('ns delnet', 'del_network'); + +Irssi::command_bind('nickserv delnick', 'del_nickname'); +Irssi::command_bind('ns delnick', 'del_nickname'); + +Irssi::command_bind('nickserv help' => sub { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_help', $help) }); +Irssi::command_bind('ns help' => sub { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_help', $help) }); + +Irssi::signal_add('event notice', 'nickserv_notice'); +Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'nickserv_loaded', $IRSSI{name}, $VERSION, $IRSSI{authors}); diff --git a/.irssi/scripts/tmux_away.pl b/.irssi/scripts/tmux_away.pl new file mode 100644 index 0000000..11e6fe8 --- /dev/null +++ b/.irssi/scripts/tmux_away.pl @@ -0,0 +1,179 @@ +use Irssi; +use strict; +use FileHandle; + +use vars qw($VERSION %IRSSI); + +$VERSION = "1.1"; +%IRSSI = ( + authors => 'cdidier', + name => 'tmux_away', + description => 'set (un)away, if tmux session is attached/detached', + license => 'GPL v2', + url => 'http://cybione.org', +); + +# tmux_away irssi module +# +# Written by Colin Didier <cdidier@cybione.org> and heavily based on +# screen_away irssi module version 0.9.7.1 written by Andreas 'ads' Scherbaum +# <ads@ufp.de>. +# +# usage: +# +# put this script into your autorun directory and/or load it with +# /SCRIPT LOAD <name> +# +# there are 5 settings available: +# +# /set tmux_away_active ON/OFF/TOGGLE +# /set tmux_away_repeat <integer> +# /set tmux_away_message <string> +# /set tmux_away_window <string> +# /set tmux_away_nick <string> +# +# active means, that you will be only set away/unaway, if this +# flag is set, default is ON +# repeat is the number of seconds, after the script will check the +# tmux session status again, default is 5 seconds +# message is the away message sent to the server, default: not here ... +# window is a window number or name, if set, the script will switch +# to this window, if it sets you away, default is '1' +# nick is the new nick, if the script goes away +# will only be used it not empty + + +# variables +my $timer_name = undef; +my $away_status = 0; +my %old_nicks = (); +my %away = (); + +# Register formats +Irssi::theme_register( +[ + 'tmux_away_crap', + '{line_start}{hilight ' . $IRSSI{'name'} . ':} $0' +]); + +# try to find out, if we are running in a tmux session +# (see if $ENV{TMUX} is set) +if (!defined($ENV{TMUX})) { + # just return, we will never be called again + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', + "no tmux session!"); + return; +} + +my @args_env = split(',', $ENV{TMUX}); +my $tmux_socket = @args_env[0]; +my $tmux_session = @args_env[2]; + +# register config variables +Irssi::settings_add_bool('misc', $IRSSI{'name'} . '_active', 1); +Irssi::settings_add_int('misc', $IRSSI{'name'} . '_repeat', 5); +Irssi::settings_add_str('misc', $IRSSI{'name'} . '_message', "not here..."); +Irssi::settings_add_str('misc', $IRSSI{'name'} . '_window', "1"); +Irssi::settings_add_str('misc', $IRSSI{'name'} . '_nick', ""); + + +# check, set or reset the away status +sub tmux_away { + my ($status, @res); + + # only run, if activated + if (Irssi::settings_get_bool($IRSSI{'name'} . '_active') != 1) { + $away_status = 0; + } else { + if ($away_status == 0) { + # display init message at first time + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', + "activating $IRSSI{'name'} (interval: " . Irssi::settings_get_int($IRSSI{'name'} . '_repeat') . " seconds)"); + $away_status = 2; + } + + # get actual tmux session status + @res = `tmux -S '$tmux_socket' lsc 2>&1`; + if (@res[0] =~ /^server not found/) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', + "error getting tmux session status."); + return; + } + $status = 1; # away, assumes the session is detached + foreach (@res) { + my @args_st = split(' '); + if (@args_st[1] == $tmux_session) { + $status = 2; # unaway + } + } + + # unaway -> away + if ($status == 1 and $away_status != 1) { + if (length(Irssi::settings_get_str($IRSSI{'name'} . '_window')) > 0) { + # if length of window is greater then 0, make this window active + Irssi::command('window goto ' . Irssi::settings_get_str($IRSSI{'name'} . '_window')); + } + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', "Set away"); + my $message = Irssi::settings_get_str($IRSSI{'name'} . '_message'); + if (length($message) == 0) { + # we have to set a message or we wouldnt go away + $message = "not here ..."; + } + foreach (Irssi::servers()) { + if (!$_->{usermode_away}) { + # user isnt yet away + $away{$_->{'tag'}} = 0; + $_->command("AWAY " . ($_->{chat_type} ne 'SILC' ? "-one " : "") . "$message"); + if ($_->{chat_type} ne 'XMPP' and length(Irssi::settings_get_str($IRSSI{'name'} . '_nick')) > 0) { + # only change, if actual nick isnt already the away nick + if (Irssi::settings_get_str($IRSSI{'name'} . '_nick') ne $_->{nick}) { + # keep old nick + $old_nicks{$_->{'tag'}} = $_->{nick}; + # set new nick + $_->command("NICK " . Irssi::settings_get_str($IRSSI{'name'} . '_nick')); + } + } + } else { + # user is already away, remember this + $away{$_->{'tag'}} = 1; + } + } + $away_status = $status; + + # away -> unaway + } elsif ($status == 2 and $away_status != 2) { + # unset away + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', "Reset away"); + foreach (Irssi::servers()) { + if ($away{$_->{'tag'}} == 1) { + # user was already away, dont reset away + $away{$_->{'tag'}} = 0; + next; + } + $_->command("AWAY" . (($_->{chat_type} ne 'SILC') ? " -one" : "")) if ($_->{usermode_away}); + if ($_->{chat_type} ne 'XMPP' and defined($old_nicks{$_->{'tag'}}) and length($old_nicks{$_->{'tag'}}) > 0) { + # set old nick + $_->command("NICK " . $old_nicks{$_->{'tag'}}); + $old_nicks{$_->{'tag'}} = ""; + } + } + $away_status = $status; + } + } + # but everytimes install a new timer + register_tmux_away_timer(); + return 0; +} + +# remove old timer and install a new one +sub register_tmux_away_timer { + if (defined($timer_name)) { + Irssi::timeout_remove($timer_name); + } + # add new timer with new timeout (maybe the timeout has been changed) + $timer_name = Irssi::timeout_add(Irssi::settings_get_int($IRSSI{'name'} . '_repeat') * 1000, 'tmux_away', ''); +} + +# init process +tmux_away(); + |