# prefix.pl is in the public domain.
# Written by Thomas Morgan <tmorgan@pobox.com>

$add_ons .= '+prefix.pl' unless $add_ons =~ /\+prefix\.pl/;

$prefix = 'say ';
$cmdprefix = '/';

sub douserline {
  local($line)=@_;
  &dohooks("userline", $line);
  if ($line =~ /^\@ssfe\@/) {
    $ssfe=1;
    $raw_mode=1;
    $add_ons.="+ssfe";
    &dostatus;
  } elsif ($line =~ s/^$cmdprefix//) {
    &dohooks("command", $line);
    &docommand($line);
  } elsif ($query) {
    &dohooks("query", $line);
    &msg($query, $line);
  } else {
    &dohooks("noslash", $line);
    &docommand($line);
  }
}

push(@hooks, "userline", "command", "query", "noslash");

sub hook_prefix {
  $line = "$prefix$_[0]";
}

&addhook("noslash", "prefix");

sub cmd_prefix {
  if ($args) {
    eval(qq(\$prefix = $args));
  } else {
    &tell(qq(*** Prefix: "$prefix"));
  } 
}

&addcmd("prefix");

&addhelp("prefix", <<"EOH");
Usage: \cBPREFIX\cB ['<prefix>']
Changes the prefix for each line you type that doesn't start with /.
e.g. when you type /prefix 'say ' everything you type will be said on
the current channel (the default).  /prefix ' ' will set it to the
null command (the same as 'say ').  To emulate ircII's command_ mode,
use /prefix ''.  If you invoke /prefix with no arguments, it will tell
you the current prefix (the current value of \$prefix, which is
$prefix).
EOH

sub cmd_cmdprefix {
  if ($args) {
    eval(qq(\$cmdprefix = $args));
  } else {
    &tell(qq(*** Command prefix: "$cmdprefix"));
  }
}

&addcmd("cmdprefix");

&addhelp("cmdprefix", <<"EOH");
Usage: \cBCMDPREFIX\cB ['<prefix>']
Changes the prefix that determines whether each line you type is a
command or a message.  For example, /cmdprefix '#' makes sirc
interpret every line starting with a `#' as a command.  The default
is, of course, `/'.  If /cmdprefix is invoked with no arguments, it
prints the current command prefix (the current value of \$cmdprefix,
which is $cmdprefix).
EOH

1;

