Skip to content

Commit

Permalink
added from_user tag to JELP BANINFO and BANDEL for use in oper notic…
Browse files Browse the repository at this point in the history
…es. #32
  • Loading branch information
cooper committed Jul 24, 2016
1 parent ad4f3a1 commit cdf4469
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions INDEV
Expand Up @@ -3442,3 +3442,4 @@ CHANGES:

58. add TS6 handlers for UNKLINE, ENCAP UNKLINE, ENCAP UNDLINE. #32.
added notify_new_ban() and notify_delete_ban(). ban notices are now handled locally.
added from_user tag to JELP BANINFO and BANDEL for use in oper notices.
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/Ban.json
Expand Up @@ -12,5 +12,5 @@
"description" : "provides an interface for user and server banning",
"name" : "Ban",
"package" : "M::Ban",
"version" : "10.5"
"version" : "10.6"
}
1 change: 0 additions & 1 deletion modules/Ban/Ban.module/Ban.pm
Expand Up @@ -19,7 +19,6 @@ use strict;
use 5.010;

use IO::Async::Timer::Absolute;
use Scalar::Util 'looks_like_number';
use utils qw(import notice string_to_seconds);

our ($api, $mod, $pool, $conf, $me);
Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/JELP.module/JELP.json
Expand Up @@ -11,5 +11,5 @@
"description" : "JELP ban propagation",
"name" : "Ban::JELP",
"package" : "M::Ban::JELP",
"version" : "1.5"
"version" : "1.9"
}
28 changes: 20 additions & 8 deletions modules/Ban/Ban.module/JELP.module/JELP.pm
Expand Up @@ -50,15 +50,15 @@ our %jelp_incoming_commands = (
code => \&in_ban
},
BANINFO => {
params => '@rest',
params => '-tag.from_user(user,opt) @rest',
code => \&in_baninfo
},
BANIDK => {
params => '@rest',
code => \&in_banidk
},
BANDEL => {
params => '@rest',
params => '-tag.from_user(user,opt) @rest',
code => \&in_bandel
}
);
Expand Down Expand Up @@ -106,6 +106,9 @@ sub out_baninfo {
my ($to_server, $ban) = @_;
my $str = '';

# get user set by
my $from = $pool->lookup_user($ban->{_just_set_by});

# remove bogus keys
delete @$ban{ grep !$good_keys{$_}, keys %$ban };

Expand All @@ -118,7 +121,10 @@ sub out_baninfo {
}

my $reason = $ban->{reason} // '';
":$$me{sid} BANINFO $str:$reason"

my $res = ":$$me{sid} BANINFO $str:$reason";
$res = "\@from_user=$$from{uid} $res" if $from;
$res;
}

# BANIDK: request ban data
Expand All @@ -132,7 +138,13 @@ sub out_banidk {
sub out_bandel {
my $to_server = shift;
my $str = join ' ', map $_->{id}, @_;
":$$me{sid} BANDEL $str"

# get user deleted by
my $from = $pool->lookup_user($_[0]{_just_set_by});

my $res = ":$$me{sid} BANDEL $str";
$res = "\@from_user=$$from{uid} $res" if $from;
$res;
}

# Incoming
Expand Down Expand Up @@ -172,7 +184,7 @@ sub in_ban {
# :sid BANINFO key value key value :reason
# TODO: add @from_user for passing to notify
sub in_baninfo {
my ($server, $msg, @parts) = @_;
my ($server, $msg, $from, @parts) = @_;

# the reason is always last
my $reason = pop @parts;
Expand All @@ -186,7 +198,7 @@ sub in_baninfo {

# validate, update, enforce, and activate
%ban = add_update_enforce_activate_ban(%ban) or return;
notify_new_ban($server, %ban);
notify_new_ban($from || $server, %ban);

#=== Forward ===#
$msg->forward(baninfo => \%ban);
Expand All @@ -210,14 +222,14 @@ sub in_banidk {
# BANDEL: delete a ban
# TODO: add @from_user for passing to notify
sub in_bandel {
my ($server, $msg, @ids) = @_;
my ($server, $msg, $from, @ids) = @_;

foreach my $id (@ids) {

# find and delete each ban
my %ban = ban_by_id($id) or next;
delete_ban_by_id($id);
notify_delete_ban($server, %ban);
notify_delete_ban($from || $server, %ban);

#=== Forward ===#
$msg->forward(bandel => \%ban);
Expand Down

0 comments on commit cdf4469

Please sign in to comment.