mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 12:32:37 +01:00
Improve unbanme
behavior
This commit is contained in:
parent
2e0a5e411c
commit
4ef978963c
@ -478,6 +478,7 @@ sub unbanme {
|
|||||||
return "/msg $nick Usage: unbanme <channel>";
|
return "/msg $nick Usage: unbanme <channel>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $warning = '';
|
||||||
my %unbanned;
|
my %unbanned;
|
||||||
|
|
||||||
my %aliases = $self->{pbot}->{messagehistory}->{database}->get_also_known_as($nick);
|
my %aliases = $self->{pbot}->{messagehistory}->{database}->get_also_known_as($nick);
|
||||||
@ -515,9 +516,19 @@ sub unbanme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'offenses');
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'unbanmes');
|
||||||
if($channel_data->{offenses} > 1) {
|
if ($channel_data->{unbanmes} > 1) {
|
||||||
return "/msg $nick You may only use unbanme for the first offense. You will be automatically unbanned in a few hours, and your offense counter will decrement once every 24 hours.";
|
return "/msg $nick You may only use unbanme for the first two offenses. You will be automatically unbanned in a few hours, and your offense counter will decrement once every 24 hours.";
|
||||||
|
}
|
||||||
|
|
||||||
|
$channel_data->{unbanmes}++;
|
||||||
|
|
||||||
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($message_account, $channel, $channel_data);
|
||||||
|
|
||||||
|
if ($channel_data->{unbanmes} == 1) {
|
||||||
|
$warning = ' You may use `unbanme` only one more time today; use it wisely.';
|
||||||
|
} else {
|
||||||
|
$warning = ' You may not use `unbanme` any longer today; please ensure that your client or connection issues are resolved, otherwise leave the channel until they are or you will be temporarily banned for several hours.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{pbot}->{chanops}->unban_user($mask, $channel . '-floodbans');
|
$self->{pbot}->{chanops}->unban_user($mask, $channel . '-floodbans');
|
||||||
@ -525,7 +536,7 @@ sub unbanme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keys %unbanned) {
|
if (keys %unbanned) {
|
||||||
return "/msg $nick You have been unbanned from $channel.";
|
return "/msg $nick You have been unbanned from $channel.$warning";
|
||||||
} else {
|
} else {
|
||||||
return "/msg $nick There is no temporary join-flooding ban set for you in channel $channel.";
|
return "/msg $nick There is no temporary join-flooding ban set for you in channel $channel.";
|
||||||
}
|
}
|
||||||
@ -820,12 +831,22 @@ sub adjust_offenses {
|
|||||||
# decrease offenses counter if 24 hours have elapsed since latest offense
|
# decrease offenses counter if 24 hours have elapsed since latest offense
|
||||||
my $channel_datas = $self->{pbot}->{messagehistory}->{database}->get_channel_datas_where_last_offense_older_than(gettimeofday - 60 * 60 * 24);
|
my $channel_datas = $self->{pbot}->{messagehistory}->{database}->get_channel_datas_where_last_offense_older_than(gettimeofday - 60 * 60 * 24);
|
||||||
foreach my $channel_data (@$channel_datas) {
|
foreach my $channel_data (@$channel_datas) {
|
||||||
if($channel_data->{offenses} > 0) {
|
my $id = delete $channel_data->{id};
|
||||||
my $id = delete $channel_data->{id};
|
my $channel = delete $channel_data->{channel};
|
||||||
my $channel = delete $channel_data->{channel};
|
my $update = 0;
|
||||||
|
|
||||||
|
if ($channel_data->{offenses} > 0) {
|
||||||
$channel_data->{offenses}--;
|
$channel_data->{offenses}--;
|
||||||
|
$update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($channel_data->{unbanmes} > 0) {
|
||||||
|
$channel_data->{unbanmes}--;
|
||||||
|
$update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($update) {
|
||||||
$channel_data->{last_offense} = gettimeofday;
|
$channel_data->{last_offense} = gettimeofday;
|
||||||
#$self->{pbot}->{logger}->log("[adjust-offenses] [$id][$channel] 24 hours since last offense/decrease -- decreasing offenses to $channel_data->{offenses}\n");
|
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,8 @@ CREATE TABLE IF NOT EXISTS Channels (
|
|||||||
last_offense NUMERIC,
|
last_offense NUMERIC,
|
||||||
last_seen NUMERIC,
|
last_seen NUMERIC,
|
||||||
validated INTEGER,
|
validated INTEGER,
|
||||||
join_watch INTEGER
|
join_watch INTEGER,
|
||||||
|
unbanmes INTEGER
|
||||||
)
|
)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
@ -700,7 +701,7 @@ sub create_channel {
|
|||||||
my ($self, $id, $channel) = @_;
|
my ($self, $id, $channel) = @_;
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $sth = $self->{dbh}->prepare('INSERT INTO Channels SELECT ?, ?, 0, 0, 0, 0, 0, 0, 0 WHERE NOT EXISTS (SELECT 1 FROM Channels WHERE id = ? AND channel = ?)');
|
my $sth = $self->{dbh}->prepare('INSERT INTO Channels SELECT ?, ?, 0, 0, 0, 0, 0, 0, 0, 0 WHERE NOT EXISTS (SELECT 1 FROM Channels WHERE id = ? AND channel = ?)');
|
||||||
$sth->bind_param(1, $id);
|
$sth->bind_param(1, $id);
|
||||||
$sth->bind_param(2, $channel);
|
$sth->bind_param(2, $channel);
|
||||||
$sth->bind_param(3, $id);
|
$sth->bind_param(3, $id);
|
||||||
@ -788,7 +789,7 @@ sub get_channel_datas_where_last_offense_older_than {
|
|||||||
my ($self, $timestamp) = @_;
|
my ($self, $timestamp) = @_;
|
||||||
|
|
||||||
my $channel_datas = eval {
|
my $channel_datas = eval {
|
||||||
my $sth = $self->{dbh}->prepare('SELECT id, channel, offenses, last_offense FROM Channels WHERE last_offense > 0 AND last_offense <= ?');
|
my $sth = $self->{dbh}->prepare('SELECT id, channel, offenses, last_offense, unbanmes FROM Channels WHERE last_offense > 0 AND last_offense <= ?');
|
||||||
$sth->bind_param(1, $timestamp);
|
$sth->bind_param(1, $timestamp);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
return $sth->fetchall_arrayref({});
|
return $sth->fetchall_arrayref({});
|
||||||
|
Loading…
Reference in New Issue
Block a user