html/xcmd.pl


   1 #!/usr/bin/perl
   2 # X is the Undernet bot
   3 # This script is meant to make X commands easier and faster to use.
   4 # 
   5 # Copyright 2003 Clément Hermann <clement.hermann@free.fr>
   6 # 
   7 # This program is free software; you can redistribute it and/or modify
   8 # it under the terms of the GNU General Public License as published by
   9 # the Free Software Foundation; either version 2 of the License, or
  10 # (at your option) any later version.
  11 #
  12 # This program is distributed in the hope that it will be useful,
  13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 # GNU General Public License for more details.
  16 #
  17 # You should have received a copy of the GNU General Public License
  18 # along with this program; if not, write to the Free Software
  19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20 
  21 use strict;
  22 use vars qw($VERSION %IRSSI);
  23 
  24 use Irssi qw(command_bind signal_add);
  25 
  26 $VERSION = '0.2';
  27 %IRSSI = (
  28 authors     => 	'Clément "nodens" Hermann',
  29 contact     => 	'clement.hermann@free.fr',
  30 name        => 	'Xcmd',
  31 description => 	'makes Undernet\'s X commands easier and faster to use',
  32 license     => 	'GPLv2',
  33 changed     => 	$VERSION,
  34 commands    => 	'xcmd',
  35 );
  36 
  37 sub help {
  38 	Irssi::print("xcmd launch an X command (/MSG X <command>), using the current windows as channel name.");
  39 	Irssi::print("Any command that have a <channel> parameter can be used.");
  40 	Irssi::print("/Xcmd showcommands show X commands for the current channel.");
  41 }
  42 	
  43 sub xcommand {
  44 	my ($data, $server, $witem) = @_;
  45 	my $channel;
  46 	
  47 	if (! $data) {
  48 		&help;
  49 	} else {
  50 		my @params = split (/ /,$data);
  51 		my $cmd = shift @params;
  52 		my $args = join (" ",@params);
  53 	
  54 		if ($witem && ($witem->{type} eq "CHANNEL")) {
  55 			$channel = $witem->{name};
  56 			$witem->command("MSG X $cmd $channel $args");
  57 		} else {
  58 			Irssi::print("No active channel in window");
  59 		}
  60 	}
  61 }
  62 
  63 Irssi::command_bind('xcmd', 'xcommand');
  64 
  65 Irssi::print("Xcmd $VERSION by nodens. Try /xcmd for help");