<commit_before>'use babel';
'use strict';

import GuildStorage from './GuildStorage';

/**
 * Handles loading all guild-specific data from persistent storage into
 * {@link GuildStorage} objects
 * @class GuildStorageLoader
 */
export default class GuildStorageLoader
{
	constructor(bot)
	{
		/** @type {Bot} */
		this._bot = bot;
	}

	/**
	 * Load data for each guild from persistent storage and store it in a
	 * {@link GuildStorage} object
	 * @memberof GuildStorageLoader
	 * @instance
	 * @param {LocalStorage} dataStorage - LocalStorage instance containing all guild-specific data
	 * @param {LocalStorage} settingsStorage - LocalStorage instance containing all guild-specific settings
	 */
	loadStorages(dataStorage, settingsStorage)
	{
		dataStorage.keys.forEach((key) =>
		{
			this._bot.guildStorages.set(key, new GuildStorage(this._bot, key, dataStorage, settingsStorage));
		});

		// If the number of guilds in localStorage doesn't match
		// the number of guilds the bot is a member of, assume
		// this means there are guilds that have not yet been
		// assigned storage and create storage for them
		if (dataStorage.length !== this._bot.guilds.size)
		{
			this.initNewGuilds(dataStorage, settingsStorage);
		}
	}

	/**
	 * Assign a GuildStorage to guilds that lack one due to the bot being
	 * in the guild before adopting this storage spec or the bot being
	 * added to a new guild
	 * @memberof GuildStorageLoader
	 * @instance
	 * @param {LocalStorage} dataStorage - LocalStorage instance containing all guild-specific data
	 * @param {LocalStorage} settingsStorage - LocalStorage instance containing all guild-specific settings
	 */
	initNewGuilds(dataStorage, settingsStorage)
	{
		let storagelessGuilds = this._bot.guilds.filter(guild =>
			!dataStorage.keys.includes(guild.id));
		if (storagelessGuilds.size > 0)
		{
			storagelessGuilds.forEach(guild =>
			{
				this._bot.guildStorages.set(guild.id, new GuildStorage(this._bot, guild.id, dataStorage, settingsStorage));
			});
		}
	}
}<commit_msg>Clean up initNewGuilds<commit_after>'use babel';
'use strict';

import GuildStorage from './GuildStorage';

/**
 * Handles loading all guild-specific data from persistent storage into
 * {@link GuildStorage} objects
 * @class GuildStorageLoader
 */
export default class GuildStorageLoader
{
	constructor(bot)
	{
		/** @type {Bot} */
		this._bot = bot;
	}

	/**
	 * Load data for each guild from persistent storage and store it in a
	 * {@link GuildStorage} object
	 * @memberof GuildStorageLoader
	 * @instance
	 * @param {LocalStorage} dataStorage - LocalStorage instance containing all guild-specific data
	 * @param {LocalStorage} settingsStorage - LocalStorage instance containing all guild-specific settings
	 */
	loadStorages(dataStorage, settingsStorage)
	{
		dataStorage.keys.forEach((key) =>
		{
			this._bot.guildStorages.set(key, new GuildStorage(this._bot, key, dataStorage, settingsStorage));
		});

		// If the number of guilds in localStorage doesn't match
		// the number of guilds the bot is a member of, assume
		// this means there are guilds that have not yet been
		// assigned storage and create storage for them
		if (dataStorage.length !== this._bot.guilds.size)
		{
			this.initNewGuilds(dataStorage, settingsStorage);
		}
	}

	/**
	 * Assign a GuildStorage to guilds that lack one due to the bot being
	 * in the guild before adopting this storage spec or the bot being
	 * added to a new guild
	 * @memberof GuildStorageLoader
	 * @instance
	 * @param {LocalStorage} dataStorage - LocalStorage instance containing all guild-specific data
	 * @param {LocalStorage} settingsStorage - LocalStorage instance containing all guild-specific settings
	 */
	initNewGuilds(dataStorage, settingsStorage)
	{
		let storagelessGuilds = this._bot.guilds.filter(guild => !dataStorage.keys.includes(guild.id));
		if (storagelessGuilds.size === 0) return;
		storagelessGuilds.forEach(guild =>
		{
			this._bot.guildStorages.set(guild.id, new GuildStorage(this._bot, guild.id, dataStorage, settingsStorage));
		});
	}
}
{'fraction_non_alphanumeric': 0.09802469135802469, 'fraction_numerical': 0.0004938271604938272, 'mean_word_length': 4.160509554140128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '915384', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1161, 'n_words': 375}