mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 15:29:32 +01:00
Progressing on converting things to objects
This commit is contained in:
parent
d48f286aca
commit
313da0b587
@ -102,7 +102,7 @@ sub check_flood {
|
|||||||
}
|
}
|
||||||
} else { # private message flood
|
} else { # private message flood
|
||||||
$self->{pbot}->logger->log("$nick msg flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second ignore\n");
|
$self->{pbot}->logger->log("$nick msg flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second ignore\n");
|
||||||
$self->{pbot}->ignorelist->ignore_user("", "floodcontrol", "", "$nick" . '@' . "$host $channel $length");
|
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,23 +69,24 @@ sub list {
|
|||||||
return "/msg $nick Usage: list <modules|factoids|commands|admins>";
|
return "/msg $nick Usage: list <modules|factoids|commands|admins>";
|
||||||
}
|
}
|
||||||
|
|
||||||
=cut move to PBot::AntiFlood somehow
|
|
||||||
if($arguments =~/^messages\s+(.*?)\s+(.*)$/) {
|
if($arguments =~/^messages\s+(.*?)\s+(.*)$/) {
|
||||||
my $nick_search = $1;
|
my $nick_search = $1;
|
||||||
my $channel = $2;
|
my $channel = $2;
|
||||||
|
|
||||||
if(not exists $flood_watch{$nick_search}) {
|
if(not exists ${ $self->{pbot}->antiflood->message_history }{$nick_search}) {
|
||||||
return "/msg $nick No messages for $nick_search yet.";
|
return "/msg $nick No messages for $nick_search yet.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not exists $flood_watch{$nick_search}{$channel}) {
|
if(not exists ${ $self->{pbot}->antiflood->message_history }{$nick_search}{$channel}) {
|
||||||
return "/msg $nick No messages for $nick_search in $channel yet.";
|
return "/msg $nick No messages for $nick_search in $channel yet.";
|
||||||
}
|
}
|
||||||
|
|
||||||
my @messages = @{ $flood_watch{$nick_search}{$channel}{messages} };
|
my @messages = @{ ${ $self->{pbot}->antiflood->message_history }{$nick_search}{$channel}{messages} };
|
||||||
|
my $botnick = $self->{pbot}->botnick;
|
||||||
|
|
||||||
for(my $i = 0; $i <= $#messages; $i++) {
|
for(my $i = 0; $i <= $#messages; $i++) {
|
||||||
$conn->privmsg($nick, "" . ($i + 1) . ": " . $messages[$i]->{msg} . "\n") unless $nick =~ /\Q$botnick\E/i;
|
$self->{pbot}->logger->log("" . ($i + 1) . ") " . localtime($messages[$i]->{timestamp}) . " <$nick_search> " . $messages[$i]->{msg} . "\n");
|
||||||
|
$self->{pbot}->conn->privmsg($nick, "" . ($i + 1) . ") " . localtime($messages[$i]->{timestamp}) . " <$nick_search> " . $messages[$i]->{msg} . "\n") unless $nick =~ /\Q$botnick\E/i;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -101,29 +102,27 @@ sub list {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($arguments =~ /^commands$/i) {
|
if($arguments =~ /^commands$/i) {
|
||||||
$text = "Internal commands: ";
|
$text = "Registered commands: ";
|
||||||
foreach my $command (sort keys %internal_commands) {
|
foreach my $command (sort { $a->{name} cmp $b->{name} } @{ $self->{pbot}->commands->{handlers} }) {
|
||||||
$text .= "$command ";
|
$text .= "$command->{name} ";
|
||||||
$text .= "($internal_commands{$command}{level}) "
|
$text .= "($command->{level}) " if $command->{level} > 0;
|
||||||
if $internal_commands{$command}{level} > 0;
|
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($arguments =~ /^factoids$/i) {
|
if($arguments =~ /^factoids$/i) {
|
||||||
return "For a list of factoids see http://blackshell.com/~msmud/candide/factoids.html";
|
return "For a list of factoids see " . $self->{pbot}->factoids->export_site;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($arguments =~ /^admins$/i) {
|
if($arguments =~ /^admins$/i) {
|
||||||
$text = "Admins: ";
|
$text = "Admins: ";
|
||||||
foreach my $admin (sort { $admins{$b}{level} <=> $admins{$a}{level} } keys %admins) {
|
foreach my $admin (sort { ${ $self->{pbot}->admins->admins }{$b}{level} <=> ${ $self->{pbot}->admins->admins }{$a}{level} } keys %{ $self->{pbot}->admins->admins }) {
|
||||||
$text .= "*" if exists $admins{$admin}{login};
|
$text .= "*" if exists ${ $self->{pbot}->admins->admins }{$admin}{login};
|
||||||
$text .= "$admin ($admins{$admin}{level}) ";
|
$text .= "$admin (" . ${ $self->{pbot}->admins->admins }{$admin}{level} . ") ";
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
return "/msg $nick Usage: list <modules|commands|factoids|admins>";
|
return "/msg $nick Usage: list <modules|commands|factoids|admins>";
|
||||||
=cut
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub alias {
|
sub alias {
|
||||||
|
@ -82,6 +82,9 @@ sub execute_module {
|
|||||||
|
|
||||||
return "/me moans loudly."; # er, didn't execute the module?
|
return "/me moans loudly."; # er, didn't execute the module?
|
||||||
} # end child block
|
} # end child block
|
||||||
|
else {
|
||||||
|
$self->{child} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ""; # child returns bot command, not parent -- so return blank/no command
|
return ""; # child returns bot command, not parent -- so return blank/no command
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ sub on_disconnect {
|
|||||||
$conn->connect();
|
$conn->connect();
|
||||||
if(not $conn->connected) {
|
if(not $conn->connected) {
|
||||||
sleep(5);
|
sleep(5);
|
||||||
on_disconnect($self, $conn, $event)
|
on_disconnect($self, $conn, $event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ sub initialize {
|
|||||||
|
|
||||||
$self->{pbot} = $pbot;
|
$self->{pbot} = $pbot;
|
||||||
$self->{ignore_list} = {};
|
$self->{ignore_list} = {};
|
||||||
|
$self->{ignore_flood_counter} = 0;
|
||||||
|
$self->{last_timestamp} = gettimeofday;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add {
|
sub add {
|
||||||
@ -54,10 +56,39 @@ sub remove {
|
|||||||
sub check_ignore {
|
sub check_ignore {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($nick, $user, $host, $channel) = @_;
|
my ($nick, $user, $host, $channel) = @_;
|
||||||
|
my $pbot = $self->{pbot};
|
||||||
$channel = lc $channel;
|
$channel = lc $channel;
|
||||||
|
|
||||||
my $hostmask = "$nick!$user\@$host";
|
my $hostmask = "$nick!$user\@$host";
|
||||||
|
|
||||||
|
my $now = gettimeofday;
|
||||||
|
|
||||||
|
if(defined $channel) { # do not execute following if text is coming from STDIN ($channel undef)
|
||||||
|
if($channel =~ /^#/) {
|
||||||
|
$self->{ignore_flood_counter}++; # TODO: make this per channel, e.g., ${ $self->{ignore_flood_counter} }{$channel}++
|
||||||
|
$pbot->logger->log("flood_msg: $self->{ignore_flood_counter}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if($self->{ignore_flood_counter} > 4) {
|
||||||
|
$pbot->logger->log("flood_msg exceeded! [$self->{ignore_flood_counter}]\n");
|
||||||
|
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
|
||||||
|
$self->{ignore_flood_counter} = 0;
|
||||||
|
if($channel =~ /^#/) {
|
||||||
|
$pbot->conn->me($channel, "has been overwhelmed.");
|
||||||
|
$pbot->conn->me($channel, "lies down and falls asleep.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($now - $self->{last_timestamp} >= 15) {
|
||||||
|
$self->{last_timestamp} = $now;
|
||||||
|
if($self->{ignore_flood_counter} > 0) {
|
||||||
|
$pbot->logger->log("flood_msg reset: (was $self->{ignore_flood_counter})\n");
|
||||||
|
$self->{ignore_flood_counter} = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $ignored (keys %{ $self->{ignore_list} }) {
|
foreach my $ignored (keys %{ $self->{ignore_list} }) {
|
||||||
foreach my $ignored_channel (keys %{ ${ $self->{ignore_list} }{$ignored} }) {
|
foreach my $ignored_channel (keys %{ ${ $self->{ignore_list} }{$ignored} }) {
|
||||||
$self->{pbot}->logger->log("check_ignore: comparing '$hostmask' against '$ignored' for channel '$channel'\n");
|
$self->{pbot}->logger->log("check_ignore: comparing '$hostmask' against '$ignored' for channel '$channel'\n");
|
||||||
|
@ -48,7 +48,6 @@ sub ignore_user {
|
|||||||
|
|
||||||
my ($target, $channel, $length) = split /\s+/, $arguments;
|
my ($target, $channel, $length) = split /\s+/, $arguments;
|
||||||
|
|
||||||
|
|
||||||
if(not defined $target) {
|
if(not defined $target) {
|
||||||
return "/msg $nick Usage: ignore host [channel] [timeout]";
|
return "/msg $nick Usage: ignore host [channel] [timeout]";
|
||||||
}
|
}
|
||||||
@ -82,7 +81,7 @@ sub ignore_user {
|
|||||||
sub unignore_user {
|
sub unignore_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my ($target, $channel) = split /\s+/, $arguments;
|
my ($target, $channel) = split /\s+/, $arguments if defined $arguments;
|
||||||
|
|
||||||
if(not defined $target) {
|
if(not defined $target) {
|
||||||
return "/msg $nick Usage: unignore host [channel]";
|
return "/msg $nick Usage: unignore host [channel]";
|
||||||
|
@ -119,8 +119,8 @@ sub process_line {
|
|||||||
# TODO: move this to FactoidModuleLauncher somehow, completely out of Interpreter!
|
# TODO: move this to FactoidModuleLauncher somehow, completely out of Interpreter!
|
||||||
if($pbot->factoids->{factoidmodulelauncher}->{child} != 0) {
|
if($pbot->factoids->{factoidmodulelauncher}->{child} != 0) {
|
||||||
# if this process is a child, it must die now
|
# if this process is a child, it must die now
|
||||||
#$pbot->logger->log("Terminating module.\n");
|
$pbot->logger->log("Terminating module.\n");
|
||||||
exit;
|
exit 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user