More cleanup. Well, cleanup using perlre.
This commit is contained in:
1 parent
053bee2f0e
commit
a662c11f06
1 file changed
+75
-73
+75
-73
@@ -26,7 +26,7 @@ sub mod_init
|
|||||||
API::Log::dbug('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
API::Log::dbug('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
||||||
API::Log::alog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
API::Log::alog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
||||||
|
|
||||||
# Check if this module is compatible with this version of Auto.
|
# Check if this module is compatible with this version of Auto.
|
||||||
if ($autover ne '3.0.0d') {
|
if ($autover ne '3.0.0d') {
|
||||||
API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
||||||
API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
||||||
@@ -34,7 +34,9 @@ sub mod_init
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run the module's _init sub.
|
# Run the module's _init sub.
|
||||||
my $mi = eval($pkg."::_init();");
|
my $mi = eval {
|
||||||
|
&{ $pkg.'::_init' }();
|
||||||
|
};
|
||||||
|
|
||||||
if ($mi) {
|
if ($mi) {
|
||||||
# If successful, add to hash.
|
# If successful, add to hash.
|
||||||
@@ -43,17 +45,17 @@ sub mod_init
|
|||||||
$MODULE{$name}{author} = $author;
|
$MODULE{$name}{author} = $author;
|
||||||
$MODULE{$name}{pkg} = $pkg;
|
$MODULE{$name}{pkg} = $pkg;
|
||||||
|
|
||||||
API::Log::dbug("MODULES: ".$name." successfully loaded.");
|
API::Log::dbug('MODULES: '.$name.' successfully loaded.');
|
||||||
API::Log::alog("MODULES: ".$name." successfully loaded.");
|
API::Log::alog('MODULES: '.$name.' successfully loaded.');
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, return a failed to load message.
|
# Otherwise, return a failed to load message.
|
||||||
API::Log::dbug("MODULES: Failed to load ".$name.".");
|
API::Log::dbug('MODULES: Failed to load '.$name.q{.});
|
||||||
API::Log::alog("MODULES: Failed to load ".$name.".");
|
API::Log::alog('MODULES: Failed to load '.$name.q{.});
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +64,9 @@ sub mod_exists
|
|||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
|
||||||
return 1 if defined $API::Std::MODULE{$name};
|
if (defined $API::Std::MODULE{$name}) { return 1; }
|
||||||
return 0;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Void a module.
|
# Void a module.
|
||||||
@@ -72,32 +75,34 @@ sub mod_void
|
|||||||
my ($module) = @_;
|
my ($module) = @_;
|
||||||
|
|
||||||
# Log/debug.
|
# Log/debug.
|
||||||
API::Log::dbug("MODULES: Attempting to unload module: ".$module."...");
|
API::Log::dbug('MODULES: Attempting to unload module: '.$module.'...');
|
||||||
API::Log::alog("MODULES: Attempting to unload module: ".$module."...");
|
API::Log::alog('MODULES: Attempting to unload module: '.$module.'...');
|
||||||
|
|
||||||
# Check if this module exists.
|
# Check if this module exists.
|
||||||
unless (defined $MODULE{$module}) {
|
unless (defined $MODULE{$module}) {
|
||||||
API::Log::dbug("MODULES: Failed to unload ".$module.". No such module?");
|
API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?');
|
||||||
API::Log::alog("MODULES: Failed to unload ".$module.". No such module?");
|
API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the module's _void sub.
|
# Run the module's _void sub.
|
||||||
my $mi = eval($MODULE{$module}{pkg}."::_void();");
|
my $mi = eval {
|
||||||
|
&{ $MODULE{$module}{pkg}.'::_void' }();
|
||||||
|
};
|
||||||
|
|
||||||
if ($mi) {
|
if ($mi) {
|
||||||
# If successful, delete class from program and delete module from hash.
|
# If successful, delete class from program and delete module from hash.
|
||||||
Class::Unload->unload($MODULE{$module}{pkg});
|
Class::Unload->unload($MODULE{$module}{pkg});
|
||||||
delete $MODULE{$module};
|
delete $MODULE{$module};
|
||||||
API::Log::dbug("MODULES: Successfully unloaded ".$module.".");
|
API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.});
|
||||||
API::Log::alog("MODULES: Successfully unloaded ".$module.".");
|
API::Log::alog('MODULES: Successfully unloaded '.$module.q{.});
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, return a failed to unload message.
|
# Otherwise, return a failed to unload message.
|
||||||
API::Log::dbug("MODULES: Failed to unload ".$module.".");
|
API::Log::dbug('MODULES: Failed to unload '.$module.q{.});
|
||||||
API::Log::alog("MODULES: Failed to unload ".$module.".");
|
API::Log::alog('MODULES: Failed to unload '.$module.q{.});
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,10 +110,10 @@ sub mod_void
|
|||||||
sub cmd_add
|
sub cmd_add
|
||||||
{
|
{
|
||||||
my ($cmd, $lvl, $priv, $help, $sub) = @_;
|
my ($cmd, $lvl, $priv, $help, $sub) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if (defined $API::Std::CMDS{$cmd});
|
if (defined $API::Std::CMDS{$cmd}) { return; }
|
||||||
return 0 if ($lvl =~ m/[^0-2]/);
|
if ($lvl =~ m/[^0-2]/) { return; }
|
||||||
|
|
||||||
$API::Std::CMDS{$cmd}{lvl} = $lvl;
|
$API::Std::CMDS{$cmd}{lvl} = $lvl;
|
||||||
$API::Std::CMDS{$cmd}{help} = $help;
|
$API::Std::CMDS{$cmd}{help} = $help;
|
||||||
@@ -123,13 +128,13 @@ sub cmd_add
|
|||||||
sub cmd_del
|
sub cmd_del
|
||||||
{
|
{
|
||||||
my ($cmd) = @_;
|
my ($cmd) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
if (defined $API::Std::CMDS{$cmd}) {
|
if (defined $API::Std::CMDS{$cmd}) {
|
||||||
delete $API::Std::CMDS{$cmd};
|
delete $API::Std::CMDS{$cmd};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -140,13 +145,13 @@ sub event_add
|
|||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
|
||||||
unless (defined $EVENTS{lc($name)}) {
|
if (!defined $EVENTS{lc($name)}) {
|
||||||
$EVENTS{lc($name)} = 1;
|
$EVENTS{lc($name)} = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
API::Log::dbug("DEBUG: Attempt to add a pre-existing event[".lc($name)."]! Ignoring...");
|
API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +166,8 @@ sub event_del
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
API::Log::dbug("DEBUG: Attempt to delete a non-existing event[".lc($name)."! Ignoring...");
|
API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,9 +176,9 @@ sub event_run
|
|||||||
{
|
{
|
||||||
my ($event, @args) = @_;
|
my ($event, @args) = @_;
|
||||||
|
|
||||||
if (defined $EVENTS{lc($event)} and defined $HOOKS{lc($event)}) {
|
if (defined $EVENTS{lc $event} and defined $HOOKS{lc $event}) {
|
||||||
foreach my $hk (keys %{ $HOOKS{lc($event)} }) {
|
foreach my $hk (keys %{ $HOOKS{lc $event} }) {
|
||||||
&{ $HOOKS{lc($event)}{$hk} }(@args);
|
&{ $HOOKS{lc $event}{$hk} }(@args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,17 +190,17 @@ sub hook_add
|
|||||||
{
|
{
|
||||||
my ($event, $name, $sub) = @_;
|
my ($event, $name, $sub) = @_;
|
||||||
|
|
||||||
if (!defined $API::Std::HOOKS{lc($name)}) {
|
if (!defined $API::Std::HOOKS{lc $name}) {
|
||||||
if (defined $API::Std::EVENTS{lc($event)}) {
|
if (defined $API::Std::EVENTS{lc $event}) {
|
||||||
$API::Std::HOOKS{lc($event)}{lc($name)} = $sub;
|
$API::Std::HOOKS{lc $event}{lc $name} = $sub;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,12 +209,12 @@ sub hook_del
|
|||||||
{
|
{
|
||||||
my ($event, $name) = @_;
|
my ($event, $name) = @_;
|
||||||
|
|
||||||
if (defined $API::Std::HOOKS{lc($event)}{lc($name)}) {
|
if (defined $API::Std::HOOKS{lc $event}{lc $name}) {
|
||||||
delete $API::Std::HOOKS{lc($event)}{lc($name)};
|
delete $API::Std::HOOKS{lc $event}{lc $name};
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,49 +222,48 @@ sub hook_del
|
|||||||
sub timer_add
|
sub timer_add
|
||||||
{
|
{
|
||||||
my ($name, $type, $time, $sub) = @_;
|
my ($name, $type, $time, $sub) = @_;
|
||||||
$name = lc($name);
|
$name = lc $name;
|
||||||
|
|
||||||
# Check for invalid type/time.
|
# Check for invalid type/time.
|
||||||
if ($type =~ m/[^1-2]/) {
|
if ($type =~ m/[^1-2]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if ($time =~ m/[^0-9]/) {
|
if ($time =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless (defined $Auto::TIMERS{$name}) {
|
if (!defined $Auto::TIMERS{$name}) {
|
||||||
$Auto::TIMERS{$name}{type} = $type;
|
$Auto::TIMERS{$name}{type} = $type;
|
||||||
$Auto::TIMERS{$name}{time} = time + $time;
|
$Auto::TIMERS{$name}{time} = time + $time;
|
||||||
$Auto::TIMERS{$name}{secs} = $time if ($type == 2);
|
if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; }
|
||||||
$Auto::TIMERS{$name}{sub} = $sub;
|
$Auto::TIMERS{$name}{sub} = $sub;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a timer from Auto.
|
# Delete a timer from Auto.
|
||||||
sub timer_del
|
sub timer_del
|
||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
$name = lc($name);
|
$name = lc $name;
|
||||||
|
|
||||||
if (defined $Auto::TIMERS{$name}) {
|
if (defined $Auto::TIMERS{$name}) {
|
||||||
delete $Auto::TIMERS{$name};
|
delete $Auto::TIMERS{$name};
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hook onto a raw command.
|
# Hook onto a raw command.
|
||||||
sub rchook_add
|
sub rchook_add
|
||||||
{
|
{
|
||||||
my ($cmd, $sub) = @_;
|
my ($cmd, $sub) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if defined $Parser::IRC::RAWC{$cmd};
|
if (defined $Parser::IRC::RAWC{$cmd}) { return; }
|
||||||
|
|
||||||
$Parser::IRC::RAWC{$cmd} = $sub;
|
$Parser::IRC::RAWC{$cmd} = $sub;
|
||||||
|
|
||||||
@@ -270,9 +274,9 @@ sub rchook_add
|
|||||||
sub rchook_del
|
sub rchook_del
|
||||||
{
|
{
|
||||||
my ($cmd) = @_;
|
my ($cmd) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if !defined $Parser::IRC::RAWC{$cmd};
|
if (!defined $Parser::IRC::RAWC{$cmd}) { return; }
|
||||||
|
|
||||||
delete $Parser::IRC::RAWC{$cmd};
|
delete $Parser::IRC::RAWC{$cmd};
|
||||||
|
|
||||||
@@ -287,7 +291,7 @@ sub conf_get
|
|||||||
# Create an array out of the value.
|
# Create an array out of the value.
|
||||||
my @val;
|
my @val;
|
||||||
if ($value =~ m/:/) {
|
if ($value =~ m/:/) {
|
||||||
@val = split(':', $value);
|
@val = split ':', $value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@val = ($value);
|
@val = ($value);
|
||||||
@@ -300,7 +304,7 @@ sub conf_get
|
|||||||
|
|
||||||
# Return the requested configuration value(s).
|
# Return the requested configuration value(s).
|
||||||
if ($count == 1) {
|
if ($count == 1) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]} };
|
return %{ $Auto::SETTINGS{$val[0]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -308,7 +312,7 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($count == 2) {
|
elsif ($count == 2) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}{$val[1]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]}{$val[1]} };
|
return %{ $Auto::SETTINGS{$val[0]}{$val[1]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -316,7 +320,7 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($count == 3) {
|
elsif ($count == 3) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} };
|
return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -324,7 +328,7 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +353,7 @@ sub match_user
|
|||||||
my (%user) = @_;
|
my (%user) = @_;
|
||||||
|
|
||||||
# Get data from config.
|
# Get data from config.
|
||||||
return 0 if (!conf_get("user"));
|
if (!conf_get("user")) { return; }
|
||||||
my %uhp = conf_get("user");
|
my %uhp = conf_get("user");
|
||||||
|
|
||||||
foreach my $userkey (keys %uhp) {
|
foreach my $userkey (keys %uhp) {
|
||||||
@@ -360,7 +364,7 @@ sub match_user
|
|||||||
|
|
||||||
if ($uhk eq "net") {
|
if ($uhk eq "net") {
|
||||||
if (defined $user{svr}) {
|
if (defined $user{svr}) {
|
||||||
if (lc($user{svr}) ne lc(($ulhp{$uhk})[0][0])) {
|
if (lc $user{svr} ne lc ($ulhp{$uhk})[0][0]) {
|
||||||
# config.user:net conflicts with irc.user:svr.
|
# config.user:net conflicts with irc.user:svr.
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@@ -375,14 +379,14 @@ sub match_user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($uhk eq "chanstatus" and defined $ulhp{'net'}) {
|
elsif ($uhk eq "chanstatus" and defined $ulhp{'net'}) {
|
||||||
my ($ccst, $ccnm) = split(':', ($ulhp{$uhk})[0][0]);
|
my ($ccst, $ccnm) = split ':', ($ulhp{$uhk})[0][0];
|
||||||
my $svr = $ulhp{net}[0];
|
my $svr = $ulhp{net}[0];
|
||||||
if (defined $Auto::SOCKET{$svr}) {
|
if (defined $Auto::SOCKET{$svr}) {
|
||||||
foreach my $bcj (@{ $Parser::IRC::botchans{$svr} }) {
|
foreach my $bcj (@{ $Parser::IRC::botchans{$svr} }) {
|
||||||
if (API::IRC::match_mask($bcj, $ccnm)) {
|
if (API::IRC::match_mask($bcj, $ccnm)) {
|
||||||
API::IRC::names($svr, $bcj);
|
API::IRC::names($svr, $bcj);
|
||||||
if (defined $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
if (defined $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
||||||
return $userkey if $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/;
|
if ($Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/) { return $userkey; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +395,7 @@ sub match_user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Privilege subroutine.
|
# Privilege subroutine.
|
||||||
@@ -404,12 +408,12 @@ sub has_priv
|
|||||||
|
|
||||||
if (defined $Auto::PRIVILEGES{$cups}) {
|
if (defined $Auto::PRIVILEGES{$cups}) {
|
||||||
foreach (@{ $Auto::PRIVILEGES{$cups} }) {
|
foreach (@{ $Auto::PRIVILEGES{$cups} }) {
|
||||||
return 1 if ($_ eq $cpriv or $_ eq "ALL");
|
if ($_ eq $cpriv or $_ eq "ALL") { return 1; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Error subroutine.
|
# Error subroutine.
|
||||||
@@ -419,10 +423,10 @@ sub err
|
|||||||
|
|
||||||
# Check for an invalid level.
|
# Check for an invalid level.
|
||||||
if ($lvl =~ m/[^0-9]/) {
|
if ($lvl =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if ($fatal =~ m/[^0-1]/) {
|
if ($fatal =~ m/[^0-1]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Level 1: Print to screen.
|
# Level 1: Print to screen.
|
||||||
@@ -435,9 +439,7 @@ sub err
|
|||||||
}
|
}
|
||||||
|
|
||||||
# If it's a fatal error, exit the program.
|
# If it's a fatal error, exit the program.
|
||||||
if ($fatal) {
|
if ($fatal) { exit; }
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -449,7 +451,7 @@ sub awarn
|
|||||||
|
|
||||||
# Check for an invalid level.
|
# Check for an invalid level.
|
||||||
if ($lvl =~ m/[^0-9]/) {
|
if ($lvl =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Level 1: Print to screen.
|
# Level 1: Print to screen.
|
||||||
|
|||||||
Reference in new issue
Block a user