# This is a sample ICBM hooks file.  This one only contains
# four hook functions, but there can be any number of hooks
# in any number of files.  However, they must be loaded using
# the loadhook() function, not load().
#
# The hook function is passed an array of from 0 to 8 packet
# fields.  It is the hook function's responsibility to parse
# this array and do the right thing with the contents.
#
# The fourth of these functions is an example function that
# can be used to dump the contents of packets so that you can
# see what to filter on.

sub who
{
    docommand('/who .');
}
addhook('group', 'who');


sub register
{
    docommand('/msg server p MYPASSWORD');
}
addhook('connect', 'register');


sub humbug
{
    my ($who, $msg) = @_;

    if (substr($who,0,1) eq '*')	# private message
    {
        $who = substr($who,1);		# strip the *
        docommand("/msg $who H$1umb$1ug$2") if ($msg =~ /^b(l)?ah([.!])?$/i);
    }
    else				# open message
    {
        docommand("H$1umb$1ug$2") if ($msg =~ /^b(l)?ah([.!])?$/i);
    }
}
addhook('openmsg', 'humbug');


sub show_packet
{
    my $n = scalar @_;
    out(sprintf('Packet received with %d field%s',
                 $n,
                 $n == 1 ? '' : 's'));
    for (my $i = 0; $i < $n; $i++)
    {
        out(sprintf("Field %d: '%s'", $i, @_[$i]));
    }
}
# addhook ('rawmsg', 'show_packet');


sub deadjim
{
    my ($who, $msg) = @_;
    my $mask = get_trig_mask();

    if ($msg =~ /$mask/i || $who =~ /User not found/)
    {
        set_trig_status(0);
        set_trig_result($msg =~ /$mask/i ? $msg : $who);
    }
}
addhook('trigger', 'deadjim');
