<commit_before>#!/usr/bin/perl

#requres json
#apt-get install libjson-perl libconfig-simple-perl

use strict;
use JSON::XS;
use Config::Simple;


my @binding_templates = ();
my @extension_templates = ();

my $conf;
our $saved_values;

sub ask_multi {
	my $params = shift;
	my $question = $params->{'question'};
	my $values = $params->{'values'};
	my $save_key = $params->{'save_key'};


	my $save_value;
       	if (defined $save_key) {
		$save_value = $saved_values->param($save_key);
	}

	print "\n$question:\n";
	if (defined $values) {
		print "\nSpecify the number of each value you want separated by a space:\n";
		my $i = 0;

		foreach my $value (@$values) {
			print "\t$i - $value\n";
			$i++;
		}
	}
	print "\n";

	print ">";

	my $value;

	if (defined $save_value) {
		if (ref($save_value) eq 'ARRAY') {
			print join(" ", @$save_value) . "\n";
			$value=$save_value;
		} else {
			print "$save_value\n";
			$value=[$save_value];
		}
	} else {
		my $answer = <>;
		chomp($answer);

		my @answer_list = ();

		foreach my $ans (split(/ /, $answer)) {
			push @answer_list, $values->[$ans];
		}

		$value = \@answer_list;

	}

	return $value;
}

sub ask {
	my $params = shift;
	my $question = $params->{'question'};
	my $values = $params->{'values'};
	my $default = $params->{'default'};
	my $save_key = $params->{'save_key'};


	my $save_value;
       	if ($save_key) {
		$save_value = $saved_values->param($save_key);
	}

	print "\n$question:\n";
	if (defined $values) {
		print "\nPossible Values:\n";

		foreach my $value (@$values) {
			print "\t$value\n";
		}
	}
	print "\n";

	my $value = $default;

	if (defined $value) {
		print "[$value]>";
	} else {
		print ">";
	}

	if (defined $save_value) {
		print "$save_value\n";
		$value=$save_value;
	} else {
		my $answer = <>;
		chomp($answer);

		if ($answer ne "") {
			$value = $answer;
		}

		if ($save_key) {
			$saved_values->param($save_key, $value);
		}
	}

	return $value;
}

sub makeBindings {
	my @bindings = ();
	foreach my $binding (@binding_templates) {
		my $b;
		$b->{'name'} = $binding->{'name'};
		$b->{'className'} = $binding->{'className'};
		push @bindings, $b;
	}
	$conf->{'bindings'} = \@bindings;
	
}


our @serverList = ();

sub makeRooms {
	my $type = shift;
	my $no_rooms= ask({question=>"Number of rooms for $type to join", save_key=>"binding.$type.no_rooms"});

	my @rooms;
	for (my $i = 1; $i <= $no_rooms; $i++) {
		my %room;
		$room{"name"} = ask({question=>"Name for room $i of $type", save_key=>"binding.$type.rooms.$i.name"});
		$room{"nickname"} = ask({question=>"Nickname to use in room $i of $type", save_key=>"binding.$type.rooms.$i.nickname"});
		push @rooms, \%room;
	}
	return \@rooms;
}

sub makeCommands {
	my $type = shift;
	my @commands;
	foreach my $extension (@extension_templates) {
		my $command_name = $extension->{'name'};
		my $use_command = ask({question=>"Add command '$command_name' to $type", values=>["Y", "N"], default=>"Y", save_key=>"binding.$type.command.$command_name.enable"});

		if (uc($use_command) eq "Y") {
			my %command;
			$command{"name"} = $command_name;
			$command{"className"} = $extension->{'className'};

			if (defined $extension->{'configuration'}) {
				if ($extension->{'immutable'}) {
					$command{"configuration"} = $extension->{'configuration'};
				} else {
					my $configuration = $extension->{'configuration'};
					foreach my $conf (keys $configuration) {
						$command{"configuration"}{$conf} = ask({question=>"value for '$conf' for $command_name command of $type", default=>$configuration->{$conf}, save_key=>"binding.$type.command.$command_name.$conf"});
					}
				}
			}
			push @commands, \%command;
		}
	}
	return \@commands;
}

