/COMMAND creation example fixed/updated.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1809 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-09-22 08:15:30 +00:00 committed by cras
parent 235402aa9f
commit d246f862e8

View File

@ -74,10 +74,16 @@ A list of signals that irssi sends can be found from signals.txt file.
You can create your own commands, or replace existing ones with You can create your own commands, or replace existing ones with
Irssi::command_bind(). The command handling work internally pretty much Irssi::command_bind(). The command handling work internally pretty much
the same as signal handlers, so if you replace existing command and don't the same as signal handlers, so if you replace existing command and don't
wish to let it run, call Irssi::signal_stop(). Here's an example: wish to let it run, call Irssi::signal_stop().
Here's an example:
# Usage: /HELLO [<nick>] # Usage: /HELLO [<nick>]
sub cmd_hello { sub cmd_hello {
# data - contains the parameters for /HELLO
# server - the active server in window
# witem - the active window item (eg. channel, query)
# or undef if the window is empty
my ($data, $server, $witem) = @_; my ($data, $server, $witem) = @_;
if (!$server || !$server->{connected}) { if (!$server || !$server->{connected}) {
@ -87,9 +93,10 @@ wish to let it run, call Irssi::signal_stop(). Here's an example:
if ($data) { if ($data) {
$server->command("/MSG $data Hello!"); $server->command("/MSG $data Hello!");
} elsif ($witem) { } elsif ($witem && ($witem->{type} eq "CHANNEL" ||
$witem->{type} eq "QUERY")) {
# there's query/channel active in window # there's query/channel active in window
$server->command("/MSG * Hello!"); $witem->command("/MSG ".$witem->{name}." Hello!");
} else { } else {
Irssi::print("Nick not given, and no active channel/query in window"); Irssi::print("Nick not given, and no active channel/query in window");
} }
@ -97,6 +104,7 @@ wish to let it run, call Irssi::signal_stop(). Here's an example:
Irssi::command_bind('hello', 'cmd_hello'); Irssi::command_bind('hello', 'cmd_hello');
Message levels Message levels
-------------- --------------