All pastes #778319 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-17 14:06 UTC
rendered paste body
#####################################################################
# 
# There is no need to modify this script.
# 
# See the section after __END__ for more information.
#
#####################################################################

package Xchat::b0at::MultipleCommands;
use strict;
use warnings;

my $NAME    = 'Multiple Commands';
my $VERSION = '005';

my %CMDS = (
	'MULTI' => {
		'usage' => "Usage: MULTI <sep> <command1> [sep <command2> [...]], spaces around separator are required"
,		'callback' => sub {
			my ($w, $e, $help) = @_;
			my $sep = $w->[1]; # first word is the separator
			my $cmd = $e->[2]; # rest of the arguments taken as one string
			if( not( $sep and $cmd ) ) { Xchat::print($help) }
			else { Xchat::command([ split/\s\Q$sep\E\s+/,$cmd ]) }
			return Xchat::EAT_XCHAT;
		}
	}
,	'COMBO' => {
		'usage' => "Usage: COMBO <sep> <common> sep <command1> [sep <command2> [...]], executes 'common command1', 'common command2', ..."
,		'callback' => sub {
			my ($w, $e, $help) = @_;
			my $sep = $w->[1]; # first word is the separator
			my $cmd = $e->[2]; # rest of the arguments taken as one string
			if( not( $sep and $cmd ) ) { Xchat::print($help) }
			else {
				my ($common, @cmds) = split/\s\Q$sep\E\s+/,$cmd;
				if( not( $common and scalar@cmds ) ) { Xchat::print($help) }
				else { Xchat::command([ map {join'',$common,$_} @cmds ]) }
			}
			return Xchat::EAT_XCHAT;
		}
	}
);

Xchat::register( $NAME, $VERSION, "Execute multiple commands in sequence" );
Xchat::print( "\02$NAME $VERSION\02 by b0at (use /".uc(join', /',keys%CMDS).")" );
Xchat::hook_command($_, $CMDS{$_}{callback}, 
	{help_text=>$CMDS{$_}{usage},
	      data=>$CMDS{$_}{usage}})
	for keys%CMDS;

__END__
#####################################################################

  author: b0at
 license: public domain

#####################################################################

examples:

    /multi | cmode +m | say NO YOU STFU! | timer 7 cmode -m
    /multi => say Well, would you look at the time? => join 0 => quit
	 /combo | say I want to | dance! | rock! | sing! | party until my pants fall down. | find a belt...

	Since space is required around the separator, 
	that character can appear elsewhere without it 
	separating commands; eg,

	 /multi : say Public notice: something : notice @#channel Private notice
	
	is the same as
	 /multi | say Public notice: something | notice @#channel Private notice
	
#####################################################################

some other ways to execute multiple commands:
	(http://www.xchat.org/faq/index.html#q214)
	 - /load -e /path/to/file
	 		which can allow you to save connect commands
	 		in a file in the config dir
	 - same-named user commands
	 		Settings -> Lists -> User Commands

#####################################################################