<commit_before>const SettingGateway = require("./settingGateway");
const SettingResolver = require("./settingResolver");

class SettingsCache {
  constructor(client) {
    Object.defineProperty(this, "client", { value: client });
    this.resolver = new SettingResolver(client);

    this.guilds = new SettingGateway(this, "guilds", this.validate, this.defaultDataSchema);
  }

  async add(name, validateFunction, schema = {}) {
    if (!name || typeof name !== "string") throw "You must pass a name for your new gateway and it must be a string.";
    if (name in this) throw "There is already a Gateway with that name.";
    if (typeof validateFunction !== "function") throw "You must pass a validate function.";
    const hasPrototype = Object.prototype.hasOwnProperty.call(validateFunction, "prototype");
    if (!hasPrototype) throw "You did not create a valid validate function. You must use the function keyword or constructor, and may not use arrow functions.";
    if (schema.constructor.name !== "Object") throw "Schema must be a valid Schema object or left undefined for an empty object.";
    this[name] = new SettingGateway(this, name, validateFunction, schema);
    await this[name].init();
    return this[name];
  }

  async validate(guild) {
    const result = await this.resolver.guild(guild);
    if (!result) throw "The parameter <Guild> expects either a Guild ID or a Guild Object.";<commit_msg>change validateFunction<commit_after>const SettingGateway = require("./settingGateway");
const SettingResolver = require("./settingResolver");

class SettingsCache {
  constructor(client) {
    Object.defineProperty(this, "client", { value: client });
    this.resolver = new SettingResolver(client);

    this.guilds = new SettingGateway(this, "guilds", this.validate.bind(null, this), this.defaultDataSchema);
  }

  async add(name, validateFunction, schema = {}) {
    if (!name || typeof name !== "string") throw "You must pass a name for your new gateway and it must be a string.";
    if (name in this) throw "There is already a Gateway with that name.";
    if (typeof validateFunction !== "function") throw "You must pass a validate function.";
    validateFunction = validateFunction.bind(null, this);
    if (schema.constructor.name !== "Object") throw "Schema must be a valid object or left undefined for an empty object.";
    this[name] = new SettingGateway(this, name, validateFunction, schema);
    await this[name].init();
    return this[name];
  }

  async validate(cache, guild) { // eslint-disable-line
    const result = await cache.resolver.guild(guild);
    if (!result) throw "The parameter <Guild> expects either a Guild ID or a Guild Object.";
{'fraction_non_alphanumeric': 0.11773472429210134, 'fraction_numerical': 0.0, 'mean_word_length': 4.348605577689243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3185363', 'n_tokens_mistral': 712, 'n_tokens_neox': 711, 'n_words': 274}