<commit_before>const Command = require("../base/Command");

class GrandArena extends Command {
    constructor(Bot) {
        super(Bot, {
            name: "grandarena",
            category: "SWGoH",
            enabled: true,
            aliases: ["ga"],
            permissions: ["EMBED_LINKS"],
            subArgs: {
                faction: {
                    aliases: ["fact", "f"]
                }
            }
        });
    }

    async run(Bot, message, [user1str, user2str, ...characters], options) { // eslint-disable-line no-unused-vars
        const problemArr = [];

        // Make sure the userStrings are valid
        if (!user1str || (user1str !== "me" && !Bot.isAllyCode(user1str) && !Bot.isUserID(user1str))) {
            problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 1));
        }
        if (!user2str || (user2str !== "me" && !Bot.isAllyCode(user2str) && !Bot.isUserID(user2str))) {
            problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 2));
        }
        if (problemArr.length) {
            return super.error(message, Bot.codeBlock(problemArr.map(p => "* " + p).join("\n")));
        }

        // Get the first user's ally code if possible
        let user1 = await super.getUser(message, user1str, false);
        if (!user1) {
            if (user1str === "me") {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_UNREGISTERED", message.guildSettings.prefix));
            } else {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 1));
            }
        }

        // Get the second user's ally code if possible
        let user2 = await super.getUser(message, user2str, false);
        if (!user2) {
            if (user2str === "me") {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_UNREGISTERED", message.guildSettings.prefix));
            } else {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 2));
            }
        }

        // If they're looking for specific characters, do what we can to get matches for them
        let charOut = [];
        if (characters.length) {
            characters = characters.join(" ").split("|").map(c => c.trim());
            for (const char of characters) {
                let chars = Bot.findChar(char, Bot.characters);
                if (!chars.length) {
                    // If it didn't find a matching character, try checking the ships
                    chars = Bot.findChar(char, Bot.ships, true);
                }
                if (!chars.length) {
                    // It could not find any matches, so let em know
                    problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_CHAR", char));
                } else {
                    // It found at least one matching character
                    chars.forEach(c => {
                        charOut.push(c.uniqueName);
                    });
                }
            }
        }

        const cooldown = await Bot.getPlayerCooldown(message.author.id);
        if (!problemArr.length) {
            // If there are no problems, go ahead and pull the users
            try {
                user1 = await Bot.swgohAPI.unitStats(user1, cooldown);
                if (Array.isArray(user1)) user1 = user1[0];
            } catch (e) {
                problemArr.push(e.message);
            }
            try {
                user2 = await Bot.swgohAPI.unitStats(user2, cooldown);
                if (Array.isArray(user2)) user2 = user2[0];
            } catch (e) {
                problemArr.push(e.message);
            }
            if (!user1?.roster?.length) {
                problemArr.push("Could not get user 1");
            }
            if (!user2?.roster?.length) {
                problemArr.push("Could not get user 2");
            }
        }
        if (problemArr.length) {
            // Otherwise, spit out the list of issues
            return super.error(message, Bot.codeBlock(problemArr.map(p => "* " + p).join("\n")));
        }

        // If there are no problems, continue
        const checkArr = {};

        // Localized labels for each row
        const labels = message.language.get("COMMAND_GRANDARENA_COMP_NAMES");

        // Set of default characters to show
        let charArr = [
            "COMMANDERLUKESKYWALKER",
            "ENFYSNEST",
            "GENERALKENOBI",
            "GENERALSKYWALKER",
            "GRANDMASTERYODA",
            "HANSOLO",
            "ANAKINKNIGHT",
            "JEDIKNIGHTREVAN",
            "PADMEAMIDALA",
            "R2D2_LEGENDARY",
            "REYJEDITRAINING",
            "BASTILASHANDARK",
            "BOSSK",
            "DARTHMALAK",
            "DARTHREVAN",
            "DARTHTRAYA",
            "EMPERORPALPATINE",
            "GRIEVOUS",
            "GRANDADMIRALTHRAWN",
            "KYLORENUNMASKED",
            "MOTHERTALZIN"
        ];

        // In case the user wants to look for charcters from a specific faction
        if (options.subArgs.faction) {
            const fact = Bot.findFaction(options.subArgs.faction);
            if (Array.isArray(fact)) {
                fact.forEach(f => {
                    charOut = charOut.concat(Bot.characters.filter(c => c.factions.find(ch => ch.toLowerCase() === f)).map(c => c.uniqueName));
                });
            } else if (fact) {
                charOut = charOut.concat(Bot.characters.filter(c => c.factions.find(ch => ch.toLowerCase() === fact)).map(c => c.uniqueName));
            } else {
                return super.error(message, "Sorry, but I did not find a match for the faction: `" + options.subArgs.faction + "`");
            }
        }

        // Get rid of any duplicates in case
        if (charOut.length) {
            charArr = [...new Set(charOut)];
        }

        let overview = [];
        const charList = Bot.characters.map(c => c.uniqueName);
        const shipList = Bot.ships.map(s => s.uniqueName);

        overview.push({
            check: labels.charGP,
            user1: user1.roster.reduce((a, b) => a + (charList.indexOf(b.defId) > -1 ? b.gp : 0), 0).shortenNum(2),
            user2: user2.roster.reduce((a, b) => a + (charList.indexOf(b.defId) > -1 ? b.gp : 0), 0).shortenNum(2)
        });
        overview.push({
            check: labels.shipGP,
            user1: user1.roster.reduce((a, b) => a + (shipList.indexOf(b.defId) > -1 ? b.gp : 0), 0).shortenNum(2),
            user2: user2.roster.reduce((a, b) => a + (shipList.indexOf(b.defId) > -1 ? b.gp : 0), 0).shortenNum(2)
        });
        if (user1.arena && user2.arena) {
            if (user1.arena.char && user2.arena.char) {<commit_msg>Some more cleanup in ;ga<commit_after>const Command = require("../base/Command");

class GrandArena extends Command {
    constructor(Bot) {
        super(Bot, {
            name: "grandarena",
            category: "SWGoH",
            enabled: true,
            aliases: ["ga"],
            permissions: ["EMBED_LINKS"],
            subArgs: {
                faction: {
                    aliases: ["fact", "f"]
                }
            }
        });
    }

    async run(Bot, message, [user1str, user2str, ...characters], options) { // eslint-disable-line no-unused-vars
        const problemArr = [];

        // Make sure the userStrings are valid
        if (!user1str || (user1str !== "me" && !Bot.isAllyCode(user1str) && !Bot.isUserID(user1str))) {
            problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 1));
        }
        if (!user2str || (user2str !== "me" && !Bot.isAllyCode(user2str) && !Bot.isUserID(user2str))) {
            problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 2));
        }
        if (problemArr.length) {
            return super.error(message, Bot.codeBlock(problemArr.map(p => "* " + p).join("\n")));
        }

        // Get the first user's ally code if possible
        let user1 = await super.getUser(message, user1str, false);
        if (!user1) {
            if (user1str === "me") {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_UNREGISTERED", message.guildSettings.prefix));
            } else {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 1));
            }
        }

        // Get the second user's ally code if possible
        let user2 = await super.getUser(message, user2str, false);
        if (!user2) {
            if (user2str === "me") {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_UNREGISTERED", message.guildSettings.prefix));
            } else {
                problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_USER", 2));
            }
        }

        // If they're looking for specific characters, do what we can to get matches for them
        let charOut = [];
        if (characters.length) {
            characters = characters.join(" ").split("|").map(c => c.trim());
            for (const char of characters) {
                let chars = Bot.findChar(char, Bot.characters);
                if (!chars.length) {
                    // If it didn't find a matching character, try checking the ships
                    chars = Bot.findChar(char, Bot.ships, true);
                }
                if (!chars.length) {
                    // It could not find any matches, so let em know
                    problemArr.push(message.language.get("COMMAND_GRANDARENA_INVALID_CHAR", char));
                } else {
                    // It found at least one matching character
                    chars.forEach(c => {
                        charOut.push(c.uniqueName);
                    });
                }
            }
        }

        const cooldown = await Bot.getPlayerCooldown(message.author.id);
        if (!problemArr.length) {
            // If there are no problems, go ahead and pull the users
            try {
                user1 = await Bot.swgohAPI.unitStats(user1, cooldown);
                if (Array.isArray(user1)) user1 = user1[0];
            } catch (e) {
                problemArr.push(e.message);
            }
            try {
                user2 = await Bot.swgohAPI.unitStats(user2, cooldown);
                if (Array.isArray(user2)) user2 = user2[0];
            } catch (e) {
                problemArr.push(e.message);
            }
            if (!user1?.roster?.length) {
                problemArr.push("Could not get user 1");
            }
            if (!user2?.roster?.length) {
                problemArr.push("Could not get user 2");
            }
        }
        if (problemArr.length) {
            // Otherwise, spit out the list of issues
            return super.error(message, Bot.codeBlock(problemArr.map(p => "* " + p).join("\n")));
        }

        // If there are no problems, continue
        const checkArr = {};

        // Localized labels for each row
        const labels = message.language.get("COMMAND_GRANDARENA_COMP_NAMES");

        // Set of default characters to show
        let charArr = [
            "COMMANDERLUKESKYWALKER",
            "ENFYSNEST",
            "GENERALKENOBI",
            "GENERALSKYWALKER",
            "GRANDMASTERYODA",
            "HANSOLO",
            "ANAKINKNIGHT",
            "JEDIKNIGHTREVAN",
            "PADMEAMIDALA",
            "R2D2_LEGENDARY",
            "REYJEDITRAINING",
            "BASTILASHANDARK",
            "BOSSK",
            "DARTHMALAK",
            "DARTHREVAN",
            "DARTHTRAYA",
            "EMPERORPALPATINE",
            "GRIEVOUS",
            "GRANDADMIRALTHRAWN",
            "KYLORENUNMASKED",
            "MOTHERTALZIN"
        ];

        // Quick mapping of gp to how many teams are needed
        // const gpMap = {
        //     //        |   General stuff   |        5v5 Specific stuff           |        3v3 Specific Stuff
        //     7800000: { div: 1,  fleets: 2, teams5: 11, topX5: 110, kyber5: 44900, teams3: 15, topX3: 90, kyber3: 53200 },
        //     6650000: { div: 2,  fleets: 2, teams5: 10, topX5: 100, kyber5: 43100, teams3: 14, topX3: 84, kyber3: 51400 },
        //     6000000: { div: 3,  fleets: 2, teams5: 9,  topX5: 90,  kyber5: 40000, teams3: 13, topX3: 78, kyber3: 51400 },
        //     5150000: { div: 4,  fleets: 2, teams5: 9,  topX5: 90,  kyber5: 40000, teams3: 12, topX3: 72, kyber3: 50500 },
        //     4500000: { div: 5,  fleets: 2, teams5: 7,  topX5: 70,  kyber5: 34700, teams3: 11, topX3: 66, kyber3: 43500 },
        //     3850000: { div: 6,  fleets: 2, teams5: 7,  topX5: 70,  kyber5: 34700, teams3: 11, topX3: 66, kyber3: 42300 },
        //     3100000: { div: 7,  fleets: 2, teams5: 7,  topX5: 70,  kyber5: 33000, teams3: 10, topX3: 60, kyber3: 39600 },
        //     2300000: { div: 8,  fleets: 1, teams5: 6,  topX5: 60,  kyber5: 29500, teams3: 8,  topX3: 48, kyber3: 32100 },
        //     1600000: { div: 9,  fleets: 1, teams5: 5,  topX5: 50,  kyber5: 27700, teams3: 7,  topX3: 42, kyber3: 30300 },
        //     1000000: { div: 10, fleets: 1, teams5: 4,  topX5: 40,  kyber5: 25800, teams3: 4,  topX3: 24, kyber3: 23300 },
        //     0:       { div: 11, fleets: 1, teams5: 3,  topX5: 30,  kyber5: 24000, teams3: 3,  topX3: 18, kyber3: 21500 }
        // };

        // In case the user wants to look for charcters from a specific faction
        if (options.subArgs.faction) {
            const fact = Bot.findFaction(options.subArgs.faction);
            if (Array.isArray(fact)) {
                fact.forEach(f => {
                    charOut = charOut.concat(Bot.characters.filter(c => c.factions.find(ch => ch.toLowerCase() === f)).map(c => c.uniqueName));
                });
            } else if (fact) {
                charOut = charOut.concat(Bot.characters.filter(c => c.factions.find(ch => ch.toLowerCase() === fact)).map(c => c.uniqueName));
            } else {
                return super.error(message, "Sorry, but I did not find a match for the faction: `" + options.subArgs.faction + "`");
            }
        }

        // Get rid of any duplicates in case
        if (charOut.length) {
            charArr = [...new Set(charOut)];
        }

        let overview = [];
        const user1CharRoster = user1.roster.filter(ch => ch.combatType === 1);
        const user2CharRoster = user2.roster.filter(ch => ch.combatType === 1);

        const user1ShipRoster = user1.roster.filter(ch => ch.combatType === 2);
        const user2ShipRoster = user1.roster.filter(ch => ch.combatType === 2);

        // Quick little function to add up all the gp frm a given chunk of roster
        const sumGP = (rosterIn) => {
            return rosterIn.reduce((a, b) => a + b.gp, 0).shortenNum(2);
        };

        overview.push({
            check: "Ttl GP",
            user1: sumGP(user1.roster),
            user2: sumGP(user2.roster)
        });
        overview.push({
            check: labels.charGP,
            user1: sumGP(user1CharRoster),
            user2: sumGP(user2CharRoster)
        });
        overview.push({
            check: labels.shipGP,
            user1: sumGP(user1ShipRoster),
            user2: sumGP(user2ShipRoster)
        });
        if (user1.arena && user2.arena) {
            if (user1.arena.char && user2.arena.char) {
{'fraction_non_alphanumeric': 0.13049957882459665, 'fraction_numerical': 0.03175014579148578, 'mean_word_length': 1.6697803148244248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '3789896', 'n_tokens_mistral': 5137, 'n_tokens_neox': 4712, 'n_words': 1063}