<commit_before>const Discord = require("discord.js");
const moment = require("moment-timezone");
require("moment-duration-format");
const {promisify, inspect} = require("util");     // eslint-disable-line no-unused-vars
const fs = require("fs");
const readdir = promisify(require("fs").readdir);

module.exports = (Bot, client) => {
    Bot.constants = {
        // The main invite for the support server
        invite: "https://discord.com/invite/FfwGvhr",

        // Zero width space
        zws: "\u200B",

        // Some normal color codes
        colors: {
            black:  "#000000",
            blue:   "#0000FF",
            green:  "#00FF00",
            red:    "#FF0000",
            white:  "#FFFFFF",
            yellow: "#FFFF00",
        }
    };

    // Permissions mapping
    const permMap = {
        // Can do anything, access to the dev commands, etc
        BOT_OWNER: 10,

        // Can help out with the bot as needed, some extra stuff possibly
        HELPER: 8,

        // Owner of the server a command is being run in
        GUILD_OWNER: 7,

        // Has ADMIN or MANAGE_GUILD, or has one of the
        // configured roles from the guild's settings
        GUILD_ADMIN: 6,

        // Base users, anyone that's not included above
        BASE_USER: 0
    };

    /*  PERMISSION LEVEL FUNCTION
     *  This is a very basic permission system for commands which uses "levels"
     *  "spaces" are intentionally left black so you can add them if you want.
     *  NEVER GIVE ANYONE BUT OWNER THE LEVEL 10! By default this can run any
     *  command including the VERY DANGEROUS `eval` and `exec` commands!
     */
    Bot.permlevel = message => {
        let permlvl = 0;

        // Depending on message or interaction, grab the ID of the user
        const authId = message.author ? message.author.id : message.user.id;

        // If bot owner, return max perm level
        if (authId === Bot.config.ownerid) {
            return permMap.BOT_OWNER;
        }

        // If DMs or webhook, return 0 perm level.
        if (!message.guild || !message.member) {
            return permMap.BASE_USER;
        }
        const guildConf = message.guildSettings;

        // Guild Owner gets an extra level, wooh!
        const gOwner = message.guild.fetchOwner();
        if (message.channel.type === "text" && message.guild && gOwner) {
            if (message.author.id === gOwner.id) {
                return permMap.GUILD_OWNER;
            }
        }

        // Also giving them the permissions if they have the manage server role,
        // since they can change anything else in the server, so no reason not to
        if (message.member.permissions.has(["ADMINISTRATOR"]) || message.member.permissions.has(["MANAGE_GUILD"])) {
            return permMap.GUILD_ADMIN;
        }

        // The rest of the perms rely on roles. If those roles are not found
        // in the settings, or the user does not have it, their level will be 0
        try {
            const adminRoles = guildConf.adminRole;

            for (var ix = 0, len = adminRoles.length; ix < len; ix++) {
                const adminRole = message.guild.roles.cache.find(r => r.name.toLowerCase() === adminRoles[ix].toLowerCase() || r.id === adminRoles[ix]);
                if (adminRole && message.member.roles.cache.has(adminRole.id)) {
                    return permlvl = permMap.GUILD_ADMIN;
                }
            }
        } catch (e) {() => {};}
        return permlvl;
    };

    // Default formatting for current US/Pacific time
    Bot.myTime = () => {
        return moment.tz("US/Pacific").format("M/D/YYYY h:mma");
    };

    // This finds any character that matches the search, and returns them in an array
    Bot.findChar = (searchName, charList, ship=false) => {
        if (!searchName?.length || typeof searchName !== "string") {
            return [];
        }

        searchName = searchName.trim().toLowerCase();

        // Try finding an exact match for the name or aliases
        let foundChar = charList.filter(char => char.name.toLowerCase() === searchName);
        if (!foundChar.length) {
            foundChar = charList.filter(char => char.aliases.some(alias => alias.toLowerCase() === searchName));
        }
        if (ship && !foundChar.length) {
            foundChar = charList.filter(ship => ship.crew?.some(crew => crew.toLowerCase() === searchName));
        }
        if (foundChar?.length) {
            return foundChar;
        }
<commit_msg>Cleaned up too much, whoops<commit_after>const Discord = require("discord.js");
const moment = require("moment-timezone");
require("moment-duration-format");
const {promisify, inspect} = require("util");     // eslint-disable-line no-unused-vars
const fs = require("fs");
const readdir = promisify(require("fs").readdir);

module.exports = (Bot, client) => {
    Bot.constants = {
        // The main invite for the support server
        invite: "https://discord.com/invite/FfwGvhr",

        // Zero width space
        zws: "\u200B",

        // Some normal color codes
        colors: {
            black:  "#000000",
            blue:   "#0000FF",
            green:  "#00FF00",
            red:    "#FF0000",
            white:  "#FFFFFF",
            yellow: "#FFFF00",
        }
    };

    // Permissions mapping
    const permMap = {
        // Can do anything, access to the dev commands, etc
        BOT_OWNER: 10,

        // Can help out with the bot as needed, some extra stuff possibly
        HELPER: 8,

        // Owner of the server a command is being run in
        GUILD_OWNER: 7,

        // Has ADMIN or MANAGE_GUILD, or has one of the
        // configured roles from the guild's settings
        GUILD_ADMIN: 6,

        // Base users, anyone that's not included above
        BASE_USER: 0
    };

    /*  PERMISSION LEVEL FUNCTION
     *  This is a very basic permission system for commands which uses "levels"
     *  "spaces" are intentionally left black so you can add them if you want.
     *  NEVER GIVE ANYONE BUT OWNER THE LEVEL 10! By default this can run any
     *  command including the VERY DANGEROUS `eval` and `exec` commands!
     */
    Bot.permLevel = message => {
        let permlvl = 0;

        // Depending on message or interaction, grab the ID of the user
        const authId = message.author ? message.author.id : message.user.id;

        // If bot owner, return max perm level
        if (authId === Bot.config.ownerid) {
            return permMap.BOT_OWNER;
        }

        // If DMs or webhook, return 0 perm level.
        if (!message.guild || !message.member) {
            return permMap.BASE_USER;
        }
        const guildConf = message.guildSettings;

        // Guild Owner gets an extra level, wooh!
        const gOwner = message.guild.fetchOwner();
        if (message.channel.type === "text" && message.guild && gOwner) {
            if (message.author.id === gOwner.id) {
                return permMap.GUILD_OWNER;
            }
        }

        // Also giving them the permissions if they have the manage server role,
        // since they can change anything else in the server, so no reason not to
        if (message.member.permissions.has(["ADMINISTRATOR"]) || message.member.permissions.has(["MANAGE_GUILD"])) {
            return permMap.GUILD_ADMIN;
        }

        // The rest of the perms rely on roles. If those roles are not found
        // in the settings, or the user does not have it, their level will be 0
        try {
            const adminRoles = guildConf.adminRole;

            for (var ix = 0, len = adminRoles.length; ix < len; ix++) {
                const adminRole = message.guild.roles.cache.find(r => r.name.toLowerCase() === adminRoles[ix].toLowerCase() || r.id === adminRoles[ix]);
                if (adminRole && message.member.roles.cache.has(adminRole.id)) {
                    return permlvl = permMap.GUILD_ADMIN;
                }
            }
        } catch (e) {() => {};}
        return permlvl;
    };

    // Check if the bot's account is the main (real) bot
    Bot.isMain = () => {
        if (client.user.id === "315739499932024834") return true;
        return false;
    };

    // Default formatting for current US/Pacific time
    Bot.myTime = () => {
        return moment.tz("US/Pacific").format("M/D/YYYY h:mma");
    };

    // This finds any character that matches the search, and returns them in an array
    Bot.findChar = (searchName, charList, ship=false) => {
        if (!searchName?.length || typeof searchName !== "string") {
            return [];
        }

        searchName = searchName.trim().toLowerCase();

        // Try finding an exact match for the name or aliases
        let foundChar = charList.filter(char => char.name.toLowerCase() === searchName);
        if (!foundChar.length) {
            foundChar = charList.filter(char => char.aliases.some(alias => alias.toLowerCase() === searchName));
        }
        if (ship && !foundChar.length) {
            foundChar = charList.filter(ship => ship.crew?.some(crew => crew.toLowerCase() === searchName));
        }
        if (foundChar?.length) {
            return foundChar;
        }

{'fraction_non_alphanumeric': 0.11602689221427022, 'fraction_numerical': 0.009542398612014747, 'mean_word_length': 2.0140522875816993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '727811', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2616, 'n_words': 824}