sub makeServer {
	my @serverKeys = ('url', 'serverName', 'port', 'username', 'password', 'identifier', "commandPrefix", "debug");

	my $serverConfig = { 'debug' => "false", "commandPrefix"=>"!" };

	my $type = shift;

	$serverConfig->{'type'} = $type;

	my $binding;
	foreach $b (@binding_templates) {
		if ($b->{'name'} eq $type) {
			$binding = $b;
			last;
		}
	}
<commit_msg>make genconf more sensitive to data type<commit_after>#!/usr/bin/perl

#requres json
#apt-get install libjson-perl libconfig-simple-perl

use strict;
use JSON::XS;
use Config::Simple;
use Scalar::Util qw(looks_like_number);


my @binding_templates = ();
my @extension_templates = ();

my $conf;
our $saved_values;

sub to_bool {
	my $val = shift;

	if ($val eq "true" || $val == 1) {
		return JSON::XS::true;
	} else {
		return JSON::XS::false;
	}
}

sub ask_multi {
	my $params = shift;
	my $question = $params->{'question'};
	my $values = $params->{'values'};
	my $save_key = $params->{'save_key'};


	my $save_value;
       	if (defined $save_key) {
		$save_value = $saved_values->param($save_key);
	}

	print "\n$question:\n";
	if (defined $values) {
		print "\nSpecify the number of each value you want separated by a space:\n";
		my $i = 0;

		foreach my $value (@$values) {
			print "\t$i - $value\n";
			$i++;
		}
	}
	print "\n";

	print ">";

	my $value;

	if (defined $save_value) {
		if (ref($save_value) eq 'ARRAY') {
			print join(" ", @$save_value) . "\n";
			$value=$save_value;
		} else {
			print "$save_value\n";
			$value=[$save_value];
		}
	} else {
		my $answer = <>;
		chomp($answer);

		my @answer_list = ();

		foreach my $ans (split(/ /, $answer)) {
			push @answer_list, $values->[$ans];
		}

		$value = \@answer_list;

	}

	return $value;
}

sub ask {
	my $params = shift;
	my $question = $params->{'question'};
	my $values = $params->{'values'};
	my $default = $params->{'default'};
	my $save_key = $params->{'save_key'};


	my $save_value;
       	if ($save_key) {
		$save_value = $saved_values->param($save_key);
	}

	print "\n$question:\n";
	if (defined $values) {
		print "\nPossible Values:\n";

		foreach my $value (@$values) {
			print "\t$value\n";
		}
	}
	print "\n";

	my $value = $default;

	if (defined $value) {
		print "[$value]>";
	} else {
		print ">";
	}

	if (defined $save_value) {
		print "$save_value\n";
		$value = $save_value;
	} else {
		my $answer = <>;
		chomp($answer);

		if ($answer ne "") {
			$value = $answer;
		}

		if ($save_key) {
			$saved_values->param($save_key, $value);
		}
	}

	# fix the type
	if (defined $default && JSON::XS::is_bool($default)) {
		$value = to_bool($value);
	} else {
		if (looks_like_number($default)) {
			$value = $value +0;
		} 
	}

	return $value;
}

sub makeBindings {
	my @bindings = ();
	foreach my $binding (@binding_templates) {
		my $b;
		$b->{'name'} = $binding->{'name'};
		$b->{'className'} = $binding->{'className'};
		push @bindings, $b;
	}
	$conf->{'bindings'} = \@bindings;
	
}


our @serverList = ();

sub makeRooms {
	my $type = shift;
	my $no_rooms= ask({question=>"Number of rooms for $type to join", save_key=>"binding.$type.no_rooms"});

	my @rooms;
	for (my $i = 1; $i <= $no_rooms; $i++) {
		my %room;
		$room{"name"} = ask({question=>"Name for room $i of $type", save_key=>"binding.$type.rooms.$i.name"});
		$room{"nickname"} = ask({question=>"Nickname to use in room $i of $type", save_key=>"binding.$type.rooms.$i.nickname"});
		push @rooms, \%room;
	}
	return \@rooms;
}

sub makeCommands {
	my $type = shift;
	my @commands;
	foreach my $extension (@extension_templates) {
		my $command_name = $extension->{'name'};
		my $use_command = ask({question=>"Add command '$command_name' to $type", values=>["Y", "N"], default=>"Y", save_key=>"binding.$type.command.$command_name.enable"});

		if (uc($use_command) eq "Y") {
			my %command;
			$command{"name"} = $command_name;
			$command{"className"} = $extension->{'className'};

			if (defined $extension->{'configuration'}) {
				if ($extension->{'immutable'}) {
					$command{"configuration"} = $extension->{'configuration'};
				} else {
					my $configuration = $extension->{'configuration'};
					foreach my $conf (keys $configuration) {
						$command{"configuration"}{$conf} = ask({question=>"value for '$conf' for $command_name command of $type", default=>$configuration->{$conf}, save_key=>"binding.$type.command.$command_name.$conf"});
					}
				}
			}
			push @commands, \%command;
		}
	}
	return \@commands;
}

sub makeServer {
	my @serverKeys = ('url', 'serverName', 'port', 'username', 'password', 'identifier', "commandPrefix", "debug");

	my $serverConfig = { 'debug' => JSON::XS::false, "commandPrefix"=>"!" };

	my $type = shift;

	$serverConfig->{'type'} = $type;

	my $binding;
	foreach $b (@binding_templates) {
		if ($b->{'name'} eq $type) {
			$binding = $b;
			last;
		}
	}

{'fraction_non_alphanumeric': 0.2089289899226623, 'fraction_numerical': 0.0007030700726505742, 'mean_word_length': 3.7976391231028668, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1936809', 'n_tokens_mistral': 3475, 'n_tokens_neox': 3147, 'n_words': 743}