Skip to content

Commit

Permalink
Update storage usage
Browse files Browse the repository at this point in the history
Going to have all my plugins going forward that don't use their own storage use the `plugin` key in ClientStorage
  • Loading branch information
zajrik committed Jul 13, 2017
1 parent 3adcdde commit 3bee97c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/DMManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export function DMManager(guild: string): PluginConstructor
public async init(): Promise<void>
{
this.guild = this.client.guilds.get(this._guild);
if (await this.storage.exists('dmManager.guild')
&& await this.storage.get('dmManager.guild') !== this._guild)
if (await this.storage.exists('plugin.dmManager.guild')
&& await this.storage.get('plugin.dmManager.guild') !== this._guild)
await this.clearOpenChannels();

await this.storage.set('dmManager.guild', this._guild);
await this.storage.set('plugin.dmManager.guild', this._guild);

if (!this.guild.member(this.client.user).permissions.has(['MANAGE_CHANNELS', 'MANAGE_MESSAGES']))
throw new Error('DMManager: Bot must have MANAGE_CHANNELS, MANAGE_MESSAGES permissions in the supplied guild');

this.channels = new Collection<string, TextChannel>(
(await this.storage.get('dmManager.openChannels') || []).map((c: [string, string]) =>
(await this.storage.get('plugin.dmManager.openChannels') || []).map((c: [string, string]) =>
[c[0], this.guild.channels.get(c[1])]) || []);

this.client.on('message', (message: Message) => this.handleMessage(message));
Expand All @@ -61,31 +61,31 @@ export function DMManager(guild: string): PluginConstructor
*/
public async blacklist(user: User): Promise<void>
{
await this.storage.set(`dmManager.blacklist.${user.id}`, true);
await this.storage.set(`plugin.dmManager.blacklist.${user.id}`, true);
}

/**
* Remove a user from the DMManager blacklist
*/
public async whitelist(user: User): Promise<void>
{
await this.storage.remove(`dmManager.blacklist.${user.id}`);
await this.storage.remove(`plugin.dmManager.blacklist.${user.id}`);
}

/**
* Return whether or not a user is blacklisted from the DMManager
*/
private async isBlacklisted(user: User): Promise<boolean>
{
return await this.storage.exists(`dmManager.blacklist.${user.id}`);
return await this.storage.exists(`plugin.dmManager.blacklist.${user.id}`);
}

/**
* Update open managed channels in storage
*/
private async storeOpenChannels(): Promise<void>
{
await this.storage.set('dmManager.openChannels',
await this.storage.set('plugin.dmManager.openChannels',
Array.from(this.channels.entries())
.map((c: [string, TextChannel]) => [c[0], c[1].id]));
}
Expand All @@ -95,7 +95,7 @@ export function DMManager(guild: string): PluginConstructor
*/
private async clearOpenChannels(): Promise<void>
{
await this.storage.set('dmManager.openChannels', []);
await this.storage.set('plugin.dmManager.openChannels', []);
this.channels = new Collection<string, TextChannel>();
}

Expand Down

0 comments on commit 3bee97c

Please sign in to comment.