diff --git a/src/index.ts b/src/index.ts index 8431acf2..3c95ae84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,9 @@ export { RateLimit } from './lib/command/RateLimit'; export { StorageProvider } from './lib/storage/StorageProvider'; export { JSONProvider } from './lib/storage/JSONProvider'; export { GuildSettings } from './lib/storage/GuildSettings'; -export { guildStorageMixin } from './lib/storage/GuildStorageMixin'; +export { createGuildStorageMixin } from './lib/storage/mixin/GuildStorageMixin'; +export { applyClientStorageMixin } from './lib/storage/mixin/ClientStorageMixin'; +export { ClientStorage } from './lib/types/ClientStorage'; import * as CommandDecorators from './lib/command/CommandDecorators'; export { CommandDecorators } diff --git a/src/lib/storage/GuildStorageMixin.ts b/src/lib/storage/GuildStorageMixin.ts deleted file mode 100644 index 21a964ad..00000000 --- a/src/lib/storage/GuildStorageMixin.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Guild } from 'discord.js'; -import { GuildSettings } from './GuildSettings'; -import { GuildStorage } from '../types/GuildStorage'; -import { StorageProvider } from './StorageProvider'; -import { Bot } from '../bot/Bot'; - -export async function guildStorageMixin(storage: StorageProvider, settings: StorageProvider, guild: Guild, client: Bot): Promise -{ - const newStorage: GuildSettings = new GuildSettings(storage, guild, client); - ( newStorage).settings = new GuildSettings(settings, guild, client); - await newStorage.init(); - await ( newStorage).settings.init(); - return newStorage; -} diff --git a/src/lib/storage/mixin/ClientStorageMixin.ts b/src/lib/storage/mixin/ClientStorageMixin.ts new file mode 100644 index 00000000..4e819fd9 --- /dev/null +++ b/src/lib/storage/mixin/ClientStorageMixin.ts @@ -0,0 +1,9 @@ +import { Collection } from 'discord.js'; +import { StorageProvider } from '../StorageProvider'; +import { ClientStorage } from '../../types/ClientStorage'; +import { GuildStorage } from '../../types/GuildStorage'; + +export function applyClientStorageMixin(storage: StorageProvider): void +{ + ( storage).guilds = new Collection(); +} diff --git a/src/lib/storage/mixin/GuildStorageMixin.ts b/src/lib/storage/mixin/GuildStorageMixin.ts new file mode 100644 index 00000000..4a4d0777 --- /dev/null +++ b/src/lib/storage/mixin/GuildStorageMixin.ts @@ -0,0 +1,14 @@ +import { Guild } from 'discord.js'; +import { GuildSettings } from '../GuildSettings'; +import { GuildStorage } from '../../types/GuildStorage'; +import { StorageProvider } from '../StorageProvider'; +import { Bot } from '../../bot/Bot'; + +export async function createGuildStorageMixin(storage: StorageProvider, settings: StorageProvider, guild: Guild, client: Bot): Promise +{ + const newStorage: GuildSettings = new GuildSettings(storage, guild, client); + ( newStorage).settings = new GuildSettings(settings, guild, client); + await newStorage.init(); + await ( newStorage).settings.init(); + return newStorage; +} diff --git a/src/lib/types/ClientStorage.ts b/src/lib/types/ClientStorage.ts new file mode 100644 index 00000000..9a7436d8 --- /dev/null +++ b/src/lib/types/ClientStorage.ts @@ -0,0 +1,5 @@ +import { Collection } from 'discord.js'; +import { StorageProvider } from '../storage/StorageProvider'; +import { GuildStorage } from './GuildStorage'; + +export type ClientStorage = StorageProvider & { guilds: Collection; };