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

Increase indentation size

This commit is contained in:
Pragmatic Software 2022-02-06 19:32:34 -08:00
parent 46fdd01ccd
commit 6b93005808

View File

@ -69,10 +69,10 @@ sub preprocess_code {
}
unless($self->{got_run} and $self->{copy_code}) {
open FILE, ">> $RealBin/../log.txt";
print FILE localtime() . "\n";
print FILE "$self->{nick} $self->{channel}: [" . $self->{arguments} . "] " . $self->{cmdline_options} . "$self->{code}\n";
close FILE;
open LOG, ">> $RealBin/../log.txt";
print LOG localtime() . "\n";
print LOG "$self->{nick} $self->{channel}: [" . $self->{arguments} . "] " . $self->{cmdline_options} . "$self->{code}\n";
close LOG;
}
# replace \n outside of quotes with literal newline
@ -140,11 +140,11 @@ sub postprocess_output {
my $self = shift;
unless($self->{got_run} and $self->{copy_code}) {
open FILE, ">> $RealBin/../log.txt";
print FILE "--------------------------post processing----------------------------------------------\n";
print FILE localtime() . "\n";
print FILE "$self->{output}\n";
close FILE;
open LOG, ">> $RealBin/../log.txt";
print LOG "--------------------------post processing----------------------------------------------\n";
print LOG localtime() . "\n";
print LOG "$self->{output}\n";
close LOG;
}
# backspace
@ -173,12 +173,12 @@ sub show_output {
my $output = $self->{output};
unless ($self->{got_run} and $self->{copy_code}) {
open FILE, ">> $RealBin/../log.txt";
print FILE "------------------------show output------------------------------------------------\n";
print FILE localtime() . "\n";
print FILE "$output\n";
print FILE "========================================================================\n";
close FILE;
open LOG, ">> $RealBin/../log.txt";
print LOG "------------------------show output------------------------------------------------\n";
print LOG localtime() . "\n";
print LOG "$output\n";
print LOG "========================================================================\n";
close LOG;
}
if (exists $self->{options}->{'-paste'} or (defined $self->{got_run} and $self->{got_run} eq 'paste')) {
@ -237,17 +237,17 @@ sub show_output {
exit 0;
}
if($self->{channel} =~ m/^#/ and length $output > 22 and open FILE, "< $RealBin/../history/$self->{channel}-$self->{lang}.last-output") {
if($self->{channel} =~ m/^#/ and length $output > 22 and open LOG, "< $RealBin/../history/$self->{channel}-$self->{lang}.last-output") {
my $last_output;
my $time = <FILE>;
my $time = <LOG>;
if(gettimeofday - $time > 60 * 4) {
close FILE;
close LOG;
} else {
while(my $line = <FILE>) {
while(my $line = <LOG>) {
$last_output .= $line;
}
close FILE;
close LOG;
if((not $self->{factoid}) and defined $last_output and $last_output eq $output) {
print "Same output.\n";
@ -258,11 +258,11 @@ sub show_output {
print "$output\n";
open FILE, "> $RealBin/../history/$self->{channel}-$self->{lang}.last-output" or die "Couldn't open $self->{channel}-$self->{lang}.last-output: $!";
open LOG, "> $RealBin/../history/$self->{channel}-$self->{lang}.last-output" or die "Couldn't open $self->{channel}-$self->{lang}.last-output: $!";
my $now = gettimeofday;
print FILE "$now\n";
print FILE "$output";
close FILE;
print LOG "$now\n";
print LOG "$output";
close LOG;
}
sub paste_ixio {
@ -359,12 +359,7 @@ sub execute {
$cmdline =~ s/\$sourcefile/$self->{sourcefile}/g;
$cmdline =~ s/\$execfile/$self->{execfile}/g;
my $options;
if (length $self->{cmdline_options}) {
$options = $self->{cmdline_options};
} else {
$options = $self->{default_options};
}
my $options = length $self->{cmdline_options} ? $self->{cmdline_options} : $self->{default_options};
if ((not exists $self->{options}->{'-paste'}) and (not defined $self->{got_run} or $self->{got_run} ne 'paste')) {
if (exists $self->{options_nopaste}) {
@ -384,10 +379,10 @@ sub execute {
$cmdline =~ s/\$options\s+//;
}
open FILE, ">> $RealBin/../log.txt";
print FILE "---------------------executing---------------------------------------------------\n";
print FILE localtime() . "\n";
print FILE "$cmdline\n$stdin\n$pretty_code\n";
open LOG, ">> $RealBin/../log.txt";
print LOG "---------------------executing---------------------------------------------------\n";
print LOG localtime() . "\n";
print LOG "$cmdline\n$stdin\n$pretty_code\n";
my $compile_in = {
lang => $self->{lang},
@ -404,9 +399,7 @@ sub execute {
$compile_in->{'persist-key'} = $self->{'persist-key'} if length $self->{'persist-key'};
my $compile_json = encode_json($compile_in);
print STDERR "outgoing json: $compile_json\n";
$compile_json .= encode('UTF-8', "\n:end:\n");
print STDERR "outgoing json after concat: $compile_json\n";
my $length = length $compile_json;
my $sent = 0;
@ -414,42 +407,40 @@ sub execute {
my $chunk_size = $length < $chunk_max ? $length : $chunk_max;
my $chunks_sent = 0;
#print FILE "Sending $length bytes [$compile_json] to vm_server\n";
#print LOG "Sending $length bytes [$compile_json] to vm_server\n";
$chunk_size -= 1; # account for newline in syswrite
while ($chunks_sent < $length) {
my $chunk = substr $compile_json, $chunks_sent, $chunk_size;
#print FILE "Sending chunk [$chunk]\n";
#print LOG "Sending chunk [$chunk]\n";
$chunks_sent += length $chunk;
my $ret = syswrite($vm, $chunk);
if (not defined $ret) {
print FILE "Error sending: $!\n";
print LOG "Error sending: $!\n";
last;
}
if ($ret == 0) {
print FILE "Sent 0 bytes. Sleep 1 sec and try again\n";
print LOG "Sent 0 bytes. Sleep 1 sec and try again\n";
sleep 1;
next;
}
$sent += $ret;
print FILE "Sent $ret bytes, so far $sent ...\n";
print LOG "Sent $ret bytes, so far $sent ...\n";
}
#print FILE "Done sending!\n";
close FILE;
#print LOG "Done sending!\n";
close LOG;
my $result = "";
my $got_result = 0;
while(my $line = <$vm_output>) {
utf8::decode($line);
print STDERR "Read from vm [$line]\n";
$line =~ s/[\r\n]+$//;
last if $line =~ /^result:end$/;
@ -489,10 +480,6 @@ sub process_standard_options {
my @opt_args = $self->split_line($self->{code}, preserve_escapes => 1, keep_spaces => 0);
use Data::Dumper;
print STDERR "code:\n$self->{code}\n";
print STDERR "opt_arg: ", Dumper \@opt_args;
my $getopt_error;
local $SIG{__WARN__} = sub {
$getopt_error = shift;
@ -570,9 +557,9 @@ sub process_interactive_edit {
if($subcode =~ s/^\s*copy\s+(\S+)\s*//) {
my $copy = $1;
if(open FILE, "< $RealBin/../history/$copy-$self->{lang}.hist") {
$copy_code = <FILE>;
close FILE;
if(open LOG, "< $RealBin/../history/$copy-$self->{lang}.hist") {
$copy_code = <LOG>;
close LOG;
goto COPY_ERROR if not $copy_code;;
chomp $copy_code;
} else {
@ -595,12 +582,12 @@ sub process_interactive_edit {
$self->{channel} = $1;
}
if(open FILE, "< $RealBin/../history/$self->{channel}-$self->{lang}.hist") {
while(my $line = <FILE>) {
if(open LOG, "< $RealBin/../history/$self->{channel}-$self->{lang}.hist") {
while(my $line = <LOG>) {
chomp $line;
push @last_code, $line;
}
close FILE;
close LOG;
}
unshift @last_code, $copy_code if defined $copy_code;
@ -1019,15 +1006,15 @@ sub process_interactive_edit {
unshift @last_code, $code;
}
open FILE, "> $RealBin/../history/$self->{channel}-$self->{lang}.hist";
open LOG, "> $RealBin/../history/$self->{channel}-$self->{lang}.hist";
my $i = 0;
foreach my $line (@last_code) {
last if(++$i > $self->{max_history});
print FILE "$line\n";
print LOG "$line\n";
}
close FILE;
close LOG;
}
if ($got_diff) {