html/autochannel.pl


   1 #! /usr/bin/perl
   2 #
   3 #    $Id: autochannel.pl,v 1.2 2007/09/20 06:58:11 peder Exp $
   4 #
   5 # Copyright (C) 2007 by Peder Stray <peder@ninja.no>
   6 #
   7 
   8 use strict;
   9 use Irssi;
  10 use Irssi::Irc;
  11 
  12 use Data::Dumper;
  13 $Data::Dumper::Indent = 1;
  14 
  15 # ======[ Script Header ]===============================================
  16 
  17 use vars qw{$VERSION %IRSSI};
  18 ($VERSION) = ' $Revision: 1.2 $ ' =~ / (\d+\.\d+) /;
  19 %IRSSI = (
  20           name        => 'autochannel',
  21           authors     => 'Peder Stray',
  22           contact     => 'peder@ninja.no',
  23           url         => 'http://ninja.no/irssi/autochannel.pl',
  24           license     => 'GPL',
  25           description => 'Auto add channels to channel list on join',
  26          );
  27 
  28 # ======[ Signal hooks ]================================================
  29 
  30 # "message join", SERVER_REC, char *channel, char *nick, char *address
  31 sub sig_message_join {
  32     my($server,$channel,$nick,$addr) = @_;
  33 
  34     return unless $nick eq $server->{nick};
  35     return unless $server->{chatnet};
  36     return unless Irssi::settings_get_bool('channel_add_on_join');
  37     
  38     Irssi::command(sprintf "channel add %s %s %s",
  39 		   Irssi::settings_get_bool('channel_add_with_auto')
  40 		   ? '-auto' : '',
  41 		   $channel,
  42 		   $server->{chatnet},
  43 		  );
  44 }
  45 
  46 # "message part", SERVER_REC, char *channel, char *nick, char *address, char *reason
  47 sub sig_message_part {
  48     my($server,$channel,$nick,$addr,$reason) = @_;
  49 
  50     return unless $nick eq $server->{nick};
  51     return unless $server->{chatnet};
  52     return unless
  53       Irssi::settings_get_bool('channel_remove_on_part') ||
  54 	  Irssi::settings_get_bool('channel_remove_auto_on_part');
  55 
  56     if (Irssi::settings_get_bool('channel_remove_on_part')) {
  57 	Irssi::command(sprintf "channel remove %s %s",
  58 		       $channel,
  59 		       $server->{chatnet},
  60 		      );
  61     }
  62     elsif (Irssi::settings_get_bool('channel_remove_auto_on_part')) {
  63 	Irssi::command(sprintf "channel add %s %s %s",
  64 		       '-noauto',
  65 		       $channel,
  66 		       $server->{chatnet},
  67 		      );
  68     }
  69 }
  70 
  71 # ======[ Setup ]=======================================================
  72 
  73 # --------[ Settings ]--------------------------------------------------
  74 
  75 Irssi::settings_add_bool('autochannel', 'channel_add_on_join', 1);
  76 Irssi::settings_add_bool('autochannel', 'channel_add_with_auto', 1);
  77 Irssi::settings_add_bool('autochannel', 'channel_remove_auto_on_part', 1);
  78 Irssi::settings_add_bool('autochannel', 'channel_remove_on_part', 0);
  79 
  80 # --------[ Signals ]---------------------------------------------------
  81 
  82 Irssi::signal_add_last('message join', 'sig_message_join');
  83 Irssi::signal_add_last('message part', 'sig_message_part');
  84 
  85 # ======[ END ]=========================================================
  86 
  87 # Local Variables:
  88 # header-initial-hide: t
  89 # mode: header-minor
  90 # end: