Skip to content

Commit

Permalink
Add ClientStorage mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Mar 27, 2017
1 parent 8368f61 commit 13a7765
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 0 additions & 14 deletions src/lib/storage/GuildStorageMixin.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/lib/storage/mixin/ClientStorageMixin.ts
Original file line number Diff line number Diff line change
@@ -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
{
(<ClientStorage> storage).guilds = new Collection<string, GuildStorage>();
}
14 changes: 14 additions & 0 deletions src/lib/storage/mixin/GuildStorageMixin.ts
Original file line number Diff line number Diff line change
@@ -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<GuildStorage>
{
const newStorage: GuildSettings = new GuildSettings(storage, guild, client);
(<GuildStorage> newStorage).settings = new GuildSettings(settings, guild, client);
await newStorage.init();
await (<GuildStorage> newStorage).settings.init();
return <GuildStorage> newStorage;
}
5 changes: 5 additions & 0 deletions src/lib/types/ClientStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Collection } from 'discord.js';
import { StorageProvider } from '../storage/StorageProvider';
import { GuildStorage } from './GuildStorage';

export type ClientStorage = StorageProvider & { guilds: Collection<string, GuildStorage>; };

0 comments on commit 13a7765

Please sign in to comment.