diff --git a/auto b/auto index 1f256ce..a979c3c 100755 --- a/auto +++ b/auto @@ -8,46 +8,46 @@ PID=bin/auto.pid MODS="Class::Unload DBI" if [ "$1" = "start" ] ; then - if [ -e $PID ]; then - if [ "$2" = "force" ]; then - echo "Starting Auto. . ." - bin/auto - sleep 2 - if [ ! -r $PID ]; then - echo "Possible failed startup... check Auto logs for more information." - fi + if [ -e $PID ]; then + if [ "$2" = "force" ]; then + echo "Starting Auto. . ." + bin/auto + sleep 2 + if [ ! -r $PID ]; then + echo "Possible failed startup... check Auto logs for more information." + fi else echo "Auto appears to be running already. Run ./auto start force to start anyway." fi - else - echo "Starting Auto. . ." - bin/auto - sleep 2 - if [ ! -r $PID ]; then - echo "Possible failed startup... check Auto logs for more information" - fi - fi + else + echo "Starting Auto. . ." + bin/auto + sleep 2 + if [ ! -r $PID ]; then + echo "Possible failed startup... check Auto logs for more information" + fi + fi elif [ "$1" = "stop" ]; then - echo "Stopping Auto. . ." - kill -TERM `cat $PID` + echo "Stopping Auto. . ." + kill -TERM `cat $PID` elif [ "$1" = "rehash" ]; then - echo "Rehashing Auto. . ." - kill -HUP `cat $PID` + echo "Rehashing Auto. . ." + kill -HUP `cat $PID` elif [ "$1" = "status" ]; then - if [ -e $PID ]; then - echo "Status: Auto appears to be running." - else - echo "Status: Auto appears to not be running." - fi + if [ -e $PID ]; then + echo "Status: Auto appears to be running." + else + echo "Status: Auto appears to not be running." + fi elif [ "$1" = "getmodules" ]; then - cpan -i $MODS + cpan -i $MODS else - echo "Usage: auto (start|stop|rehash|status|getmodules)" + echo "Usage: auto (start|stop|rehash|status|getmodules)" fi # vim: set ai sw=4 ts=4: diff --git a/bin/auto b/bin/auto index 5a9335e..10a5ee2 100755 --- a/bin/auto +++ b/bin/auto @@ -23,11 +23,11 @@ BEGIN { # Set version information. use constant { ## no critic qw(ValuesAndExpressions::ProhibitConstantPragma) - NAME => 'Auto IRC Bot', - VER => 3, - SVER => 0, - REV => 0, - RSTAGE => 'd', + NAME => 'Auto IRC Bot', + VER => 3, + SVER => 0, + REV => 0, + RSTAGE => 'd', GR => substr `cat $Bin/../.git/refs/heads/indev`, 0, 7 }; } @@ -46,7 +46,7 @@ local $PROGRAM_NAME = 'auto'; # Check for build files. if (!-e "$Bin/../build/os" or !-e "$Bin/../build/perl" or !-e "$Bin/../build/time" or !-e "$Bin/../build/ver") { - say 'Missing build file(s). Please build Auto before running it.' and exit; + say 'Missing build file(s). Please build Auto before running it.' and exit; } # Check build OS. @@ -54,7 +54,7 @@ open my $BFOS, '<', "$Bin/../build/os" or say 'Cannot start: Broken build.' and my @BFOS = <$BFOS>; close $BFOS or say 'Cannot start: Broken build.' and exit; if ($BFOS[0] ne $OSNAME."\n") { - say 'Cannot start: Broken build.' and exit; + say 'Cannot start: Broken build.' and exit; } undef @BFOS; @@ -71,7 +71,7 @@ open my $BFPERL, '<', "$Bin/../build/perl" or say 'Cannot start: Broken build.' my @BFPERL = <$BFPERL>; close $BFPERL or say 'Cannot start: Broken build.' and exit; if ($BFPERL[0] ne $]."\n") { - say 'Cannot start: Broken build.' and exit; + say 'Cannot start: Broken build.' and exit; } undef @BFPERL; @@ -80,7 +80,7 @@ open my $BFVER, '<', "$Bin/../build/ver" or say 'Cannot start: Broken build.' an my @BFVER = <$BFVER>; close $BFVER or say 'Cannot start: Broken build.' and exit; if ($BFVER[0] ne VER.q{.}.SVER.q{.}.REV.RSTAGE."\n") { - say 'Cannot start: Broken build.' and exit; + say 'Cannot start: Broken build.' and exit; } undef @BFVER; @@ -112,8 +112,8 @@ our ($APID, %TIMERS); our $DEBUG = 0; our $NUC = 0; if (defined $ARGV[0]) { - foreach (@ARGV) { - given ($_) { + foreach (@ARGV) { + given ($_) { when ('-d') { $DEBUG = 1; } when ('-nuc') { $NUC = 1; } } @@ -135,23 +135,23 @@ our %SETTINGS = $CONF->parse or err(1, 'Failed to parse configuration file!', 1) say ' Success'; if (conf_get('die')) { - if ((conf_get('die'))[0][0] == 1) { - say '!!! You didn\'t read the whole config.'; - say '!!! Insert new user then try again.'; - exit; - } + if ((conf_get('die'))[0][0] == 1) { + say '!!! You didn\'t read the whole config.'; + say '!!! Insert new user then try again.'; + exit; + } } # Check for required configuration values. my @REQCVALS = qw(locale expire_logs server fantasy_pf ratelimit database:format bantype); foreach my $REQCVAL (@REQCVALS) { - if (!conf_get($REQCVAL)) { - my $err = 2; - if ($REQCVAL eq 'expire_logs') { - $err = 1; - } - err($err, "Missing required configuration value: $REQCVAL", 1); - } + if (!conf_get($REQCVAL)) { + my $err = 2; + if ($REQCVAL eq 'expire_logs') { + $err = 1; + } + err($err, "Missing required configuration value: $REQCVAL", 1); + } } undef @REQCVALS; @@ -253,49 +253,49 @@ Core::IRC::clear_usercmd_timer(); our (%PRIVILEGES); # If there are any privsets. if (conf_get('privset')) { - # Get them. - my %tcprivs = conf_get('privset'); + # Get them. + my %tcprivs = conf_get('privset'); foreach my $tckpriv (keys %tcprivs) { - # For each privset, get the inner values. - my %mcprivs = conf_get("privset:$tckpriv"); + # For each privset, get the inner values. + my %mcprivs = conf_get("privset:$tckpriv"); # Iterate through them. - foreach my $mckpriv (keys %mcprivs) { - # Switch statement for the values. - given ($mckpriv) { - # If it's 'priv', save it as a privilege. - when ('priv') { - if (defined $PRIVILEGES{$tckpriv}) { - # If this privset exists, push to it. - push @{ $PRIVILEGES{$tckpriv} }, ($mcprivs{$mckpriv})[0][0]; - } - else { - # Otherwise, create it. - @{ $PRIVILEGES{$tckpriv} } = (($mcprivs{$mckpriv})[0][0]); - } - } - # If it's 'inherit', inherit the privileges of another privset. - when ('inherit') { - # If the privset we're inheriting exists, continue. - if (defined $PRIVILEGES{($mcprivs{$mckpriv})[0][0]}) { - # Iterate through each privilege. - foreach (@{ $PRIVILEGES{($mcprivs{$mckpriv})[0][0]} }) { - # And save them to the privset inheriting them - if (defined $PRIVILEGES{$tckpriv}) { - # If this privset exists, push to it. - push @{ $PRIVILEGES{$tckpriv} }, $_; - } - else { - # Otherwise, create it. - @{ $PRIVILEGES{$tckpriv} } = ($_); - } - } - } - } - } - } - } + foreach my $mckpriv (keys %mcprivs) { + # Switch statement for the values. + given ($mckpriv) { + # If it's 'priv', save it as a privilege. + when ('priv') { + if (defined $PRIVILEGES{$tckpriv}) { + # If this privset exists, push to it. + push @{ $PRIVILEGES{$tckpriv} }, ($mcprivs{$mckpriv})[0][0]; + } + else { + # Otherwise, create it. + @{ $PRIVILEGES{$tckpriv} } = (($mcprivs{$mckpriv})[0][0]); + } + } + # If it's 'inherit', inherit the privileges of another privset. + when ('inherit') { + # If the privset we're inheriting exists, continue. + if (defined $PRIVILEGES{($mcprivs{$mckpriv})[0][0]}) { + # Iterate through each privilege. + foreach (@{ $PRIVILEGES{($mcprivs{$mckpriv})[0][0]} }) { + # And save them to the privset inheriting them + if (defined $PRIVILEGES{$tckpriv}) { + # If this privset exists, push to it. + push @{ $PRIVILEGES{$tckpriv} }, $_; + } + else { + # Otherwise, create it. + @{ $PRIVILEGES{$tckpriv} } = ($_); + } + } + } + } + } + } + } } # Successful startup. @@ -313,11 +313,11 @@ if (!$DEBUG) { if ($APID != 0) { alog '* Successfully forked into the background. Process ID: '.$APID; if (!-e "$Bin/auto.pid") { - system "touch $Bin/auto.pid"; - } - open my $FPID, '>', "$Bin/auto.pid" or exit; - print {$FPID} "$APID\n" or exit; - close $FPID or exit; + system "touch $Bin/auto.pid"; + } + open my $FPID, '>', "$Bin/auto.pid" or exit; + print {$FPID} "$APID\n" or exit; + close $FPID or exit; exit; } POSIX::setsid() or err(2, "Can't start a new session: $ERRNO", 1); @@ -331,11 +331,11 @@ API::Std::event_add('on_preconnect'); # Load modules. if (conf_get('module')) { - alog '* Loading modules...'; - dbug '* Loading modules...'; - foreach (@{ (conf_get('module'))[0] }) { - mod_load($_); - } + alog '* Loading modules...'; + dbug '* Loading modules...'; + foreach (@{ (conf_get('module'))[0] }) { + mod_load($_); + } } ## Create sockets. @@ -351,13 +351,13 @@ my $it = 0; foreach my $cskey (keys %cservers) { # Prepare socket data. my %conndata = ( - Proto => 'tcp', - LocalAddr => $cservers{$cskey}{'bind'}[0], - PeerAddr => $cservers{$cskey}{'host'}[0], - PeerPort => $cservers{$cskey}{'port'}[0], + Proto => 'tcp', + LocalAddr => $cservers{$cskey}{'bind'}[0], + PeerAddr => $cservers{$cskey}{'host'}[0], + PeerPort => $cservers{$cskey}{'port'}[0], Timeout => 20, ); - # Set IPv6/SSL data. + # Set IPv6/SSL data. my $use6 = 0; my $usessl = 0; if (defined $cservers{$cskey}{'ipv6'}[0]) { $use6 = $cservers{$cskey}{'ipv6'}[0]; } @@ -383,50 +383,50 @@ foreach my $cskey (keys %cservers) { # Create the socket. if ($use6) { - $SOCKET{$cskey} = IO::Socket::INET6->new(%conndata) or # Or error. + $SOCKET{$cskey} = IO::Socket::INET6->new(%conndata) or # Or error. err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) and delete $SOCKET{$cskey} and next; } else { if ($usessl) { - $SOCKET{$cskey} = IO::Socket::SSL->new(%conndata) or # Or error. + $SOCKET{$cskey} = IO::Socket::SSL->new(%conndata) or # Or error. err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) and delete $SOCKET{$cskey} and next; } else { - $SOCKET{$cskey} = IO::Socket::INET->new(%conndata) or # Or error. + $SOCKET{$cskey} = IO::Socket::INET->new(%conndata) or # Or error. err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) and delete $SOCKET{$cskey} and next; } } # Send PASS if we have one. - if (defined $cservers{$cskey}{'pass'}[0]) { - socksnd($cskey, 'PASS :'.$cservers{$cskey}{'pass'}[0]) or - err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) - and next; - } - API::Std::event_run('on_preconnect', $cskey); - # Send NICK/USER. - API::IRC::nick($cskey, $cservers{$cskey}{'nick'}[0]); - socksnd($cskey, 'USER '.$cservers{$cskey}{'ident'}[0].q{ }.hostname.q{ }.$cservers{$cskey}{'host'}[0].' :'.$cservers{$cskey}{'realname'}[0]) or - err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) - and next; - # Add to select. - $SELECT->add($SOCKET{$cskey}); - # Success! - alog '** Successfully connected to server: '.$cskey; - dbug '** Successfully connected to server: '.$cskey; - $it = 1; + if (defined $cservers{$cskey}{'pass'}[0]) { + socksnd($cskey, 'PASS :'.$cservers{$cskey}{'pass'}[0]) or + err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) + and next; + } + API::Std::event_run('on_preconnect', $cskey); + # Send NICK/USER. + API::IRC::nick($cskey, $cservers{$cskey}{'nick'}[0]); + socksnd($cskey, 'USER '.$cservers{$cskey}{'ident'}[0].q{ }.hostname.q{ }.$cservers{$cskey}{'host'}[0].' :'.$cservers{$cskey}{'realname'}[0]) or + err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0) + and next; + # Add to select. + $SELECT->add($SOCKET{$cskey}); + # Success! + alog '** Successfully connected to server: '.$cskey; + dbug '** Successfully connected to server: '.$cskey; + $it = 1; } # Success! if ($it) { - alog '** Success: Connected to server(s).'; - dbug '** Success: Connected to server(s).'; + alog '** Success: Connected to server(s).'; + dbug '** Success: Connected to server(s).'; } else { - err(2, 'No server connections.', 1); + err(2, 'No server connections.', 1); } undef $it; @@ -442,40 +442,40 @@ API::Std::cmd_add('HELP', 2, 0, \%Core::Cmd::HELP_HELP, \&Core::Cmd::cmd_help); # Infinite while loop. while (1) { - # Timer check. - foreach my $tk (keys %TIMERS) { - if ($TIMERS{$tk}{time} <= time) { - &{ $TIMERS{$tk}{sub} }(); - if ($TIMERS{$tk}{type} == 1) { - # If it's type 1, delete from memory. - delete $TIMERS{$tk}; - } - elsif ($TIMERS{$tk}{type} == 2) { - # If it's type 2, reset timer. - $TIMERS{$tk}{time} = time + $TIMERS{$tk}{secs}; - } - else { - # This should never happen. - delete $TIMERS{$tk}; - } - } - } - # Socket check. - foreach my $sock ($SELECT->can_read(1)) { - # Figure out what network is sending us data. - my $sockid; - foreach (keys %SOCKET) { - if ($SOCKET{$_} eq $sock) { $sockid = $_; } - } - # Read the data. - my $idata; - sysread $sock, $idata, POSIX::BUFSIZ, 0; + # Timer check. + foreach my $tk (keys %TIMERS) { + if ($TIMERS{$tk}{time} <= time) { + &{ $TIMERS{$tk}{sub} }(); + if ($TIMERS{$tk}{type} == 1) { + # If it's type 1, delete from memory. + delete $TIMERS{$tk}; + } + elsif ($TIMERS{$tk}{type} == 2) { + # If it's type 2, reset timer. + $TIMERS{$tk}{time} = time + $TIMERS{$tk}{secs}; + } + else { + # This should never happen. + delete $TIMERS{$tk}; + } + } + } + # Socket check. + foreach my $sock ($SELECT->can_read(1)) { + # Figure out what network is sending us data. + my $sockid; + foreach (keys %SOCKET) { + if ($SOCKET{$_} eq $sock) { $sockid = $_; } + } + # Read the data. + my $idata; + sysread $sock, $idata, POSIX::BUFSIZ, 0; - # Check for the data. - if (!defined $idata || length($idata) == 0) { - # Got EOF, close socket - err(2, "Lost connection to $sockid!", 0); - $SELECT->remove($sock); + # Check for the data. + if (!defined $idata || length($idata) == 0) { + # Got EOF, close socket + err(2, "Lost connection to $sockid!", 0); + $SELECT->remove($sock); delete $SOCKET{$sockid}; if (!keys %SOCKET) { # No more connections, stop the program. @@ -486,22 +486,22 @@ while (1) { exit; } next; - } + } # Read the buffer. - my $data .= $idata; - while ($data =~ s/(.*\n)//) { - my $line = $1; + my $data .= $idata; + while ($data =~ s/(.*\n)//) { + my $line = $1; # Remove the newlines. - chomp $line; - # Debug. - dbug $sockid.' >> '.$line; + chomp $line; + # Debug. + dbug $sockid.' >> '.$line; # Parse data. - Parser::IRC::ircparse($sockid, $line); - } - } + Parser::IRC::ircparse($sockid, $line); + } + } } ############### @@ -511,16 +511,16 @@ while (1) { # Send data to socket. sub socksnd { - my ($svr, $data) = @_; + my ($svr, $data) = @_; if (defined $SOCKET{$svr}) { - syswrite $SOCKET{$svr}, $data."\n", POSIX::BUFSIZ, 0; - dbug "$svr << $data"; - return 1; - } - else { - return 0; - } + syswrite $SOCKET{$svr}, $data."\n", POSIX::BUFSIZ, 0; + dbug "$svr << $data"; + return 1; + } + else { + return 0; + } } # Load a module. diff --git a/install b/install index b9b4c83..aca3db9 100755 --- a/install +++ b/install @@ -19,18 +19,18 @@ our $ERROR = 0; # Iterate through the arguments passed to us. my $features = 'base ssl sqlite'; if (defined $ARGV[0]) { - foreach (@ARGV) { - if ($_ eq '-h' or $_ eq '--help') { - println '*** ./install help ***'; - println ' --enable-sasl - Enable support for SASL.'; + foreach (@ARGV) { + if ($_ eq '-h' or $_ eq '--help') { + println '*** ./install help ***'; + println ' --enable-sasl - Enable support for SASL.'; println ' --enable-ipv6 - Enable support for IPv6.'; println ' --disable-ssl - Disable support for SSL.'; - println '*** End of Help ***'; - exit 1; - } - elsif ($_ eq '--enable-sasl') { - $features .= ' sasl'; - } + println '*** End of Help ***'; + exit 1; + } + elsif ($_ eq '--enable-sasl') { + $features .= ' sasl'; + } elsif ($_ eq '--disable-ssl') { $features =~ s/ ssl//g; } @@ -40,13 +40,13 @@ if (defined $ARGV[0]) { elsif ($_ eq '--with-mysql') { $features =~ s/(sqlite|pgsql)/mysql/g; } - elsif ($_ eq '--with-pgsql') { + elsif ($_ eq '--with-pgsql') { $features =~ s/(sqlite|mysql)/pgsql/g; } else { - println "Warning: Unknown option '$_'"; - } - } + println "Warning: Unknown option '$_'"; + } + } } # Check Perl version. @@ -58,32 +58,32 @@ eval { # Check operating system. print "Checking operating system..... $OSNAME - "; if ($OSNAME =~ /dos/i) { - print "DOS is not supported.\r\n"; + print "DOS is not supported.\r\n"; } elsif ($OSNAME eq "MSWin32") { - print "Microsoft Windows is not supported. Support is planned for the future.\r\n"; + print "Microsoft Windows is not supported. Support is planned for the future.\r\n"; } elsif ($OSNAME eq "NetWare") { - print "NetWare is not supported.\r\n"; + print "NetWare is not supported.\r\n"; } elsif ($OSNAME eq "linux") { - print "OK\n"; + print "OK\n"; } elsif ($OSNAME eq "os2") { - print "IBM OS/2 is not supported.\r\n"; + print "IBM OS/2 is not supported.\r\n"; } elsif ($OSNAME =~ /mac/i or $OSNAME =~ /darwin/i) { - print "OK\r"; + print "OK\r"; } elsif ($OSNAME eq "freebsd") { - print "OK\n"; + print "OK\n"; } elsif ($OSNAME eq "openbsd") { - print "OK\n"; + print "OK\n"; } else { - print "Unknown operating system. Contact support.\r\n"; -} + print "Unknown operating system. Contact support.\r\n"; +} # Check for Perl core modules. println "Checking for core Perl modules....."; @@ -124,19 +124,19 @@ else { println "\0"; println "Building....."; if (!-d "$Bin/build") { - system "mkdir $Bin/build"; + system "mkdir $Bin/build"; } if (!-e "$Bin/build/time") { - system "touch $Bin/build/time"; + system "touch $Bin/build/time"; } if (!-e "$Bin/build/os") { - system "touch $Bin/build/os"; + system "touch $Bin/build/os"; } if (!-e "$Bin/build/perl") { - system "touch $Bin/build/perl"; + system "touch $Bin/build/perl"; } if (!-e "$Bin/build/ver") { - system "touch $Bin/build/ver"; + system "touch $Bin/build/ver"; } build($features); diff --git a/lib/API/IRC.pm b/lib/API/IRC.pm index 15216a1..3710e8a 100644 --- a/lib/API/IRC.pm +++ b/lib/API/IRC.pm @@ -48,68 +48,68 @@ sub ban # Join a channel. sub cjoin { - my ($svr, $chan, $key) = @_; - - Auto::socksnd($svr, "JOIN ".((defined $key) ? "$chan $key" : "$chan")); - - return 1; + my ($svr, $chan, $key) = @_; + + Auto::socksnd($svr, "JOIN ".((defined $key) ? "$chan $key" : "$chan")); + + return 1; } # Part a channel. sub cpart { - my ($svr, $chan, $reason) = @_; - - if (defined $reason) { - Auto::socksnd($svr, "PART $chan :$reason"); - } - else { - Auto::socksnd($svr, "PART $chan :Leaving"); - } + my ($svr, $chan, $reason) = @_; + + if (defined $reason) { + Auto::socksnd($svr, "PART $chan :$reason"); + } + else { + Auto::socksnd($svr, "PART $chan :Leaving"); + } if (defined $Parser::IRC::botchans{$svr}{$chan}) { delete $Parser::IRC::botchans{$svr}{$chan}; } - - return 1; + + return 1; } # Set mode(s) on a channel. sub cmode { - my ($svr, $chan, $modes) = @_; + my ($svr, $chan, $modes) = @_; - Auto::socksnd($svr, "MODE $chan $modes"); - - return 1; + Auto::socksnd($svr, "MODE $chan $modes"); + + return 1; } # Set mode(s) on us. sub umode { - my ($svr, $modes) = @_; - - Auto::socksnd($svr, "MODE ".$Parser::IRC::botnick{$svr}{nick}." $modes"); - - return 1; + my ($svr, $modes) = @_; + + Auto::socksnd($svr, "MODE ".$Parser::IRC::botnick{$svr}{nick}." $modes"); + + return 1; } # Send a PRIVMSG. sub privmsg { - my ($svr, $target, $message) = @_; - - Auto::socksnd($svr, "PRIVMSG $target :$message"); - - return 1; + my ($svr, $target, $message) = @_; + + Auto::socksnd($svr, "PRIVMSG $target :$message"); + + return 1; } # Send a NOTICE. sub notice { - my ($svr, $target, $message) = @_; - - Auto::socksnd($svr, "NOTICE $target :$message"); - - return 1; + my ($svr, $target, $message) = @_; + + Auto::socksnd($svr, "NOTICE $target :$message"); + + return 1; } # Send an ACTION PRIVMSG. @@ -125,33 +125,33 @@ sub act # Change bot nickname. sub nick { - my ($svr, $newnick) = @_; - - Auto::socksnd($svr, "NICK $newnick"); - - $Parser::IRC::botnick{$svr}{newnick} = $newnick; - - return 1; + my ($svr, $newnick) = @_; + + Auto::socksnd($svr, "NICK $newnick"); + + $Parser::IRC::botnick{$svr}{newnick} = $newnick; + + return 1; } # Request the users of a channel. sub names { - my ($svr, $chan) = @_; - - Auto::socksnd($svr, "NAMES $chan"); - - return 1; + my ($svr, $chan) = @_; + + Auto::socksnd($svr, "NAMES $chan"); + + return 1; } # Send a topic to the channel. sub topic { - my ($svr, $chan, $topic) = @_; - - Auto::socksnd($svr, "TOPIC $chan :$topic"); - - return 1; + my ($svr, $chan, $topic) = @_; + + Auto::socksnd($svr, "TOPIC $chan :$topic"); + + return 1; } # Kick a user. @@ -167,54 +167,54 @@ sub kick # Quit IRC. sub quit { - my ($svr, $reason) = @_; - - if (defined $reason) { - Auto::socksnd($svr, "QUIT :$reason"); - } - else { - Auto::socksnd($svr, "QUIT :Leaving"); - } - - delete $Parser::IRC::got_001{$svr} if (defined $Parser::IRC::got_001{$svr}); - delete $Parser::IRC::botnick{$svr} if (defined $Parser::IRC::botnick{$svr}); - - return 1; + my ($svr, $reason) = @_; + + if (defined $reason) { + Auto::socksnd($svr, "QUIT :$reason"); + } + else { + Auto::socksnd($svr, "QUIT :Leaving"); + } + + delete $Parser::IRC::got_001{$svr} if (defined $Parser::IRC::got_001{$svr}); + delete $Parser::IRC::botnick{$svr} if (defined $Parser::IRC::botnick{$svr}); + + return 1; } # Get nick, ident and host from a !@ sub usrc { - my ($ex) = @_; - - my @si = split('!', $ex); - my @sii = split('@', $si[1]); - - return ( - nick => $si[0], - user => $sii[0], - host => $sii[1] - ); + my ($ex) = @_; + + my @si = split('!', $ex); + my @sii = split('@', $si[1]); + + return ( + nick => $si[0], + user => $sii[0], + host => $sii[1] + ); } # Match two IRC masks. sub match_mask { - my ($mu, $mh) = @_; - - # Prepare the regex. - $mh =~ s/\./\\\./g; - $mh =~ s/\?/\./g; - $mh =~ s/\*/\.\*/g; - $mh = '^'.$mh.'$'; - - # Let's grep the user's mask. - if (grep(/$mh/, $mu)) { - return 1; - } - - return 0; + my ($mu, $mh) = @_; + + # Prepare the regex. + $mh =~ s/\./\\\./g; + $mh =~ s/\?/\./g; + $mh =~ s/\*/\.\*/g; + $mh = '^'.$mh.'$'; + + # Let's grep the user's mask. + if (grep(/$mh/, $mu)) { + return 1; + } + + return 0; } diff --git a/lib/API/Log.pm b/lib/API/Log.pm index 9c2222d..86c04ea 100644 --- a/lib/API/Log.pm +++ b/lib/API/Log.pm @@ -18,11 +18,11 @@ our @EXPORT_OK = qw(println dbug alog slog); # Print with the system newline appended. sub println { - my ($out) = @_; + my ($out) = @_; - if (!defined $out) { - print $RS; - } + if (!defined $out) { + print $RS; + } else { print $out.$RS; } @@ -33,79 +33,79 @@ sub println # Print only if in debug mode. sub dbug { - my ($out) = @_; + my ($out) = @_; - if ($Auto::DEBUG) { - # We're in debug mode; print it out. - say $out; - } + if ($Auto::DEBUG) { + # We're in debug mode; print it out. + say $out; + } - return 1; + return 1; } # Log to file. sub alog { - my ($lmsg) = @_; + my ($lmsg) = @_; - # Expire old logs first. - expire_logs(); + # Expire old logs first. + expire_logs(); - # Get date and time in the desired format. - my $date = POSIX::strftime('%Y%m%d', localtime); - my $time = POSIX::strftime('%Y-%m-%d %I:%M:%S %p', localtime); + # Get date and time in the desired format. + my $date = POSIX::strftime('%Y%m%d', localtime); + my $time = POSIX::strftime('%Y-%m-%d %I:%M:%S %p', localtime); - # Create var/ if it doesn't exist. - if (!-d "$Auto::Bin/../var") { - mkdir "$Auto::Bin/../var", 0600; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - } - # Create var/DATE.log if it doesn't exist. - if (!-e "$Auto::Bin/../var/$date.log") { - system "touch $Auto::Bin/../var/$date.log"; - } + # Create var/ if it doesn't exist. + if (!-d "$Auto::Bin/../var") { + mkdir "$Auto::Bin/../var", 0600; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + } + # Create var/DATE.log if it doesn't exist. + if (!-e "$Auto::Bin/../var/$date.log") { + system "touch $Auto::Bin/../var/$date.log"; + } - # Open the logfile, print the log message to it and close it. - open my $FLOG, '>>', "$Auto::Bin/../var/$date.log" or return; - print {$FLOG} "[$time] $lmsg\n" or return; - close $FLOG or return; + # Open the logfile, print the log message to it and close it. + open my $FLOG, '>>', "$Auto::Bin/../var/$date.log" or return; + print {$FLOG} "[$time] $lmsg\n" or return; + close $FLOG or return; - return 1; + return 1; } # Expire old logs. sub expire_logs { - # Get configuration value. - my $celog = (conf_get('expire_logs'))[0][0] or return; + # Get configuration value. + my $celog = (conf_get('expire_logs'))[0][0] or return; - # Check for invalid values. - if ($celog =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - # Must be numbers only. - return; - } - elsif (!$celog) { - # No expire. - return; - } + # Check for invalid values. + if ($celog =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + # Must be numbers only. + return; + } + elsif (!$celog) { + # No expire. + return; + } - # Iterate through each logfile. - foreach my $file (glob "$Auto::Bin/../var/*") { - my (undef, $file) = split 'bin/../var/', $file; ## no critic qw(BuiltinFunctions::ProhibitStringySplit) + # Iterate through each logfile. + foreach my $file (glob "$Auto::Bin/../var/*") { + my (undef, $file) = split 'bin/../var/', $file; ## no critic qw(BuiltinFunctions::ProhibitStringySplit) - # Convert filename to UNIX time. - my $yyyy = substr $file, 0, 4; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - my $mm = substr $file, 4, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - $mm = $mm - 1; - my $dd = substr $file, 6, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - my $epoch = timelocal(0, 0, 0, $dd, $mm, $yyyy); + # Convert filename to UNIX time. + my $yyyy = substr $file, 0, 4; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + my $mm = substr $file, 4, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + $mm = $mm - 1; + my $dd = substr $file, 6, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + my $epoch = timelocal(0, 0, 0, $dd, $mm, $yyyy); - # If it's older than days, delete it. - if (time - $epoch > 86_400 * $celog) { ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - unlink "$Auto::Bin/../var/$file"; - } - } + # If it's older than days, delete it. + if (time - $epoch > 86_400 * $celog) { ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + unlink "$Auto::Bin/../var/$file"; + } + } - return 1; + return 1; } # Subroutine for logging to an IRC logchan. diff --git a/lib/API/Std.pm b/lib/API/Std.pm index 93c57a4..2f33b8c 100644 --- a/lib/API/Std.pm +++ b/lib/API/Std.pm @@ -11,237 +11,237 @@ use base qw(Exporter); our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS); our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add - cmd_del hook_add hook_del rchook_add rchook_del match_user - has_priv mod_exists ratelimit_check); + cmd_del hook_add hook_del rchook_add rchook_del match_user + has_priv mod_exists ratelimit_check); # Initialize a module. sub mod_init { - my ($name, $author, $version, $autover, $pkg) = @_; + my ($name, $author, $version, $autover, $pkg) = @_; # Log/debug. - 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::dbug('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...'); + API::Log::alog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...'); } # Check if this module is compatible with this version of Auto. - if ($autover ne '3.0.0a4' and $autover ne '3.0.0a5') { - 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.'); + if ($autover ne '3.0.0a4' and $autover ne '3.0.0a5') { + 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.'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); } - return; - } + return; + } - # Run the module's _init sub. + # Run the module's _init sub. my $mi = eval($pkg.'::_init();'); ## no critic qw(BuiltinFunctions::ProhibitStringyEval) - if ($mi) { - # If successful, add to hash. - $MODULE{$name}{name} = $name; - $MODULE{$name}{version} = $version; - $MODULE{$name}{author} = $author; - $MODULE{$name}{pkg} = $pkg; + if ($mi) { + # If successful, add to hash. + $MODULE{$name}{name} = $name; + $MODULE{$name}{version} = $version; + $MODULE{$name}{author} = $author; + $MODULE{$name}{pkg} = $pkg; - API::Log::dbug('MODULES: '.$name.' successfully loaded.'); - API::Log::alog('MODULES: '.$name.' successfully loaded.'); + API::Log::dbug('MODULES: '.$name.' successfully loaded.'); + API::Log::alog('MODULES: '.$name.' successfully loaded.'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: '.$name.' successfully loaded.'); } - return 1; - } - else { - # Otherwise, return a failed to load message. - API::Log::dbug('MODULES: Failed to load '.$name.q{.}); - API::Log::alog('MODULES: Failed to load '.$name.q{.}); + return 1; + } + else { + # Otherwise, return a failed to load message. + API::Log::dbug('MODULES: Failed to load '.$name.q{.}); + API::Log::alog('MODULES: Failed to load '.$name.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to load '.$name.q{.}); } - return; - } + return; + } } # Check if a module exists. sub mod_exists { - my ($name) = @_; + my ($name) = @_; - if (defined $API::Std::MODULE{$name}) { return 1; } + if (defined $API::Std::MODULE{$name}) { return 1; } - return; + return; } # Void a module. sub mod_void { - my ($module) = @_; + my ($module) = @_; - # Log/debug. - API::Log::dbug('MODULES: Attempting to unload module: '.$module.'...'); - API::Log::alog('MODULES: Attempting to unload module: '.$module.'...'); + # Log/debug. + API::Log::dbug('MODULES: Attempting to unload module: '.$module.'...'); + API::Log::alog('MODULES: Attempting to unload module: '.$module.'...'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Attempting to unload module: '.$module.'...'); } - # Check if this module exists. - if (!defined $MODULE{$module}) { - API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?'); - API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?'); + # Check if this module exists. + if (!defined $MODULE{$module}) { + API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?'); + API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to unload '.$module.'. No such module?'); } - return; - } + return; + } - # Run the module's _void sub. + # Run the module's _void sub. my $mi = eval($MODULE{$module}{pkg}.'::_void();'); ## no critic qw(BuiltinFunctions::ProhibitStringyEval) - if ($mi) { - # If successful, delete class from program and delete module from hash. - Class::Unload->unload($MODULE{$module}{pkg}); - delete $MODULE{$module}; - API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.}); - API::Log::alog('MODULES: Successfully unloaded '.$module.q{.}); + if ($mi) { + # If successful, delete class from program and delete module from hash. + Class::Unload->unload($MODULE{$module}{pkg}); + delete $MODULE{$module}; + API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.}); + API::Log::alog('MODULES: Successfully unloaded '.$module.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Successfully unloaded '.$module.q{.}); } - return 1; - } - else { - # Otherwise, return a failed to unload message. - API::Log::dbug('MODULES: Failed to unload '.$module.q{.}); - API::Log::alog('MODULES: Failed to unload '.$module.q{.}); + return 1; + } + else { + # Otherwise, return a failed to unload message. + API::Log::dbug('MODULES: Failed to unload '.$module.q{.}); + API::Log::alog('MODULES: Failed to unload '.$module.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to unload '.$module.q{.}); } - return; - } + return; + } } # Add a command to Auto. sub cmd_add { - my ($cmd, $lvl, $priv, $help, $sub) = @_; - $cmd = uc $cmd; + my ($cmd, $lvl, $priv, $help, $sub) = @_; + $cmd = uc $cmd; - if (defined $API::Std::CMDS{$cmd}) { return; } - if ($lvl =~ m/[^0-3]/sm) { return; } ## no critic qw(RegularExpressions::RequireExtendedFormatting) + if (defined $API::Std::CMDS{$cmd}) { return; } + if ($lvl =~ m/[^0-3]/sm) { return; } ## no critic qw(RegularExpressions::RequireExtendedFormatting) - $API::Std::CMDS{$cmd}{lvl} = $lvl; - $API::Std::CMDS{$cmd}{help} = $help; - $API::Std::CMDS{$cmd}{priv} = $priv; - $API::Std::CMDS{$cmd}{'sub'} = $sub; + $API::Std::CMDS{$cmd}{lvl} = $lvl; + $API::Std::CMDS{$cmd}{help} = $help; + $API::Std::CMDS{$cmd}{priv} = $priv; + $API::Std::CMDS{$cmd}{'sub'} = $sub; - return 1; + return 1; } # Delete a command from Auto. sub cmd_del { - my ($cmd) = @_; - $cmd = uc $cmd; + my ($cmd) = @_; + $cmd = uc $cmd; - if (defined $API::Std::CMDS{$cmd}) { - delete $API::Std::CMDS{$cmd}; - } - else { - return; - } + if (defined $API::Std::CMDS{$cmd}) { + delete $API::Std::CMDS{$cmd}; + } + else { + return; + } - return 1; + return 1; } # Add an event to Auto. sub event_add { - my ($name) = @_; + my ($name) = @_; - if (!defined $EVENTS{lc $name}) { - $EVENTS{lc $name} = 1; - return 1; - } - else { - API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...'); - return; - } + if (!defined $EVENTS{lc $name}) { + $EVENTS{lc $name} = 1; + return 1; + } + else { + API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...'); + return; + } } # Delete an event from Auto. sub event_del { - my ($name) = @_; + my ($name) = @_; - if (defined $EVENTS{lc $name}) { - delete $EVENTS{lc $name}; - delete $HOOKS{lc $name}; - return 1; - } - else { - API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...'); - return; - } + if (defined $EVENTS{lc $name}) { + delete $EVENTS{lc $name}; + delete $HOOKS{lc $name}; + return 1; + } + else { + API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...'); + return; + } } # Trigger an event. sub event_run { - my ($event, @args) = @_; + my ($event, @args) = @_; - if (defined $EVENTS{lc $event} and defined $HOOKS{lc $event}) { - foreach my $hk (keys %{ $HOOKS{lc $event} }) { - my $ri = &{ $HOOKS{lc $event}{$hk} }(@args); + if (defined $EVENTS{lc $event} and defined $HOOKS{lc $event}) { + foreach my $hk (keys %{ $HOOKS{lc $event} }) { + my $ri = &{ $HOOKS{lc $event}{$hk} }(@args); if ($ri == -1) { last; } - } - } + } + } - return 1; + return 1; } # Add a hook to Auto. sub hook_add { - my ($event, $name, $sub) = @_; + my ($event, $name, $sub) = @_; - if (!defined $API::Std::HOOKS{lc $name}) { - if (defined $API::Std::EVENTS{lc $event}) { - $API::Std::HOOKS{lc $event}{lc $name} = $sub; - return 1; - } - else { - return; - } - } - else { - return; - } + if (!defined $API::Std::HOOKS{lc $name}) { + if (defined $API::Std::EVENTS{lc $event}) { + $API::Std::HOOKS{lc $event}{lc $name} = $sub; + return 1; + } + else { + return; + } + } + else { + return; + } } # Delete a hook from Auto. sub hook_del { - my ($event, $name) = @_; + my ($event, $name) = @_; - if (defined $API::Std::HOOKS{lc $event}{lc $name}) { - delete $API::Std::HOOKS{lc $event}{lc $name}; - return 1; - } - else { - return; - } + if (defined $API::Std::HOOKS{lc $event}{lc $name}) { + delete $API::Std::HOOKS{lc $event}{lc $name}; + return 1; + } + else { + return; + } } # Add a timer to Auto. sub timer_add { - my ($name, $type, $time, $sub) = @_; - $name = lc $name; + my ($name, $type, $time, $sub) = @_; + $name = lc $name; - # Check for invalid type/time. - if ($type =~ m/[^1-2]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; - } - if ($time =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; - } + # Check for invalid type/time. + if ($type =~ m/[^1-2]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + return; + } + if ($time =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + return; + } - if (!defined $Auto::TIMERS{$name}) { - $Auto::TIMERS{$name}{type} = $type; - $Auto::TIMERS{$name}{time} = time + $time; - if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; } - $Auto::TIMERS{$name}{sub} = $sub; - return 1; - } + if (!defined $Auto::TIMERS{$name}) { + $Auto::TIMERS{$name}{type} = $type; + $Auto::TIMERS{$name}{time} = time + $time; + if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; } + $Auto::TIMERS{$name}{sub} = $sub; + return 1; + } return 1; } @@ -249,123 +249,123 @@ sub timer_add # Delete a timer from Auto. sub timer_del { - my ($name) = @_; - $name = lc $name; + my ($name) = @_; + $name = lc $name; - if (defined $Auto::TIMERS{$name}) { - delete $Auto::TIMERS{$name}; - return 1; - } + if (defined $Auto::TIMERS{$name}) { + delete $Auto::TIMERS{$name}; + return 1; + } - return; + return; } # Hook onto a raw command. sub rchook_add { - my ($cmd, $sub) = @_; - $cmd = uc $cmd; + my ($cmd, $sub) = @_; + $cmd = uc $cmd; - if (defined $Parser::IRC::RAWC{$cmd}) { return; } + if (defined $Parser::IRC::RAWC{$cmd}) { return; } - $Parser::IRC::RAWC{$cmd} = $sub; + $Parser::IRC::RAWC{$cmd} = $sub; - return 1; + return 1; } # Delete a raw command hook. sub rchook_del { - my ($cmd) = @_; - $cmd = uc $cmd; + my ($cmd) = @_; + $cmd = uc $cmd; - if (!defined $Parser::IRC::RAWC{$cmd}) { return; } + if (!defined $Parser::IRC::RAWC{$cmd}) { return; } - delete $Parser::IRC::RAWC{$cmd}; + delete $Parser::IRC::RAWC{$cmd}; - return 1; + return 1; } # Configuration value getter. sub conf_get { - my ($value) = @_; + my ($value) = @_; - # Create an array out of the value. - my @val; - if ($value =~ m/:/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - @val = split m/[:]/sm, $value; ## no critic qw(RegularExpressions::RequireExtendedFormatting) - } - else { - @val = ($value); - } - # Undefine this as it's unnecessary now. - undef $value; + # Create an array out of the value. + my @val; + if ($value =~ m/:/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + @val = split m/[:]/sm, $value; ## no critic qw(RegularExpressions::RequireExtendedFormatting) + } + else { + @val = ($value); + } + # Undefine this as it's unnecessary now. + undef $value; - # Get the count of elements in the array. - my $count = scalar @val; + # Get the count of elements in the array. + my $count = scalar @val; - # Return the requested configuration value(s). - if ($count == 1) { - if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]} }; - } - else { - return $Auto::SETTINGS{$val[0]}; - } - } - elsif ($count == 2) { - if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]}{$val[1]} }; - } - else { - return $Auto::SETTINGS{$val[0]}{$val[1]}; - } - } - elsif ($count == 3) { - if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} }; - } - else { - return $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}; - } - } - else { - return; - } + # Return the requested configuration value(s). + if ($count == 1) { + if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]} }; + } + else { + return $Auto::SETTINGS{$val[0]}; + } + } + elsif ($count == 2) { + if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]}{$val[1]} }; + } + else { + return $Auto::SETTINGS{$val[0]}{$val[1]}; + } + } + elsif ($count == 3) { + if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} }; + } + else { + return $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}; + } + } + else { + return; + } } # Translation subroutine. sub trans { my $id = shift; - $id =~ s/ /_/gsm; + $id =~ s/ /_/gsm; - if (defined $API::Std::LANGE{$id}) { - return sprintf $API::Std::LANGE{$id}, @_; - } - else { - $id =~ s/_/ /gsm; - return $id; - } + if (defined $API::Std::LANGE{$id}) { + return sprintf $API::Std::LANGE{$id}, @_; + } + else { + $id =~ s/_/ /gsm; + return $id; + } } # Match user subroutine. sub match_user { - my (%user) = @_; + my (%user) = @_; - # Get data from config. + # Get data from config. if (!conf_get('user')) { return; } - my %uhp = conf_get('user'); + my %uhp = conf_get('user'); - foreach my $userkey (keys %uhp) { - # For each user block. - my %ulhp = %{ $uhp{$userkey} }; - foreach my $uhk (keys %ulhp) { + foreach my $userkey (keys %uhp) { + # For each user block. + my %ulhp = %{ $uhp{$userkey} }; + foreach my $uhk (keys %ulhp) { # For each user. - if ($uhk eq 'net') { + if ($uhk eq 'net') { if (defined $user{svr}) { if (lc $user{svr} ne lc(($ulhp{$uhk})[0][0])) { # config.user:net conflicts with irc.user:svr. @@ -374,13 +374,13 @@ sub match_user } } elsif ($uhk eq 'mask') { - # Put together the user information. - my $mask = $user{nick}.q{!}.$user{user}.q{@}.$user{host}; - if (API::IRC::match_mask($mask, ($ulhp{$uhk})[0][0])) { - # We've got a host match. - return $userkey; - } - } + # Put together the user information. + my $mask = $user{nick}.q{!}.$user{user}.q{@}.$user{host}; + if (API::IRC::match_mask($mask, ($ulhp{$uhk})[0][0])) { + # We've got a host match. + return $userkey; + } + } elsif ($uhk eq 'chanstatus' and defined $ulhp{'net'}) { my ($ccst, $ccnm) = split m/[:]/sm, ($ulhp{$uhk})[0][0]; ## no critic qw(RegularExpressions::RequireExtendedFormatting) my $svr = $ulhp{net}[0]; @@ -401,28 +401,28 @@ sub match_user } } } - } - } + } + } - return; + return; } # Privilege subroutine. sub has_priv { - my ($cuser, $cpriv) = @_; + my ($cuser, $cpriv) = @_; - if (conf_get("user:$cuser:privs")) { - my $cups = (conf_get("user:$cuser:privs"))[0][0]; + if (conf_get("user:$cuser:privs")) { + my $cups = (conf_get("user:$cuser:privs"))[0][0]; - if (defined $Auto::PRIVILEGES{$cups}) { - foreach (@{ $Auto::PRIVILEGES{$cups} }) { - if ($_ eq $cpriv or $_ eq 'ALL') { return 1; } - } - } - } + if (defined $Auto::PRIVILEGES{$cups}) { + foreach (@{ $Auto::PRIVILEGES{$cups} }) { + if ($_ eq $cpriv or $_ eq 'ALL') { return 1; } + } + } + } - return; + return; } # Ratelimit check subroutine. @@ -461,59 +461,59 @@ sub ratelimit_check # Error subroutine. sub err ## no critic qw(Subroutines::ProhibitBuiltinHomonyms) { - my ($lvl, $msg, $fatal) = @_; + my ($lvl, $msg, $fatal) = @_; - # Check for an invalid level. - if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; - } - if ($fatal =~ m/[^0-1]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; - } + # Check for an invalid level. + if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + return; + } + if ($fatal =~ m/[^0-1]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + return; + } - # Level 1: Print to screen. - if ($lvl >= 1) { - say "ERROR: $msg"; - } - # Level 2: Log to file. - if ($lvl >= 2) { - API::Log::alog("ERROR: $msg"); - } + # Level 1: Print to screen. + if ($lvl >= 1) { + say "ERROR: $msg"; + } + # Level 2: Log to file. + if ($lvl >= 2) { + API::Log::alog("ERROR: $msg"); + } # Level 3: Log to IRC. if ($lvl >= 3) { API::Log::slog("ERROR: $msg"); } - # If it's a fatal error, exit the program. - if ($fatal) { exit; } + # If it's a fatal error, exit the program. + if ($fatal) { exit; } - return 1; + return 1; } # Warn subroutine. sub awarn { - my ($lvl, $msg) = @_; + my ($lvl, $msg) = @_; - # Check for an invalid level. - if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; - } + # Check for an invalid level. + if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) + return; + } - # Level 1: Print to screen. - if ($lvl >= 1) { - say "WARNING: $msg"; - } - # Level 2: Log to file. - if ($lvl >= 2) { - API::Log::alog("WARNING: $msg"); - } + # Level 1: Print to screen. + if ($lvl >= 1) { + say "WARNING: $msg"; + } + # Level 2: Log to file. + if ($lvl >= 2) { + API::Log::alog("WARNING: $msg"); + } # Level 3: Log to IRC. if ($lvl >= 3) { API::Log::slog("WARNING: $msg"); } - return 1; + return 1; } diff --git a/lib/Core/IRC.pm b/lib/Core/IRC.pm index 478ccc1..9e5bd90 100644 --- a/lib/Core/IRC.pm +++ b/lib/Core/IRC.pm @@ -43,22 +43,22 @@ hook_add("on_quit", "quit_update_chanusers", sub { hook_add("on_connect", "on_connect_modes", sub { my ($svr) = @_; - if (conf_get("server:$svr:modes")) { - my $connmodes = (conf_get("server:$svr:modes"))[0][0]; - API::IRC::umode($svr, $connmodes); - } + if (conf_get("server:$svr:modes")) { + my $connmodes = (conf_get("server:$svr:modes"))[0][0]; + API::IRC::umode($svr, $connmodes); + } return 1; }); # Plaintext auth. hook_add("on_connect", "plaintext_auth", sub { - my ($svr) = @_; + my ($svr) = @_; if (conf_get("server:$svr:idstr")) { - my $idstr = (conf_get("server:$svr:idstr"))[0][0]; - Auto::socksnd($svr, $idstr); - } + my $idstr = (conf_get("server:$svr:idstr"))[0][0]; + Auto::socksnd($svr, $idstr); + } return 1; }); @@ -67,14 +67,14 @@ hook_add("on_connect", "plaintext_auth", sub { hook_add("on_connect", "autojoin", sub { my ($svr) = @_; - # Get the auto-join from the config. - my @cajoin = @{ (conf_get("server:$svr:ajoin"))[0] }; - - # Join the channels. - if (!defined $cajoin[1]) { - # For single-line ajoins. - my @sajoin = split(',', $cajoin[0]); - + # Get the auto-join from the config. + my @cajoin = @{ (conf_get("server:$svr:ajoin"))[0] }; + + # Join the channels. + if (!defined $cajoin[1]) { + # For single-line ajoins. + my @sajoin = split(',', $cajoin[0]); + foreach (@sajoin) { # Check if a key was specified. if ($_ =~ m/\s/xsm) { @@ -84,13 +84,13 @@ hook_add("on_connect", "autojoin", sub { } else { # Else join without one. - API::IRC::cjoin($svr, $_); + API::IRC::cjoin($svr, $_); } } - } - else { - # For multi-line ajoins. - foreach (@cajoin) { + } + else { + # For multi-line ajoins. + foreach (@cajoin) { # Check if a key was specified. if ($_ =~ m/\s/xsm) { # There was, join with it. diff --git a/lib/Parser/Config.pm b/lib/Parser/Config.pm index 313ca68..09938ce 100644 --- a/lib/Parser/Config.pm +++ b/lib/Parser/Config.pm @@ -12,18 +12,18 @@ sub new my ($file) = @_; my $self = bless {}, $class; - # Check to see if the configuration file exists. - if (!-e "$Auto::Bin/../etc/$file") { - return 0; - } - - # Open, read and close the config. - open(my $FCONF, q{<}, "$Auto::Bin/../etc/$file") or return 0; - my @cosfl = <$FCONF> or return 0; - close $FCONF or return 0; - - # Save it to self variable. - $self->{'config'}->{'path'} = "$Auto::Bin/../etc/$file"; + # Check to see if the configuration file exists. + if (!-e "$Auto::Bin/../etc/$file") { + return 0; + } + + # Open, read and close the config. + open(my $FCONF, q{<}, "$Auto::Bin/../etc/$file") or return 0; + my @cosfl = <$FCONF> or return 0; + close $FCONF or return 0; + + # Save it to self variable. + $self->{'config'}->{'path'} = "$Auto::Bin/../etc/$file"; return $self; } @@ -31,148 +31,148 @@ sub new # Parse the configuration file. sub parse { - # Get the path to the file. - my $self = shift; - my $file = $self->{'config'}->{'path'}; - my $blk = 0; - my (%rs); - - # Open, read and close it. - open(my $FCONF, q{<}, "$file") or return 0; - my @fbuf = <$FCONF> or return 0; - close $FCONF or return 0; - - # Iterate the file. - foreach my $buff (@fbuf) { - # Main newline buffer. - if (defined $buff) { - # If the line begins with a #, it's a comment so ignore it. - if (substr($buff, 0, 1) eq '#') { - next; - } - - if ($buff =~ m/;/) { - # Semicolon buffer. - my @asbuf = split(';', $buff); - foreach my $asbuff (@asbuf) { - if (defined $asbuff) { - - # Space buffer. - my @ebuf = split(' ', $asbuff); - if (!defined $ebuf[0] or !defined $ebuf[1]) { - # Garbage. Ignoring. - next; - } - my $param = $ebuf[1]; - - if (substr($param, 0, 1) eq '"' and substr($param, length($param) - 1, 1) ne '"') { - # Multi-word string. - $param = substr($param, 1); - - for (my $i = 2; $i < scalar(@ebuf); $i++) { - if (substr($ebuf[$i], length($ebuf[$i]) - 1, 1) eq '"') { - $param .= " ".substr($ebuf[$i], 0, length($ebuf[$i]) - 1); - last; - } - else { - $param .= " ".$ebuf[$i]; - } - } - } - elsif (substr($param, 0, 1) eq '"' and substr($param, length($param) - 1, 1) eq '"') { - # Single-word string. - $param = substr($param, 1, length($ebuf[1]) - 2); - } - elsif ($param =~ m/[0-9]/) { - # Numeric. - $param =~ s/[^0-9.]//g; - } - else { - # Garbage. - next; - } - - my @param = ($param); - - unless (!$blk) { - # We're inside a block. - if ($blk =~ m/@@@/) { - # We're inside a block with a parameter. - my @sblk = split('@@@', $blk); - - # Check to see if this config option already exists. - if (defined $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]}) { - # It does, so merely push this second one to the existing array. - push(@{ $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]} }, $param); - } - else { - # It doesn't, create it as an array. - @{ $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]} } = @param; - } - } - else { - # We're inside a block with no parameter. - - # Check to see if this config option already exists. - if (defined $rs{$blk}{$ebuf[0]}) { - # It does, so merely push this second one to the existing array. + # Get the path to the file. + my $self = shift; + my $file = $self->{'config'}->{'path'}; + my $blk = 0; + my (%rs); + + # Open, read and close it. + open(my $FCONF, q{<}, "$file") or return 0; + my @fbuf = <$FCONF> or return 0; + close $FCONF or return 0; + + # Iterate the file. + foreach my $buff (@fbuf) { + # Main newline buffer. + if (defined $buff) { + # If the line begins with a #, it's a comment so ignore it. + if (substr($buff, 0, 1) eq '#') { + next; + } + + if ($buff =~ m/;/) { + # Semicolon buffer. + my @asbuf = split(';', $buff); + foreach my $asbuff (@asbuf) { + if (defined $asbuff) { + + # Space buffer. + my @ebuf = split(' ', $asbuff); + if (!defined $ebuf[0] or !defined $ebuf[1]) { + # Garbage. Ignoring. + next; + } + my $param = $ebuf[1]; + + if (substr($param, 0, 1) eq '"' and substr($param, length($param) - 1, 1) ne '"') { + # Multi-word string. + $param = substr($param, 1); + + for (my $i = 2; $i < scalar(@ebuf); $i++) { + if (substr($ebuf[$i], length($ebuf[$i]) - 1, 1) eq '"') { + $param .= " ".substr($ebuf[$i], 0, length($ebuf[$i]) - 1); + last; + } + else { + $param .= " ".$ebuf[$i]; + } + } + } + elsif (substr($param, 0, 1) eq '"' and substr($param, length($param) - 1, 1) eq '"') { + # Single-word string. + $param = substr($param, 1, length($ebuf[1]) - 2); + } + elsif ($param =~ m/[0-9]/) { + # Numeric. + $param =~ s/[^0-9.]//g; + } + else { + # Garbage. + next; + } + + my @param = ($param); + + unless (!$blk) { + # We're inside a block. + if ($blk =~ m/@@@/) { + # We're inside a block with a parameter. + my @sblk = split('@@@', $blk); + + # Check to see if this config option already exists. + if (defined $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]}) { + # It does, so merely push this second one to the existing array. + push(@{ $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]} }, $param); + } + else { + # It doesn't, create it as an array. + @{ $rs{$sblk[0]}{$sblk[1]}{$ebuf[0]} } = @param; + } + } + else { + # We're inside a block with no parameter. + + # Check to see if this config option already exists. + if (defined $rs{$blk}{$ebuf[0]}) { + # It does, so merely push this second one to the existing array. push(@{ $rs{$blk}{$ebuf[0]} }, $param); - } - else { - # It doesn't, create it as an array. - @{ $rs{$blk}{$ebuf[0]} } = @param; - } - } - } - else { - # We're not inside a block. - - # Check to see if this config option already exists. - if (defined $rs{$ebuf[0]}) { - # It does, so merely push this second one to the existing array. - push(@{ $rs{$ebuf[0]} }, $param); - } - else { - # It doesn't, create it as an array. - @{ $rs{$ebuf[0]} } = @param; - } - } - } - } - } - else { - # No semicolon space buffer. - my @ebuf = split(' ', $buff); - - if (!defined $ebuf[0]) { - # Garbage. Ignoring. - next; - } - - if (defined $ebuf[1]) { - if ($ebuf[1] eq '{') { - # This is the beginning of a block with no parameter. + } + else { + # It doesn't, create it as an array. + @{ $rs{$blk}{$ebuf[0]} } = @param; + } + } + } + else { + # We're not inside a block. + + # Check to see if this config option already exists. + if (defined $rs{$ebuf[0]}) { + # It does, so merely push this second one to the existing array. + push(@{ $rs{$ebuf[0]} }, $param); + } + else { + # It doesn't, create it as an array. + @{ $rs{$ebuf[0]} } = @param; + } + } + } + } + } + else { + # No semicolon space buffer. + my @ebuf = split(' ', $buff); + + if (!defined $ebuf[0]) { + # Garbage. Ignoring. + next; + } + + if (defined $ebuf[1]) { + if ($ebuf[1] eq '{') { + # This is the beginning of a block with no parameter. $blk = $ebuf[0]; - } - elsif (defined $ebuf[2]) { - if ($ebuf[2] eq '{') { - # This is the beginning of a block with a parameter. - my $param = $ebuf[1]; - $param =~ s/"//g; - $blk = $ebuf[0].'@@@'.$param; - } - } - } - if ($ebuf[0] eq '}') { - # This is the end of a block. - $blk = 0; - } - } - } - } - - # Return the configuration data. - return %rs; + } + elsif (defined $ebuf[2]) { + if ($ebuf[2] eq '{') { + # This is the beginning of a block with a parameter. + my $param = $ebuf[1]; + $param =~ s/"//g; + $blk = $ebuf[0].'@@@'.$param; + } + } + } + if ($ebuf[0] eq '}') { + # This is the end of a block. + $blk = 0; + } + } + } + } + + # Return the configuration data. + return %rs; } diff --git a/lib/Parser/IRC.pm b/lib/Parser/IRC.pm index 5bf1902..f0fc6ec 100644 --- a/lib/Parser/IRC.pm +++ b/lib/Parser/IRC.pm @@ -9,26 +9,26 @@ use API::IRC; # Raw parsing hash. our %RAWC = ( - '001' => \&num001, - '005' => \&num005, - '353' => \&num353, - '432' => \&num432, - '433' => \&num433, - '438' => \&num438, - '465' => \&num465, - '471' => \&num471, - '473' => \&num473, - '474' => \&num474, - '475' => \&num475, - '477' => \&num477, - 'JOIN' => \&cjoin, + '001' => \&num001, + '005' => \&num005, + '353' => \&num353, + '432' => \&num432, + '433' => \&num433, + '438' => \&num438, + '465' => \&num465, + '471' => \&num471, + '473' => \&num473, + '474' => \&num474, + '475' => \&num475, + '477' => \&num477, + 'JOIN' => \&cjoin, 'KICK' => \&kick, 'MODE' => \&mode, - 'NICK' => \&nick, - 'NOTICE' => \¬ice, + 'NICK' => \&nick, + 'NOTICE' => \¬ice, 'PART' => \&part, - 'PRIVMSG' => \&privmsg, - 'QUIT' => \&quit, + 'PRIVMSG' => \&privmsg, + 'QUIT' => \&quit, 'TOPIC' => \&topic, ); @@ -50,33 +50,33 @@ API::Std::event_add("on_topic"); # Parse raw data. sub ircparse { - my ($svr, $data) = @_; - - # Split spaces into @ex. - my @ex = split /\s+/, $data; + my ($svr, $data) = @_; + + # Split spaces into @ex. + my @ex = split /\s+/, $data; - # Make sure there is enough data. - if (defined $ex[0] and defined $ex[1]) { - # If it's a ping... - if ($ex[0] eq 'PING') { - # send a PONG. - Auto::socksnd($svr, "PONG ".$ex[1]); - } - # If it's AUTHENTICATE - elsif ($ex[0] eq 'AUTHENTICATE') { - if (API::Std::mod_exists("SASLAuth")) { + # Make sure there is enough data. + if (defined $ex[0] and defined $ex[1]) { + # If it's a ping... + if ($ex[0] eq 'PING') { + # send a PONG. + Auto::socksnd($svr, "PONG ".$ex[1]); + } + # If it's AUTHENTICATE + elsif ($ex[0] eq 'AUTHENTICATE') { + if (API::Std::mod_exists("SASLAuth")) { M::SASLAuth::handle_authenticate($svr, @ex); - } - } - else { - # otherwise, check %RAWC for ex[1]. - if (defined $RAWC{$ex[1]}) { - &{ $RAWC{$ex[1]} }($svr, @ex); - } - } - } - - return 1; + } + } + else { + # otherwise, check %RAWC for ex[1]. + if (defined $RAWC{$ex[1]}) { + &{ $RAWC{$ex[1]} }($svr, @ex); + } + } + } + + return 1; } ########################### @@ -87,41 +87,41 @@ sub ircparse # Successful connection. sub num001 { - my ($svr, @ex) = @_; - - $got_001{$svr} = 1; - - # In case we don't get NICK from the server. - if (defined $botnick{$svr}{newnick}) { - $botnick{$svr}{nick} = $botnick{$svr}{newnick}; - delete $botnick{$svr}{newnick}; - } + my ($svr, @ex) = @_; + + $got_001{$svr} = 1; + + # In case we don't get NICK from the server. + if (defined $botnick{$svr}{newnick}) { + $botnick{$svr}{nick} = $botnick{$svr}{newnick}; + delete $botnick{$svr}{newnick}; + } # Trigger on_connect. API::Std::event_run("on_connect", $svr); - - return 1; + + return 1; } # Parse: Numeric:005 # Prefixes and channel modes. sub num005 { - my ($svr, @ex) = @_; - - # Find PREFIX and CHANMODES. - foreach my $ex (@ex) { - if ($ex =~ m/^PREFIX/xsm) { - # Found PREFIX. - my $rpx = substr($ex, 8); - my ($pm, $pp) = split('\)', $rpx); - my @apm = split(//, $pm); - my @app = split(//, $pp); - foreach my $ppm (@apm) { - # Store data. - $csprefix{$svr}{$ppm} = shift(@app); - } - } + my ($svr, @ex) = @_; + + # Find PREFIX and CHANMODES. + foreach my $ex (@ex) { + if ($ex =~ m/^PREFIX/xsm) { + # Found PREFIX. + my $rpx = substr($ex, 8); + my ($pm, $pp) = split('\)', $rpx); + my @apm = split(//, $pm); + my @app = split(//, $pp); + foreach my $ppm (@apm) { + # Store data. + $csprefix{$svr}{$ppm} = shift(@app); + } + } elsif ($ex =~ m/^CHANMODES/xsm) { # Found CHANMODES. my ($mtl, $mtp, $mtpp, $mts) = split m/[,]/xsm, substr($ex, 10); @@ -134,186 +134,186 @@ sub num005 # Modes without parameter. foreach (split(//, $mts)) { $chanmodes{$svr}{$_} = 4; } } - } - - return 1; + } + + return 1; } # Parse: Numeric:353 # NAMES reply. sub num353 { - my ($svr, @ex) = @_; - - # Get rid of the colon. - $ex[5] = substr($ex[5], 1); - # Delete the old chanusers hash if it exists. - delete $chanusers{$svr}{$ex[4]} if (defined $chanusers{$svr}{$ex[4]}); - # Iterate through each user. - for (my $i = 5; $i < scalar(@ex); $i++) { - my $fi = 0; - foreach (keys %{ $csprefix{$svr} }) { - # Check if the user has status in the channel. - if (substr($ex[$i], 0, 1) eq $csprefix{$svr}{$_}) { - # He/she does. Lets set that. - if (defined $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))}) { - # If the user has multiple statuses. - $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))} .= $_; - } - else { - # Or not. - $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))} = $_; - } - $fi = 1; - } - } - # They had status, so go to the next user. - next if $fi; - # They didn't, set them as a normal user. - if (!defined $chanusers{$svr}{$ex[4]}{lc($ex[$i])}) { - $chanusers{$svr}{$ex[4]}{lc($ex[$i])} = 1; - } - } - - return 1; + my ($svr, @ex) = @_; + + # Get rid of the colon. + $ex[5] = substr($ex[5], 1); + # Delete the old chanusers hash if it exists. + delete $chanusers{$svr}{$ex[4]} if (defined $chanusers{$svr}{$ex[4]}); + # Iterate through each user. + for (my $i = 5; $i < scalar(@ex); $i++) { + my $fi = 0; + foreach (keys %{ $csprefix{$svr} }) { + # Check if the user has status in the channel. + if (substr($ex[$i], 0, 1) eq $csprefix{$svr}{$_}) { + # He/she does. Lets set that. + if (defined $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))}) { + # If the user has multiple statuses. + $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))} .= $_; + } + else { + # Or not. + $chanusers{$svr}{$ex[4]}{lc(substr($ex[$i], 1))} = $_; + } + $fi = 1; + } + } + # They had status, so go to the next user. + next if $fi; + # They didn't, set them as a normal user. + if (!defined $chanusers{$svr}{$ex[4]}{lc($ex[$i])}) { + $chanusers{$svr}{$ex[4]}{lc($ex[$i])} = 1; + } + } + + return 1; } # Parse: Numeric:432 # Erroneous nickname. sub num432 { - my ($svr, undef) = @_; - - if ($got_001{$svr}) { - err(3, "Got error from server[".$svr."]: Erroneous nickname.", 0); - } - else { - err(2, "Got error from server[".$svr."] before 001: Erroneous nickname. Closing connection.", 0); - API::IRC::quit($svr, "An error occurred."); - } - - delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); - - return 1; + my ($svr, undef) = @_; + + if ($got_001{$svr}) { + err(3, "Got error from server[".$svr."]: Erroneous nickname.", 0); + } + else { + err(2, "Got error from server[".$svr."] before 001: Erroneous nickname. Closing connection.", 0); + API::IRC::quit($svr, "An error occurred."); + } + + delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); + + return 1; } # Parse: Numeric:433 # Nickname is already in use. sub num433 { - my ($svr, undef) = @_; - - if (defined $botnick{$svr}{newnick}) { - API::IRC::nick($svr, $botnick{$svr}{newnick}."_"); - delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); - } - - return 1; + my ($svr, undef) = @_; + + if (defined $botnick{$svr}{newnick}) { + API::IRC::nick($svr, $botnick{$svr}{newnick}."_"); + delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); + } + + return 1; } # Parse: Numeric:438 # Nick change too fast. sub num438 { - my ($svr, @ex) = @_; - - if (defined $botnick{$svr}{newnick}) { - API::Std::timer_add("num438_".$botnick{$svr}{newnick}, 1, $ex[11], sub { - API::IRC::nick($Parser::IRC::botnick{$svr}{newnick}); - delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); - }); - } - - return 1; + my ($svr, @ex) = @_; + + if (defined $botnick{$svr}{newnick}) { + API::Std::timer_add("num438_".$botnick{$svr}{newnick}, 1, $ex[11], sub { + API::IRC::nick($Parser::IRC::botnick{$svr}{newnick}); + delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); + }); + } + + return 1; } # Parse: Numeric:465 # You're banned creep! sub num465 { - my ($svr, undef) = @_; - - err(3, "Banned from ".$svr."! Closing link...", 0); - - return 1; + my ($svr, undef) = @_; + + err(3, "Banned from ".$svr."! Closing link...", 0); + + return 1; } # Parse: Numeric:471 # Cannot join channel: Channel is full. sub num471 { - my ($svr, (undef, undef, undef, $chan)) = @_; - - err(3, "Cannot join channel ".$chan." on ".$svr.": Channel is full.", 0); - - return 1; + my ($svr, (undef, undef, undef, $chan)) = @_; + + err(3, "Cannot join channel ".$chan." on ".$svr.": Channel is full.", 0); + + return 1; } # Parse: Numeric:473 # Cannot join channel: Channel is invite-only. sub num473 { - my ($svr, (undef, undef, undef, $chan)) = @_; - - err(3, "Cannot join channel ".$chan." on ".$svr.": Channel is invite-only.", 0); - - return 1; + my ($svr, (undef, undef, undef, $chan)) = @_; + + err(3, "Cannot join channel ".$chan." on ".$svr.": Channel is invite-only.", 0); + + return 1; } # Parse: Numeric:474 # Cannot join channel: Banned from channel. sub num474 { - my ($svr, (undef, undef, undef, $chan)) = @_; - - err(3, "Cannot join channel ".$chan." on ".$svr.": Banned from channel.", 0); - - return 1; + my ($svr, (undef, undef, undef, $chan)) = @_; + + err(3, "Cannot join channel ".$chan." on ".$svr.": Banned from channel.", 0); + + return 1; } # Parse: Numeric:475 # Cannot join channel: Bad key. sub num475 { - my ($svr, (undef, undef, undef, $chan)) = @_; - - err(3, "Cannot join channel ".$chan." on ".$svr.": Bad key.", 0); - - return 1; + my ($svr, (undef, undef, undef, $chan)) = @_; + + err(3, "Cannot join channel ".$chan." on ".$svr.": Bad key.", 0); + + return 1; } # Parse: Numeric:477 # Cannot join channel: Need registered nickname. sub num477 { - my ($svr, (undef, undef, undef, $chan)) = @_; - - err(3, "Cannot join channel ".$chan." on ".$svr.": Need registered nickname.", 0); - - return 1; + my ($svr, (undef, undef, undef, $chan)) = @_; + + err(3, "Cannot join channel ".$chan." on ".$svr.": Need registered nickname.", 0); + + return 1; } # Parse: JOIN sub cjoin { - my ($svr, @ex) = @_; - my %src = API::IRC::usrc(substr($ex[0], 1)); + my ($svr, @ex) = @_; + my %src = API::IRC::usrc(substr($ex[0], 1)); my $chan = $ex[2]; $chan =~ s/^://gxsm; - - # Check if this is coming from ourselves. - if ($src{nick} eq $botnick{$svr}{nick}) { - $botchans{$svr}{lc $chan} = 1; - API::Std::event_run("on_ucjoin", ($svr, $chan)); - } - else { - # It isn't. Update chanusers and trigger on_rcjoin. + + # Check if this is coming from ourselves. + if ($src{nick} eq $botnick{$svr}{nick}) { + $botchans{$svr}{lc $chan} = 1; + API::Std::event_run("on_ucjoin", ($svr, $chan)); + } + else { + # It isn't. Update chanusers and trigger on_rcjoin. $chanusers{$svr}{lc $chan}{$src{nick}} = 1; $src{svr} = $svr; - API::Std::event_run("on_rcjoin", (\%src, $chan)); - } - - return 1; + API::Std::event_run("on_rcjoin", (\%src, $chan)); + } + + return 1; } # Parse: KICK @@ -454,35 +454,35 @@ sub mode # Parse: NICK sub nick { - my ($svr, ($uex, undef, $nex)) = @_; + my ($svr, ($uex, undef, $nex)) = @_; $nex = substr($nex, 1); - my %src = API::IRC::usrc(substr($uex, 1)); - - # Check if this is coming from ourselves. - if ($src{nick} eq $botnick{$svr}{nick}) { - # It is. Update bot nick hash. - $botnick{$svr}{nick} = $nex; - delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); - } - else { - # It isn't. Update chanusers and trigger on_nick. + my %src = API::IRC::usrc(substr($uex, 1)); + + # Check if this is coming from ourselves. + if ($src{nick} eq $botnick{$svr}{nick}) { + # It is. Update bot nick hash. + $botnick{$svr}{nick} = $nex; + delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); + } + else { + # It isn't. Update chanusers and trigger on_nick. foreach my $chk (keys %{ $chanusers{$svr} }) { if (defined $chanusers{$svr}{$chk}{$src{nick}}) { $chanusers{$svr}{$chk}{$nex} = $chanusers{$svr}{$chk}{$src{nick}}; delete $chanusers{$svr}{$chk}{$src{nick}}; } } - API::Std::event_run("on_nick", ($svr, \%src, $nex)); - } - - return 1; + API::Std::event_run("on_nick", ($svr, \%src, $nex)); + } + + return 1; } # Parse: NOTICE sub notice { - my ($svr, @ex) = @_; + my ($svr, @ex) = @_; # Ensure this is coming from a user rather than a server. if ($ex[0] !~ m/!/xsm) { return; } @@ -493,11 +493,11 @@ sub notice shift @ex; shift @ex; shift @ex; $ex[0] = substr $ex[0], 1; $src{svr} = $svr; - + # Send it off. - API::Std::event_run("on_notice", (\%src, $target, @ex)); - - return 1; + API::Std::event_run("on_notice", (\%src, $target, @ex)); + + return 1; } # Parse: PART @@ -529,33 +529,33 @@ sub part # Parse: PRIVMSG sub privmsg { - my ($svr, @ex) = @_; + my ($svr, @ex) = @_; my %data = API::IRC::usrc(substr($ex[0], 1)); # Ensure this is coming from a user rather than a server. if ($ex[0] !~ m/!/xsm) { return; } my @argv; - for (my $i = 4; $i < scalar(@ex); $i++) { - push(@argv, $ex[$i]); - } - $data{svr} = $svr; - - my ($cmd, $cprefix, $rprefix); - # 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. + for (my $i = 4; $i < scalar(@ex); $i++) { + push(@argv, $ex[$i]); + } + $data{svr} = $svr; + + my ($cmd, $cprefix, $rprefix); + # 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. # Ensure it's a valid length. if (length($ex[3]) > 1) { - $cmd = uc(substr($ex[3], 1)); - if (defined $API::Std::CMDS{$cmd}) { + $cmd = uc(substr($ex[3], 1)); + if (defined $API::Std::CMDS{$cmd}) { # If this is indeed a command, continue. - if ($API::Std::CMDS{$cmd}{lvl} == 1 or $API::Std::CMDS{$cmd}{lvl} == 2) { + if ($API::Std::CMDS{$cmd}{lvl} == 1 or $API::Std::CMDS{$cmd}{lvl} == 2) { # Ensure the level is private or all. if (API::Std::ratelimit_check(%data)) { # Continue if the user has not passed the ratelimit amount. - if ($API::Std::CMDS{$cmd}{priv}) { + if ($API::Std::CMDS{$cmd}{priv}) { # If this command requires a privilege... if (API::Std::has_priv(API::Std::match_user(%data), $API::Std::CMDS{$cmd}{priv})) { # Make sure they have it. @@ -575,26 +575,26 @@ sub privmsg # Send them a notice about their bad deed. API::IRC::notice($data{svr}, $data{nick}, trans('Rate limit exceeded').q{.}); } - } - } + } + } } - # Trigger event on_uprivmsg. + # Trigger event on_uprivmsg. shift @ex; shift @ex; shift @ex; $ex[0] = substr $ex[0], 1; - API::Std::event_run("on_uprivmsg", (\%data, @ex)); - } - else { - # It is coming to us in a channel message. - $data{chan} = $ex[2]; + API::Std::event_run("on_uprivmsg", (\%data, @ex)); + } + else { + # It is coming to us in a channel message. + $data{chan} = $ex[2]; # Ensure it's a valid length before continuing. - if (length($ex[3]) > 1) { + if (length($ex[3]) > 1) { $cprefix = (conf_get("fantasy_pf"))[0][0]; - $rprefix = substr($ex[3], 1, 1); - $cmd = uc(substr($ex[3], 2)); - if (defined $API::Std::CMDS{$cmd} and $rprefix eq $cprefix) { + $rprefix = substr($ex[3], 1, 1); + $cmd = uc(substr($ex[3], 2)); + if (defined $API::Std::CMDS{$cmd} and $rprefix eq $cprefix) { # If this is indeed a command, continue. - if ($API::Std::CMDS{$cmd}{lvl} == 0 or $API::Std::CMDS{$cmd}{lvl} == 2) { + if ($API::Std::CMDS{$cmd}{lvl} == 0 or $API::Std::CMDS{$cmd}{lvl} == 2) { # Ensure the level is public or all. if (API::Std::ratelimit_check(%data)) { # Continue if the user has not passed the ratelimit amount. @@ -641,24 +641,24 @@ sub privmsg } } } - } + } } - # Trigger event on_cprivmsg. + # Trigger event on_cprivmsg. my $target = $ex[2]; delete $data{chan}; shift @ex; shift @ex; shift @ex; $ex[0] = substr $ex[0], 1; - API::Std::event_run("on_cprivmsg", (\%data, $target, @ex)); - } - - return 1; + API::Std::event_run("on_cprivmsg", (\%data, $target, @ex)); + } + + return 1; } # Parse: QUIT sub quit { my ($svr, @ex) = @_; - my %src = API::IRC::usrc(substr($ex[0], 1)); + my %src = API::IRC::usrc(substr($ex[0], 1)); # Set $msg to the quit message. my $msg = 0; @@ -680,23 +680,23 @@ sub quit # Parse: TOPIC sub topic { - my ($svr, @ex) = @_; - my %src = API::IRC::usrc(substr($ex[0], 1)); - - # Ignore it if it's coming from us. - if (lc($src{nick}) ne lc($botnick{$svr}{nick})) { - $src{chan} = $ex[2]; - my (@argv); - $argv[0] = substr($ex[3], 1); - if (defined $ex[4]) { - for (my $i = 4; $i < scalar(@ex); $i++) { - push(@argv, $ex[$i]); - } - } - API::Std::event_run("on_topic", ($svr, \%src, @argv)); - } - - return 1; + my ($svr, @ex) = @_; + my %src = API::IRC::usrc(substr($ex[0], 1)); + + # Ignore it if it's coming from us. + if (lc($src{nick}) ne lc($botnick{$svr}{nick})) { + $src{chan} = $ex[2]; + my (@argv); + $argv[0] = substr($ex[3], 1); + if (defined $ex[4]) { + for (my $i = 4; $i < scalar(@ex); $i++) { + push(@argv, $ex[$i]); + } + } + API::Std::event_run("on_topic", ($svr, \%src, @argv)); + } + + return 1; } diff --git a/lib/Parser/Lang.pm b/lib/Parser/Lang.pm index a31b21c..0494df0 100644 --- a/lib/Parser/Lang.pm +++ b/lib/Parser/Lang.pm @@ -10,56 +10,56 @@ use API::Log qw(dbug alog); # Parser. sub parse { - my ($lang) = @_; - - # Check that the language file exists. - unless (-e "$Auto::Bin/../lang/$lang.alf") { - # Otherwise, use English. - dbug "Language '$lang' not found. Using English."; - alog "Language '$lang' not found. Using English."; - $lang = "en"; - } - - # Open, read and close the file. - open(my $FALF, q{<}, "$Auto::Bin/../lang/$lang.alf") or return 0; - my @fbuf = <$FALF>; - close $FALF; - - # Iterate the file buffer. - foreach my $buff (@fbuf) { - if (defined $buff) { - # Space buffer. - my @sbuf = split(' ', $buff); - - # Check for all required values. - if (!defined $sbuf[0] or !defined $sbuf[1] or !defined $sbuf[2]) { - # Missing a value. - next; - } - - # Make sure the first value is "msge". - if ($sbuf[0] ne "msge") { - # It isn't. - next; - } - - my $id = $sbuf[1]; - my $val = $sbuf[2]; - - # If the translation is multi-word, continue to parse. - if (defined $sbuf[3]) { - for (my $i = 3; $i < scalar(@sbuf); $i++) { - $val .= " ".$sbuf[$i]; - } - } - - # Save to memory. - $id =~ s/"//g; - $val =~ s/"//g; - $API::Std::LANGE{$id} = $val; - } - } - return 1; + my ($lang) = @_; + + # Check that the language file exists. + unless (-e "$Auto::Bin/../lang/$lang.alf") { + # Otherwise, use English. + dbug "Language '$lang' not found. Using English."; + alog "Language '$lang' not found. Using English."; + $lang = "en"; + } + + # Open, read and close the file. + open(my $FALF, q{<}, "$Auto::Bin/../lang/$lang.alf") or return 0; + my @fbuf = <$FALF>; + close $FALF; + + # Iterate the file buffer. + foreach my $buff (@fbuf) { + if (defined $buff) { + # Space buffer. + my @sbuf = split(' ', $buff); + + # Check for all required values. + if (!defined $sbuf[0] or !defined $sbuf[1] or !defined $sbuf[2]) { + # Missing a value. + next; + } + + # Make sure the first value is "msge". + if ($sbuf[0] ne "msge") { + # It isn't. + next; + } + + my $id = $sbuf[1]; + my $val = $sbuf[2]; + + # If the translation is multi-word, continue to parse. + if (defined $sbuf[3]) { + for (my $i = 3; $i < scalar(@sbuf); $i++) { + $val .= " ".$sbuf[$i]; + } + } + + # Save to memory. + $id =~ s/"//g; + $val =~ s/"//g; + $API::Std::LANGE{$id} = $val; + } + } + return 1; } diff --git a/modules/Badwords.pm b/modules/Badwords.pm index 34134f7..1757679 100644 --- a/modules/Badwords.pm +++ b/modules/Badwords.pm @@ -12,12 +12,12 @@ use API::IRC qw(privmsg notice kick ban); sub _init { # Check for required configuration values. - if (!conf_get('badwords')) { - err(2, 'Please verify that you have a badwords block with word entries defined in your configuration file.', 0); - return; - } + if (!conf_get('badwords')) { + err(2, 'Please verify that you have a badwords block with word entries defined in your configuration file.', 0); + return; + } # Create the act_on_badword hook. - hook_add('on_cprivmsg', 'act_on_badword', \&M::Badwords::actonbadword) or return; + hook_add('on_cprivmsg', 'act_on_badword', \&M::Badwords::actonbadword) or return; # Success. return 1; @@ -27,16 +27,16 @@ sub _init sub _void { # Delete the act_on_badword hook. - hook_del('act_on_badword') or return 0; + hook_del('act_on_badword') or return 0; # Success. - return 1; + return 1; } # Callback for act_on_badword hook. sub actonbadword { - my (($src, $chan, @msg)) = @_; + my (($src, $chan, @msg)) = @_; my $msg = join ' ', @msg; diff --git a/modules/Bitly.pm b/modules/Bitly.pm index 4c160fe..1dfc4b6 100644 --- a/modules/Bitly.pm +++ b/modules/Bitly.pm @@ -13,13 +13,13 @@ use URI::Escape; sub _init { # Check for required configuration values. - if (!(conf_get('bitly:user'))[0][0] or !(conf_get('bitly:key'))[0][0]) { - err(2, "Please verify that you have bitly_user and bitly_key defined in your configuration file.", 0); - return 0; - } + if (!(conf_get('bitly:user'))[0][0] or !(conf_get('bitly:key'))[0][0]) { + err(2, "Please verify that you have bitly_user and bitly_key defined in your configuration file.", 0); + return 0; + } # Create the SHORTEN and REVERSE commands. - cmd_add("SHORTEN", 0, 0, \%M::Bitly::HELP_SHORTEN, \&M::Bitly::shorten) or return 0; - cmd_add("REVERSE", 0, 0, \%M::Bitly::HELP_REVERSE, \&M::Bitly::reverse) or return 0; + cmd_add("SHORTEN", 0, 0, \%M::Bitly::HELP_SHORTEN, \&M::Bitly::shorten) or return 0; + cmd_add("REVERSE", 0, 0, \%M::Bitly::HELP_REVERSE, \&M::Bitly::reverse) or return 0; # Success. return 1; @@ -29,11 +29,11 @@ sub _init sub _void { # Delete the SHORTEN and REVERSE commands. - cmd_del("SHORTEN") or return 0; - cmd_del("REVERSE") or return 0; + cmd_del("SHORTEN") or return 0; + cmd_del("REVERSE") or return 0; # Success. - return 1; + return 1; } # Help hashes. @@ -47,37 +47,37 @@ our %HELP_REVERSE = ( # Callback for SHORTEN command. sub shorten { - my ($src, @args) = @_; + my ($src, @args) = @_; # Create an instance of LWP::UserAgent. - my $ua = LWP::UserAgent->new(); - $ua->agent('Auto IRC Bot'); - $ua->timeout(2); + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); # Put together the call to the Bit.ly API. if (!defined $args[0]) { notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); return 0; } - my ($surl, $user, $key) = ($args[0], (conf_get('bitly:user'))[0][0], (conf_get('bitly:key'))[0][0]); + my ($surl, $user, $key) = ($args[0], (conf_get('bitly:user'))[0][0], (conf_get('bitly:key'))[0][0]); $surl = uri_escape($surl); - my $url = "http://api.bit.ly/v3/shorten?version=3.0.1&longUrl=".$surl."&apiKey=".$key."&login=".$user."&format=txt"; + my $url = "http://api.bit.ly/v3/shorten?version=3.0.1&longUrl=".$surl."&apiKey=".$key."&login=".$user."&format=txt"; # Get the response via HTTP. my $response = $ua->get($url); - if ($response->is_success) { + if ($response->is_success) { # If successful, decode the content. my $d = $response->decoded_content; - chomp $d; + chomp $d; # And send to channel. - privmsg($src->{svr}, $src->{chan}, "URL: ".$d); - } + privmsg($src->{svr}, $src->{chan}, "URL: ".$d); + } else { # Otherwise, send an error message. privmsg($src->{svr}, $src->{chan}, "An error occurred while shortening your URL."); } - return 1; + return 1; } # Callback for REVERSE command. @@ -104,16 +104,16 @@ sub reverse if ($response->is_success) { # If successful, decode the content. my $d = $response->decoded_content; - chomp $d; + chomp $d; # And send it to channel. - privmsg($src->{svr}, $src->{chan}, "URL: ".$d); - } - else { + privmsg($src->{svr}, $src->{chan}, "URL: ".$d); + } + else { # Otherwise, send an error message. - privmsg($src->{svr}, $src->{chan}, "An error occurred while reversing your URL."); - } + privmsg($src->{svr}, $src->{chan}, "An error occurred while reversing your URL."); + } - return 1; + return 1; } diff --git a/modules/Calc.pm b/modules/Calc.pm index f9247dc..19916a7 100644 --- a/modules/Calc.pm +++ b/modules/Calc.pm @@ -13,68 +13,68 @@ use JSON -support_by_pp; # Initialization subroutine. sub _init { - # Create the CALC command. - cmd_add("CALC", 0, 0, \%M::Calc::HELP_CALC, \&M::Calc::calc) or return 0; + # Create the CALC command. + cmd_add("CALC", 0, 0, \%M::Calc::HELP_CALC, \&M::Calc::calc) or return 0; - # Success. - return 1; + # Success. + return 1; } # Void subroutine. sub _void { - # Delete the CALC command. - cmd_del("CALC") or return 0; + # Delete the CALC command. + cmd_del("CALC") or return 0; - # Success. - return 1; + # Success. + return 1; } # Help hash. our %FHELP_CALC = ( - 'en' => "This command will calculate an expression using Google Calculator. \002Syntax:\002 CALC ", + 'en' => "This command will calculate an expression using Google Calculator. \002Syntax:\002 CALC ", ); # Callback for CALC command. sub calc { - my ($src, @args) = @_; + my ($src, @args) = @_; - # Create an instance of LWP::UserAgent. - my $ua = LWP::UserAgent->new(); - $ua->agent('Auto IRC Bot'); - $ua->timeout(2); - # Create an instance of JSON. - my $json = JSON->new(); - # Put together the call to the Google Calculator API. + # Create an instance of LWP::UserAgent. + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); + # Create an instance of JSON. + my $json = JSON->new(); + # Put together the call to the Google Calculator API. if (!defined $args[0]) { notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); return 0; } my $expr = join(' ', @args); - my $url = "http://www.google.com/ig/calculator?q=".uri_escape($expr); - # Get the response via HTTP. - my $response = $ua->get($url); + my $url = "http://www.google.com/ig/calculator?q=".uri_escape($expr); + # Get the response via HTTP. + my $response = $ua->get($url); - if ($response->is_success) { - # If successful, decode the content. - my $d = $json->allow_nonref->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($response->decoded_content); + if ($response->is_success) { + # If successful, decode the content. + my $d = $json->allow_nonref->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($response->decoded_content); - if ($d->{error} eq "" or $d->{error} == 0) { - # And send to channel + if ($d->{error} eq "" or $d->{error} == 0) { + # And send to channel privmsg($src->{svr}, $src->{chan}, "Result: ".$d->{lhs}." = ".$d->{rhs}); - } - else { - # Otherwise, send an error message. - privmsg($src->{svr}, $src->{chan}, "Google Calculator sent an error."); - } - } - else { - # Otherwise, send an error message. - privmsg($src->{svr}, $src->{chan}, "An error occurred while sending your expression to Google Calculator."); - } + } + else { + # Otherwise, send an error message. + privmsg($src->{svr}, $src->{chan}, "Google Calculator sent an error."); + } + } + else { + # Otherwise, send an error message. + privmsg($src->{svr}, $src->{chan}, "An error occurred while sending your expression to Google Calculator."); + } - return 1; + return 1; } # Start initialization. diff --git a/modules/EightBall.pm b/modules/EightBall.pm index eaaf8f1..a045307 100644 --- a/modules/EightBall.pm +++ b/modules/EightBall.pm @@ -13,8 +13,8 @@ our $ANSWER = 0; sub _init { # Create the 8BALL and RIGBALL commands. - cmd_add('8BALL', 0, 0, \%M::EightBall::HELP_8BALL, \&M::EightBall::c_8ball) or return 0; - cmd_add('RIGBALL', 1, 'cmd.rigball', \%M::EightBall::HELP_RIGBALL, \&M::EightBall::rigball) or return 0; + cmd_add('8BALL', 0, 0, \%M::EightBall::HELP_8BALL, \&M::EightBall::c_8ball) or return 0; + cmd_add('RIGBALL', 1, 'cmd.rigball', \%M::EightBall::HELP_RIGBALL, \&M::EightBall::rigball) or return 0; # Success. return 1; @@ -24,11 +24,11 @@ sub _init sub _void { # Delete the 8BALL and RIGBALL commands. - cmd_del('8BALL') or return 0; - cmd_del('RIGBALL') or return 0; + cmd_del('8BALL') or return 0; + cmd_del('RIGBALL') or return 0; # Success. - return 1; + return 1; } # Help hashes. @@ -42,7 +42,7 @@ our %HELP_RIGBALL = ( # Callback for 8BALL command. sub c_8ball { - my ($src, @argv) = @_; + my ($src, @argv) = @_; if (!defined $argv[0]) { notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); @@ -77,7 +77,7 @@ sub c_8ball privmsg($src->{svr}, $src->{chan}, "\002Answer:\002 ".$a); - return 1; + return 1; } # Callback for RIGBALL command. @@ -94,7 +94,7 @@ sub rigball $ANSWER = join(" ", @argv); privmsg($src->{svr}, $src->{nick}, "Answer set to: ".$ANSWER); - return 1; + return 1; } diff --git a/modules/FML.pm b/modules/FML.pm index 0131984..260f817 100644 --- a/modules/FML.pm +++ b/modules/FML.pm @@ -12,7 +12,7 @@ use LWP::UserAgent; sub _init { # Create the FML command. - cmd_add('FML', 0, 0, \%M::FML::HELP_FML, \&M::FML::fml) or return 0; + cmd_add('FML', 0, 0, \%M::FML::HELP_FML, \&M::FML::fml) or return 0; # Success. return 1; @@ -22,10 +22,10 @@ sub _init sub _void { # Delete the FML command. - cmd_del('FML') or return 0; + cmd_del('FML') or return 0; # Success. - return 1; + return 1; } # Help hash. @@ -36,34 +36,34 @@ our %HELP_FML = ( # Callback for FML command. sub fml { - my ($src, undef) = @_; + my ($src, undef) = @_; # Create an instance of LWP::UserAgent. - my $ua = LWP::UserAgent->new(); - $ua->agent('Auto IRC Bot'); - $ua->timeout(2); + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); # Get the random FML via HTTP. my $rp = $ua->get('http://rscript.org/lookup.php?type=fml'); - if ($rp->is_success) { + if ($rp->is_success) { # If successful, decode the content. my $d = $rp->decoded_content; - $d =~ s/(\n|\r)//g; + $d =~ s/(\n|\r)//g; # Get the FML. my (undef, $dfa) = split('Text: ', $d); my ($fml, undef) = split('Agree:', $dfa); # And send to channel. - privmsg($src->{svr}, $src->{chan}, "\002Random FML:\002 ".$fml); - } + privmsg($src->{svr}, $src->{chan}, "\002Random FML:\002 ".$fml); + } else { # Otherwise, send an error message. privmsg($src->{svr}, $src->{chan}, "An error occurred while retrieving the FML."); } - return 1; + return 1; } # Start initialization. diff --git a/modules/HelloChan.pm b/modules/HelloChan.pm index b02b023..1bd887d 100644 --- a/modules/HelloChan.pm +++ b/modules/HelloChan.pm @@ -10,28 +10,28 @@ use API::IRC qw(privmsg); # Initialization subroutine. sub _init { - # Add a hook for when we join a channel. - hook_add("on_ucjoin", "HelloChan", \&M::HelloChan::hello) or return 0; - return 1; + # Add a hook for when we join a channel. + hook_add("on_ucjoin", "HelloChan", \&M::HelloChan::hello) or return 0; + return 1; } # Void subroutine. sub _void { - # Delete the hook. - hook_del("on_ucjoin", "HelloChan") or return 0; - return 1; + # Delete the hook. + hook_del("on_ucjoin", "HelloChan") or return 0; + return 1; } # Main subroutine. sub hello { - my (($svr, $chan)) = @_; - - # Send a PRIVMSG. - privmsg($svr, $chan, "Hello channel! I am a bot!"); - - return 1; + my (($svr, $chan)) = @_; + + # Send a PRIVMSG. + privmsg($svr, $chan, "Hello channel! I am a bot!"); + + return 1; } diff --git a/modules/IsItUp.pm b/modules/IsItUp.pm index 67c07ad..904b9ba 100644 --- a/modules/IsItUp.pm +++ b/modules/IsItUp.pm @@ -11,61 +11,61 @@ use LWP::UserAgent; # Initialization subroutine. sub _init { - # Create the ISITUP command. - cmd_add('ISITUP', 0, 0, \%M::IsItUp::HELP_ISITUP, \&M::IsItUp::check) or return 0; + # Create the ISITUP command. + cmd_add('ISITUP', 0, 0, \%M::IsItUp::HELP_ISITUP, \&M::IsItUp::check) or return 0; - # Success. - return 1; + # Success. + return 1; } # Void subroutine. sub _void { - # Delete the ISITUP command. - cmd_del('ISITUP') or return 0; + # Delete the ISITUP command. + cmd_del('ISITUP') or return 0; - # Success. - return 1; + # Success. + return 1; } # Help hashes. our %HELP_ISITUP = ( - 'en' => "This command will check if a website appears up or down to the bot. \002Syntax:\002 ISITUP ", + 'en' => "This command will check if a website appears up or down to the bot. \002Syntax:\002 ISITUP ", ); # Callback for ISITUP command. sub check { - my ($src, @argv) = @_; + my ($src, @argv) = @_; - # Create an instance of LWP::UserAgent. - my $ua = LWP::UserAgent->new(); - $ua->agent('Auto IRC Bot'); - $ua->timeout(2); - # Do we have enough parameters? - if (!defined $argv[0]) { - notice($src->{svr}, $src->{nick}, trans('Not enough parameters').q{.}); - return 0; - } - my $curl = $argv[0]; - # Does the URL start with http(s)? - if ($curl !~ m/^http/) { - $curl = 'http://'.$curl; - } + # Create an instance of LWP::UserAgent. + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); + # Do we have enough parameters? + if (!defined $argv[0]) { + notice($src->{svr}, $src->{nick}, trans('Not enough parameters').q{.}); + return 0; + } + my $curl = $argv[0]; + # Does the URL start with http(s)? + if ($curl !~ m/^http/) { + $curl = 'http://'.$curl; + } - # Get the response via HTTP. - my $response = $ua->get($curl); + # Get the response via HTTP. + my $response = $ua->get($curl); - if ($response->is_success) { - # If successful, it's up. - privmsg($src->{svr}, $src->{chan}, $curl.' appears to be up from here.'); - } - else { - # Otherwise, it's down. - privmsg($src->{svr}, $src->{chan}, $curl.' appears to be down from here.'); - } + if ($response->is_success) { + # If successful, it's up. + privmsg($src->{svr}, $src->{chan}, $curl.' appears to be up from here.'); + } + else { + # Otherwise, it's down. + privmsg($src->{svr}, $src->{chan}, $curl.' appears to be down from here.'); + } - return 1; + return 1; } # Start initialization. diff --git a/modules/SASLAuth.pm b/modules/SASLAuth.pm index f4ad9a5..972ec5f 100644 --- a/modules/SASLAuth.pm +++ b/modules/SASLAuth.pm @@ -13,9 +13,9 @@ use API::IRC qw(privmsg); # Initialization subroutine. sub _init { - # Check if this Auto was built with SASL support. - err(2, "Auto was not built with SASL support. Aborting SASLAuth.", 0) and return 0 if $Auto::ENFEAT !~ /sasl/; - # Add a hook for before we connect. + # Check if this Auto was built with SASL support. + err(2, "Auto was not built with SASL support. Aborting SASLAuth.", 0) and return 0 if $Auto::ENFEAT !~ /sasl/; + # Add a hook for before we connect. hook_add('on_preconnect', 'CAP', sub { my ($srv) = @_; Auto::socksnd($srv, 'CAP LS'); } ) or return 0; # Hook for parsing CAP. @@ -26,19 +26,19 @@ sub _init rchook_add('904', \&M::SASLAuth::handle_904) or return 0; # Hook for parsing 906. rchook_add('906', \&M::SASLAuth::handle_906) or return 0; - return 1; + return 1; } # Void subroutine. sub _void { - # Delete the hooks. - hook_del("on_preconnect", "CAP") or return 0; + # Delete the hooks. + hook_del("on_preconnect", "CAP") or return 0; rchook_del('CAP'); rchook_del('903'); rchook_del('904'); rchook_del('906'); - return 1; + return 1; } sub handle_cap { @@ -123,8 +123,8 @@ sub handle_904 # SASL authentication aborted. sub handle_906 { - my ($svr, undef) = @_; - Auto::socksnd($svr, 'CAP END'); + my ($svr, undef) = @_; + Auto::socksnd($svr, 'CAP END'); timer_del('auth_timeout'); awarn(2, "SASL authentication aborted!"); } diff --git a/modules/Weather.pm b/modules/Weather.pm index 0f3180b..7556f7e 100644 --- a/modules/Weather.pm +++ b/modules/Weather.pm @@ -12,69 +12,69 @@ use XML::Simple; # Initialization subroutine. sub _init { - # Create the Weather command. - cmd_add("WEATHER", 0, 0, \%M::Weather::HELP_WEATHER, \&M::Weather::weather) or return 0; + # Create the Weather command. + cmd_add("WEATHER", 0, 0, \%M::Weather::HELP_WEATHER, \&M::Weather::weather) or return 0; - # Success. - return 1; + # Success. + return 1; } # Void subroutine. sub _void { - # Delete the Weather command. - cmd_del("WEATHER") or return 0; + # Delete the Weather command. + cmd_del("WEATHER") or return 0; - # Success. - return 1; + # Success. + return 1; } # Help hashes. our %HELP_WEATHER = ( - 'en' => "This command will retrieve the weather via Wunderground for the specified location. \002Syntax:\002 WEATHER ", + 'en' => "This command will retrieve the weather via Wunderground for the specified location. \002Syntax:\002 WEATHER ", ); # Callback for Weather command. sub weather { - my ($src, @args) = @_; + my ($src, @args) = @_; - # Create an instance of LWP::UserAgent. - my $ua = LWP::UserAgent->new(); - $ua->agent('Auto IRC Bot'); - $ua->timeout(2); - # Put together the call to the Wunderground API. - if (!defined $args[0]) { - notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); - return 0; - } - my $loc = join(' ', @args); - $loc =~ s/ /%20/g; - my $url = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=".$loc; - # Get the response via HTTP. - my $response = $ua->get($url); + # Create an instance of LWP::UserAgent. + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); + # Put together the call to the Wunderground API. + if (!defined $args[0]) { + notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); + return 0; + } + my $loc = join(' ', @args); + $loc =~ s/ /%20/g; + my $url = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=".$loc; + # Get the response via HTTP. + my $response = $ua->get($url); - if ($response->is_success) { - # If successful, decode the content. - my $d = XMLin($response->decoded_content); - # And send to channel - if (!ref($d->{observation_location}->{country})) { - my $windc = $d->{wind_string}; - if (substr($windc, length($windc) - 1, 1) eq " ") { $windc = substr($windc, 0, length($windc) - 1); } - privmsg($src->{svr}, $src->{chan}, "Results for \2".$d->{observation_location}->{full}."\2 - \2Temperature:\2 ".$d->{temperature_string}." \2Wind Conditions:\2 ".$windc." \2Conditions:\2 ".$d->{weather}); - privmsg($src->{svr}, $src->{chan}, "\2Heat index:\2 ".$d->{heat_index_string}." \2Humidity:\2 ".$d->{relative_humidity}." \2Pressure:\2 ".$d->{pressure_string}." - ".$d->{observation_time}); - } - else { - # Otherwise, send an error message. - privmsg($src->{svr}, $src->{chan}, "Location not found."); - } - } - else { - # Otherwise, send an error message. - privmsg($src->{svr}, $src->{chan}, "An error occurred while retrieving your weather."); - } + if ($response->is_success) { + # If successful, decode the content. + my $d = XMLin($response->decoded_content); + # And send to channel + if (!ref($d->{observation_location}->{country})) { + my $windc = $d->{wind_string}; + if (substr($windc, length($windc) - 1, 1) eq " ") { $windc = substr($windc, 0, length($windc) - 1); } + privmsg($src->{svr}, $src->{chan}, "Results for \2".$d->{observation_location}->{full}."\2 - \2Temperature:\2 ".$d->{temperature_string}." \2Wind Conditions:\2 ".$windc." \2Conditions:\2 ".$d->{weather}); + privmsg($src->{svr}, $src->{chan}, "\2Heat index:\2 ".$d->{heat_index_string}." \2Humidity:\2 ".$d->{relative_humidity}." \2Pressure:\2 ".$d->{pressure_string}." - ".$d->{observation_time}); + } + else { + # Otherwise, send an error message. + privmsg($src->{svr}, $src->{chan}, "Location not found."); + } + } + else { + # Otherwise, send an error message. + privmsg($src->{svr}, $src->{chan}, "An error occurred while retrieving your weather."); + } - return 1; + return 1; } # Start initialization.