3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Truncate long output to codepad.org

This commit is contained in:
Pragmatic Software 2010-04-13 04:17:54 +00:00
parent a56a297460
commit 1131ab32df
4 changed files with 31 additions and 9 deletions

View File

@ -95,12 +95,14 @@ sub check_flood {
${ $self->message_history }{$nick}{$channel}{offenses}++; ${ $self->message_history }{$nick}{$channel}{offenses}++;
my $length = ${ $self->message_history }{$nick}{$channel}{offenses} * ${ $self->message_history }{$nick}{$channel}{offenses} * 30; my $length = ${ $self->message_history }{$nick}{$channel}{offenses} * ${ $self->message_history }{$nick}{$channel}{offenses} * 30;
if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise) if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise)
return if exists $self->{pbot}->chanops->{quieted_nicks}->{$nick};
if($mode == $self->{FLOOD_CHAT}) { if($mode == $self->{FLOOD_CHAT}) {
$self->{pbot}->chanops->quiet_nick_timed($nick, $channel, $length); $self->{pbot}->chanops->quiet_nick_timed($nick, $channel, $length);
$self->{pbot}->conn->privmsg($nick, "You have been quieted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length seconds."); $self->{pbot}->conn->privmsg($nick, "You have been quieted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length seconds.");
$self->{pbot}->logger->log("$nick $channel flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second quiet\n"); $self->{pbot}->logger->log("$nick $channel flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second quiet\n");
} }
} else { # private message flood } else { # private message flood
return if exists $self->{pbot}->ignorelist->{ignore_list}->{"$nick!$user\@$host"}{$channel};
$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}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length seconds."); $self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length seconds.");
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length"); $self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");

View File

@ -151,7 +151,7 @@ sub check_ignore {
if(not exists $self->{last_timestamp}->{$channel}) { if(not exists $self->{last_timestamp}->{$channel}) {
$self->{last_timestamp}->{$channel} = $now; $self->{last_timestamp}->{$channel} = $now;
} elsif($now - $self->{last_timestamp}->{$channel} >= 30) { } elsif($now - $self->{last_timestamp}->{$channel} >= 15) {
$self->{last_timestamp}->{$channel} = $now; $self->{last_timestamp}->{$channel} = $now;
if($self->{ignore_flood_counter}->{$channel} > 0) { if($self->{ignore_flood_counter}->{$channel} > 0) {
$self->{ignore_flood_counter}->{$channel}--; $self->{ignore_flood_counter}->{$channel}--;
@ -159,9 +159,9 @@ sub check_ignore {
} }
} }
if(($self->{ignore_flood_counter}->{$channel} > 4) or ($channel =~ /^#osdev$/i and $self->{ignore_flood_counter}->{$channel} >= 3)) { if(($self->{ignore_flood_counter}->{$channel} > 5) or ($channel =~ /^#osdev$/i and $self->{ignore_flood_counter}->{$channel} >= 3)) {
$pbot->logger->log("flood_msg exceeded! [$self->{ignore_flood_counter}->{$channel}]\n"); $pbot->logger->log("flood_msg exceeded! [$self->{ignore_flood_counter}->{$channel}]\n");
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", ".* $channel 600"); $self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
$self->{ignore_flood_counter}->{$channel} = 0; $self->{ignore_flood_counter}->{$channel} = 0;
if($channel =~ /^#/) { if($channel =~ /^#/) {
$pbot->conn->me($channel, "has been overwhelmed."); $pbot->conn->me($channel, "has been overwhelmed.");

View File

@ -10,6 +10,7 @@ use strict;
use base 'PBot::Registerable'; use base 'PBot::Registerable';
use LWP::UserAgent;
use Carp (); use Carp ();
use vars qw($VERSION); use vars qw($VERSION);
@ -41,6 +42,25 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
} }
sub paste_codepad {
my $text = join(' ', @_);
$text =~ s/(.{120})\s/$1\n/g;
my $ua = LWP::UserAgent->new();
$ua->agent("Mozilla/5.0");
push @{ $ua->requests_redirectable }, 'POST';
my %post = ( 'lang' => 'Plain Text', 'code' => $text, 'private' => 'True', 'submit' => 'Submit' );
my $response = $ua->post("http://codepad.org", \%post);
if(not $response->is_success) {
return $response->status_line;
}
return $response->request->uri;
}
sub process_line { sub process_line {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $text) = @_; my ($from, $nick, $user, $host, $text) = @_;
@ -86,11 +106,11 @@ sub process_line {
if(defined $result && length $result > 0) { if(defined $result && length $result > 0) {
my $len = length $result; my $len = length $result;
if($len > $pbot->max_msg_len) { if($len > $pbot->max_msg_len) {
if(($len - $pbot->max_msg_len) > 10) { my $link = paste_codepad("[$from] <$nick> $text\n$result");
$pbot->logger->log("Message truncated.\n"); my $trunc = "... truncated; see $link for full text.";
$result = substr($result, 0, $pbot->max_msg_len); $pbot->logger->log("Message truncated -- pasted to $link\n");
substr($result, $pbot->max_msg_len) = "... (" . ($len - $pbot->max_msg_len) . " more characters)"; $result = substr($result, 0, $pbot->max_msg_len);
} substr($result, $pbot->max_msg_len - length $trunc) = $trunc;
} }
$pbot->logger->log("Final result: $result\n"); $pbot->logger->log("Final result: $result\n");

View File

@ -88,7 +88,7 @@ sub initialize {
$botnick = "pbot2" unless defined $botnick; $botnick = "pbot2" unless defined $botnick;
$identify_password = "" unless defined $identify_password; $identify_password = "" unless defined $identify_password;
$max_msg_len = 460 unless defined $max_msg_len; $max_msg_len = 430 unless defined $max_msg_len;
$MAX_FLOOD_MESSAGES = 4 unless defined $MAX_FLOOD_MESSAGES; $MAX_FLOOD_MESSAGES = 4 unless defined $MAX_FLOOD_MESSAGES;
$MAX_NICK_MESSAGES = 8 unless defined $MAX_NICK_MESSAGES; $MAX_NICK_MESSAGES = 8 unless defined $MAX_NICK_MESSAGES;