* Removed dependency Async.

* Rewrote the socket engine.
* Added cmd_add|del|run() to API::Std for commands.
* Parse PRIVMSG.
This commit is contained in:
Elijah Perrault committed 2011-01-28 22:36:59 -07:00
1 parent 17c00c5afd
commit 41d74bd20e
5 files changed
+114 -27

No files matched your search

+49 -1
View File
@@ -8,10 +8,10 @@ use strict;
use warnings;
use Exporter;
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS);
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del);
my (%LANGE, %MODULE, %EVENTS, %HOOKS);
# Initialize a module.
@@ -92,13 +92,51 @@ sub mod_void
# Add a command to Auto.
sub cmd_add
{
my ($cmd, $lvl, $fhelp, $shelp, $sub) = @_;
$cmd = uc($cmd);
return 0 if (defined $CMDS{$cmd});
return 0 if ($lvl =~ m/[^0-2]/);
$CMDS{$cmd}{lvl} = $lvl;
$CMDS{$cmd}{fhelp} = $fhelp;
$CMDS{$cmd}{shelp} = $shelp;
$CMDS{$cmd}{sub} = $sub;
return 1;
}
# Delete a command from Auto.
sub cmd_del
{
my ($cmd) = @_;
$cmd = uc($cmd);
if (defined $CMDS{$cmd}) {
delete $CMDS{$cmd};
}
else {
return 0;
}
return 1;
}
# Run a command if it exists.
sub cmd_run
{
my ($cmd, $lvl, %src, @argv) = @_;
$cmd = uc($cmd);
return 0 if (!defined $CMDS{$cmd});
if ($CMDS{$cmd}{lvl} == $lvl or $CMDS{$cmd}{lvl} == 2) {
API::Log::println $cmd;
&{ $CMDS{$cmd}{sub} }(%src, @argv);
}
return 1;
}
# Add an event to Auto.
@@ -283,6 +321,16 @@ sub trans
}
}
# Privilege subroutine.
sub has_priv
{
my (%user, $priv) = @_;
return 1;
}
# Error subroutine.
sub err
{
+30
View File
@@ -25,6 +25,7 @@ our %RAWC = (
'477' => \&num477,
'JOIN' => \&cjoin,
'NICK' => \&nick,
'PRIVMSG' => \&privmsg,
);
# Variables for various functions.
@@ -334,6 +335,35 @@ sub nick
return 1;
}
# Parse: PRIVMSG
sub privmsg
{
my ($svr, @ex) = @_;
my %src = API::IRC::usrc(substr($ex[0], 1));
my $cprefix = (conf_get("fantasy_pf"))[0][0];
my $rprefix = substr($ex[3], 1, 1);
my $cmd = uc(substr($ex[3], 2));
my (@argv);
for (my $i = 4; $i < scalar(@ex); $i++) {
push(@argv, $ex[$i]);
}
$src{svr} = $svr;
# Check if it's to a channel or to us.
if (lc($ex[2]) eq lc($botnick{$svr}{nick})) {
# It is coming to us in a private message.
API::Std::cmd_run($cmd, 1, %src, @argv);
}
else {
# It is coming to us in a channel message.
$src{chan} = $ex[2];
API::Std::cmd_run($cmd, 0, %src, @argv);
}
return 1;
}
# Parse: TOPIC
sub topic
{