Added match_mask() to API::IRC and match_user() to API::Std, match_user checks
config user:mask to find a user block, if a match is found, the configured username is returned.
This commit is contained in:
1 parent
ccce5d5ef6
commit
a04e181378
4 files changed
+57
-5
No files matched your search
@@ -230,6 +230,18 @@ else {
|
|||||||
}
|
}
|
||||||
undef $it;
|
undef $it;
|
||||||
|
|
||||||
|
### NOTE: REMOVE THIS FROM MAINLINE CODE. IT IS FOR DEVELOPMENT PURPOSES ONLY. ###
|
||||||
|
sub hw {
|
||||||
|
my (%data) = @_; my @argv = @{ $data{args} };
|
||||||
|
if (API::Std::match_user(( 'nick' => $data{nick}, 'user' => $data{user}, 'host' => $data{host} ))) {
|
||||||
|
API::IRC::privmsg($data{svr}, $data{chan}, @argv);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_add("SAY", 0, 0, 0, \&Auto::hw) or exit;
|
||||||
|
### End ###
|
||||||
|
|
||||||
# Infinite while loop.
|
# Infinite while loop.
|
||||||
while (1) {
|
while (1) {
|
||||||
# Timer check.
|
# Timer check.
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
==================================================================
|
==================================================================
|
||||||
|
* Added match_mask() to API::IRC and match_user() to API::Std,
|
||||||
|
match_user checks config user:mask to find a user block, if
|
||||||
|
a match is found, the configured username is returned.
|
||||||
* Added rchook_add() and rchook_del() to API::Std.
|
* Added rchook_add() and rchook_del() to API::Std.
|
||||||
* Parse NOTICE and added hook on_notice.
|
* Parse NOTICE and added hook on_notice.
|
||||||
* Added hooks on_uprivmsg and on_cprivmsg.
|
* Added hooks on_uprivmsg and on_cprivmsg.
|
||||||
|
|||||||
+20
-1
@@ -9,7 +9,7 @@ use warnings;
|
|||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(cjoin cpart cmode umode privmsg notice quit nick names usrc);
|
our @EXPORT_OK = qw(cjoin cpart cmode umode privmsg notice quit nick names usrc match_mask);
|
||||||
|
|
||||||
|
|
||||||
# Join a channel.
|
# Join a channel.
|
||||||
@@ -133,5 +133,24 @@ sub usrc
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
+22
-4
@@ -11,7 +11,7 @@ use Exporter;
|
|||||||
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS);
|
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS);
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add
|
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);
|
cmd_del hook_add hook_del rchook_add rchook_del match_user);
|
||||||
|
|
||||||
|
|
||||||
# Initialize a module.
|
# Initialize a module.
|
||||||
@@ -332,13 +332,31 @@ sub trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Privilege subroutine.
|
# Privilege subroutine.
|
||||||
sub has_priv
|
sub match_user
|
||||||
{
|
{
|
||||||
my (%user, $priv) = @_;
|
my (%user) = @_;
|
||||||
|
|
||||||
|
# Get data from config.
|
||||||
|
return 0 if (!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) {
|
||||||
|
# For each user.
|
||||||
|
if ($uhk eq "mask") {
|
||||||
|
# Put together the user information.
|
||||||
|
my $mask = $user{nick}."!".$user{user}."@".$user{host};
|
||||||
|
if (API::IRC::match_mask($mask, ($ulhp{$uhk})[0][0])) {
|
||||||
|
# We've got a host match.
|
||||||
|
return $userkey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Error subroutine.
|
# Error subroutine.
|
||||||
|
|||||||
Reference in new issue
Block a user