diff --git a/NEWS b/NEWS index 3c1fd8e..1e9426c 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ Incompatibilities: * Database: Changed structure of the `qdb` table. Modify the configuration values in upgrade.pl then run it to upgrade the database. * database:format is now required in the config. +* bantype is now required in the config. We thank you for choosing Auto. Please remember that he is still in early development stages. But we hope we've piqued your interest, as Auto's upcoming diff --git a/bin/auto b/bin/auto index c33fc0e..f4580dc 100755 --- a/bin/auto +++ b/bin/auto @@ -143,7 +143,7 @@ if (conf_get('die')) { } # Check for required configuration values. -my @REQCVALS = qw(locale expire_logs server fantasy_pf ratelimit database:format); +my @REQCVALS = qw(locale expire_logs server fantasy_pf ratelimit database:format bantype); foreach my $REQCVAL (@REQCVALS) { if (!conf_get($REQCVAL)) { my $err = 2; diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 8013630..12f3cd4 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * bantype is now a required configuration value. + * Added ban() to API::IRC. * Changed on_cprivmsg arguments to: \%src, $channel, @msg * Changed on_uprivmsg arguments to: \%src, @msg * Bug fix: Commands getting Permission denied even with incorrect prefix. diff --git a/lib/API/IRC.pm b/lib/API/IRC.pm index c3be022..40959dd 100644 --- a/lib/API/IRC.pm +++ b/lib/API/IRC.pm @@ -4,13 +4,47 @@ package API::IRC; use strict; use warnings; +use feature qw(switch); use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(cjoin cpart cmode umode kick privmsg notice quit nick names topic - usrc match_mask); +our @EXPORT_OK = qw(ban cjoin cpart cmode umode kick privmsg notice quit nick names + topic usrc match_mask); +# Set a ban, based on config bantype value. +sub ban +{ + my ($svr, $chan, $type, $user) = @_; + my $cbt = (API::Std::conf_get('bantype'))[0][0]; + + # Prepare the mask we're going to ban. + my $mask; + given ($cbt) { + when (1) { $mask = '*!*@'.$user->{host}; } + when (2) { $mask = $user->{nick}.'!*@*'; } + when (3) { $mask = '*!'.$user->{user}.'@'.$user->{host}; } + when (4) { $mask = $user->{nick}.'!*'.$user->{user}.'@'.$user->{host}; } + when (5) { + my @hd = split m/[\.]/, $user->{host}; + shift @hd; + $mask = '*!*@*.'.join ' ', @hd; + } + } + + # Now set the ban. + if (lc $type eq 'b') { + # We were requested to set a regular ban. + cmode($svr, $chan, "+b $mask"); + } + elsif (lc $type eq 'q') { + # We were requested to set a ratbox-style quiet. + cmode($svr, $chan, "+q $mask"); + } + + return 1; +} + # Join a channel. sub cjoin {