html/bitlbee_join_notice-pre-3.0.pl


   1 #CHANGELOG:
   2 #
   3 #28-11-2004:
   4 #it gives a join message in a query if a user joins &bitlbee and you hve a query open with that person.
   5 #
   6 #/statusbar window add join_notice
   7 #use Data::Dumper;
   8 
   9 use strict;
  10 #use Irssi::TextUI;
  11 #use Irssi::Themes;
  12 
  13 use vars qw($VERSION %IRSSI);
  14 
  15 $VERSION = '1.2';
  16 %IRSSI = (
  17     authors     => 'Tijmen "timing" Ruizendaal',
  18     contact     => 'tijmen.ruizendaal@gmail.com',
  19     name        => 'Bitlbee_join_notice-pre-3.0',
  20     description => '	1. Adds an item to the status bar wich shows [joined: <nicks>] when someone is joining &bitlbee.
  21     			    			2. Shows join messages in the query.
  22     			    			(For bitlbee 1.2.x)',
  23     license => 'GPLv2',
  24     url     => 'http://the-timing.nl/stuff/irssi-bitlbee',
  25     changed => '2006-10-27',
  26 );
  27 my %online;
  28 my %tag;
  29 my $bitlbee_channel= "&bitlbee";
  30 my $bitlbee_server_tag="localhost";
  31 
  32 get_channel();
  33 
  34 Irssi::signal_add_last 'channel sync' => sub {
  35         my( $channel ) = @_;
  36         if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){
  37                 $bitlbee_server_tag = $channel->{server}->{tag};
  38                 $bitlbee_channel = $channel->{name};
  39         }
  40 };
  41 
  42 sub get_channel {
  43         my @channels = Irssi::channels();
  44         foreach my $channel(@channels) {
  45                 if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") {
  46                         $bitlbee_channel = $channel->{name};
  47                         $bitlbee_server_tag = $channel->{server}->{tag};
  48 			return 1;
  49                 }
  50         }
  51 	return 0;
  52 }
  53 
  54 sub event_join {
  55   my ($server, $channel, $nick, $address) = @_;
  56   if ($channel eq ":$bitlbee_channel" && $server->{tag} eq $bitlbee_server_tag){
  57     $online{$nick} = 1;
  58     Irssi::timeout_remove($tag{$nick});
  59     $tag{$nick} = Irssi::timeout_add(7000, 'empty', $nick);
  60     Irssi::statusbar_items_redraw('join_notice');
  61     my $window = Irssi::window_find_item($nick);
  62     if($window){
  63       $window->printformat(MSGLEVEL_JOINS, 'join', $nick, $address, $bitlbee_channel); 
  64     }
  65   }
  66 }
  67 sub join_notice {
  68   my ($item, $get_size_only) = @_; 
  69   my $line;
  70   foreach my $key (keys(%online) )
  71   {
  72     $line = $line." ".$key;
  73   }
  74   if ($line ne "" ){
  75     $item->default_handler($get_size_only, "{sb joined:$line}", undef, 1);
  76     $line = "";
  77   }else{
  78     $item->default_handler($get_size_only, "", undef, 1);
  79   } 
  80 }
  81 sub empty{
  82   my $nick = shift;
  83   delete($online{$nick});
  84   Irssi::timeout_remove($tag{$nick});
  85   Irssi::statusbar_items_redraw('join_notice');
  86 }
  87 
  88 Irssi::signal_add("event join", "event_join");
  89 Irssi::statusbar_item_register('join_notice', undef, 'join_notice');
  90 Irssi::statusbars_recreate_items();
  91 Irssi::theme_register([
  92   'join', '{channick_hilight $0} {chanhost $1} has joined {channel $2}',
  93 ]);
  94 
  95