<commit_before>package org.hildan.bots.riseoflords;

import java.io.Console;
import java.io.IOException;
import java.time.Duration;

import org.hildan.bots.riseoflords.config.Config;
import org.hildan.bots.riseoflords.config.Config.BadConfigException;
import org.hildan.bots.riseoflords.sequencing.LoginException;
import org.hildan.bots.riseoflords.sequencing.Sequence;
import org.hildan.bots.riseoflords.util.Log;

public class RolAutomizer {

    private static final String TAG = RolAutomizer.class.getSimpleName();

    public static void main(String[] args) {
        try {
            launch(args);
        } catch (LoginException e) {
            Log.get().e(TAG, "\nLogin failed for user ", e.getUsername());
        } catch (Exception e) {
            Log.get().e(TAG, "\nUNCAUGHT EXCEPTION: ", e.getMessage());
            e.printStackTrace(System.err);
        }
        waitForEnter(null);
    }

    private static void launch(String[] args) throws LoginException {
        if (args.length == 0) {
            System.out.println("No config file provided: you must provide a .rol file to open.");
            System.out.println();
            System.out.println("More info at https://github.com/joffrey-bion/rol-automizer");
            return;
        }
        final String filename = args[0];

        Config config;
        try {
            config = Config.loadFromFile(filename);
        } catch (final BadConfigException e) {
            Log.get().e(TAG, "Error reading config file: ", e.getMessage());
            return;
        } catch (final IOException e) {
            try {
                config = Config.loadFromResource(filename);
            } catch (IOException | BadConfigException e2) {
                Log.get().e(TAG, "Error reading config file: ", e.getMessage());
                return;
            }
        }
        Log.get().title(TAG, "CONFIG");
        Log.get().i(TAG, config);
        System.out.println();

        final Sequence sequence = new Sequence(config);
        for (int i = 0; config.unlimitedAttacks() || i < config.getNbOfAttacks(); i++) {
            Log.get().title(TAG, String.format("ATTACK SESSION %d/%d", i + 1, config.getNbOfAttacks()));
            sequence.start();
            if (config.unlimitedAttacks() || i + 1 < config.getNbOfAttacks()) {
                // more attacks are waiting
                System.out.println();
                waitForNextAttack(config.getTimeBetweenAttacks());
            }
        }
        System.out.println();
        Log.get().i(TAG, "End of attacks.");
    }

    private static void waitForEnter(String message, Object... args) {
        final Console c = System.console();
        if (c != null) {
            if (message != null) {
                c.format(message, args);
            } else {
                c.format("\nPress ENTER to exit.\n");
            }
            c.readLine();
        }
    }

    private static void waitForNextAttack(Duration duration) {
        try {
            long millis = duration.toMillis() % 1000;
            Thread.sleep(millis);
            duration = duration.minusMillis(millis);<commit_msg>Move exception catch to the sequence so that the whole execution doesn't stop<commit_after>package org.hildan.bots.riseoflords;

import java.io.Console;
import java.io.IOException;
import java.time.Duration;

import org.hildan.bots.riseoflords.config.Config;
import org.hildan.bots.riseoflords.config.Config.BadConfigException;
import org.hildan.bots.riseoflords.sequencing.LoginException;
import org.hildan.bots.riseoflords.sequencing.Sequence;
import org.hildan.bots.riseoflords.util.Log;

public class RolAutomizer {

    private static final String TAG = RolAutomizer.class.getSimpleName();

    public static void main(String[] args) {
        launch(args);
        waitForEnter(null);
    }

    private static void launch(String[] args) {
        if (args.length == 0) {
            System.out.println("No config file provided: you must provide a .rol file to open.");
            System.out.println();
            System.out.println("More info at https://github.com/joffrey-bion/rol-automizer");
            return;
        }
        final String filename = args[0];

        Config config;
        try {
            config = Config.loadFromFile(filename);
        } catch (final BadConfigException e) {
            Log.get().e(TAG, "Error reading config file: ", e.getMessage());
            return;
        } catch (final IOException e) {
            try {
                config = Config.loadFromResource(filename);
            } catch (IOException | BadConfigException e2) {
                Log.get().e(TAG, "Error reading config file: ", e.getMessage());
                return;
            }
        }
        Log.get().title(TAG, "CONFIG");
        Log.get().i(TAG, config);
        System.out.println();

        final Sequence sequence = new Sequence(config);
        for (int i = 0; config.unlimitedAttacks() || i < config.getNbOfAttacks(); i++) {
            Log.get().title(TAG, String.format("ATTACK SESSION %d/%d", i + 1, config.getNbOfAttacks()));
            try {
                sequence.start();
            } catch (LoginException e) {
                Log.get().e(TAG, "\nLogin failed for user ", e.getUsername());
            } catch (Exception e) {
                Log.get().e(TAG, "\nUNCAUGHT EXCEPTION: ", e.getMessage());
                e.printStackTrace(System.err);
            }
            if (config.unlimitedAttacks() || i + 1 < config.getNbOfAttacks()) {
                // more attacks are waiting
                System.out.println();
                waitForNextAttack(config.getTimeBetweenAttacks());
            }
        }
        System.out.println();
        Log.get().i(TAG, "End of attacks.");
    }

    private static void waitForEnter(String message, Object... args) {
        final Console c = System.console();
        if (c != null) {
            if (message != null) {
                c.format(message, args);
            } else {
                c.format("\nPress ENTER to exit.\n");
            }
            c.readLine();
        }
    }

    private static void waitForNextAttack(Duration duration) {
        try {
            long millis = duration.toMillis() % 1000;
            Thread.sleep(millis);
            duration = duration.minusMillis(millis);
{'fraction_non_alphanumeric': 0.12527507073247407, 'fraction_numerical': 0.0031436655139893115, 'mean_word_length': 2.005668398677374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4330944', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1762, 'n_words': 405}