From 670fac3658acccf98fa72659ef99c4814eeefc91 Mon Sep 17 00:00:00 2001 From: Faith Date: Sun, 31 May 2020 08:09:43 -0400 Subject: [PATCH 1/3] settings sync stuff --- src/actions/GUILD_CREATE.ts | 31 ++++++++++++++++++++++++++++ src/index.ts | 1 + src/lib/Client.ts | 5 +++++ src/lib/extensions/KlasaUserStore.ts | 16 ++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/actions/GUILD_CREATE.ts create mode 100644 src/lib/extensions/KlasaUserStore.ts diff --git a/src/actions/GUILD_CREATE.ts b/src/actions/GUILD_CREATE.ts new file mode 100644 index 0000000000..315d2b76cf --- /dev/null +++ b/src/actions/GUILD_CREATE.ts @@ -0,0 +1,31 @@ +import { Action, extender, Guild } from '@klasa/core'; + +import type { GuildCreateDispatch } from '@klasa/ws'; + +export default class CoreAction extends Action { + + public async run(data: GuildCreateDispatch): Promise { + const built = this.build(data); + if (built) { + await built.settings.sync(); + this.cache(built); + this.client.emit(this.clientEvent, built); + } + } + + public check(): null { + return null; + } + + public build(data: GuildCreateDispatch): Guild { + // eslint-disable-next-line @typescript-eslint/camelcase + return new (extender.get('Guild'))(this.client, data.d, data.shard_id); + } + + public cache(data: Guild): void { + if (this.client.options.cache.enabled) { + this.client.guilds.set(data.id, data); + } + } + +} diff --git a/src/index.ts b/src/index.ts index 24950b57dd..9f04c5c38a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ export * from './lib/Client'; export * from './lib/extensions/KlasaGuild'; export * from './lib/extensions/KlasaMessage'; export * from './lib/extensions/KlasaUser'; +export * from './lib/extensions/KlasaUserStore'; // lib/permissions export * from './lib/permissions/PermissionLevels'; diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 3fcbf8b1ff..80d1174716 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -15,6 +15,9 @@ import { isObject, mergeDefault } from '@klasa/utils'; import { join } from 'path'; import { PermissionLevels } from './permissions/PermissionLevels'; +// lib/extensions +import { KlasaUserStore } from './extensions/KlasaUserStore'; + // lib/schedule import { Schedule } from './schedule/Schedule'; @@ -421,6 +424,8 @@ export class KlasaClient extends Client { mergeDefault(KlasaClientDefaults as unknown as Required, options); super(options); + Reflect.set(this, 'users', new KlasaUserStore(this)); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error this.console = new KlasaConsole(this.options.console); diff --git a/src/lib/extensions/KlasaUserStore.ts b/src/lib/extensions/KlasaUserStore.ts new file mode 100644 index 0000000000..d25798019b --- /dev/null +++ b/src/lib/extensions/KlasaUserStore.ts @@ -0,0 +1,16 @@ +import { UserStore, User } from '@klasa/core'; + +export class KlasaUserStore extends UserStore { + + /** + * Gets a {@link User user} by its ID, then syncs the user's settings instance + * @since 0.6.0 + * @param userID The {@link User user} ID. + */ + public async fetch(userID: string): Promise { + const user = await super.fetch(userID); + await user.settings.sync(); + return user; + } + +} From e17cc6fd48757d7143559ab136f465dc0537e891 Mon Sep 17 00:00:00 2001 From: bdistin Date: Wed, 24 Jun 2020 10:46:40 -0500 Subject: [PATCH 2/3] Update GUILD_CREATE.ts --- src/actions/GUILD_CREATE.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/GUILD_CREATE.ts b/src/actions/GUILD_CREATE.ts index 315d2b76cf..c036d828a7 100644 --- a/src/actions/GUILD_CREATE.ts +++ b/src/actions/GUILD_CREATE.ts @@ -18,7 +18,7 @@ export default class CoreAction extends Action { } public build(data: GuildCreateDispatch): Guild { - // eslint-disable-next-line @typescript-eslint/camelcase + // eslint-disable-next-line @typescript-eslint/naming-convention return new (extender.get('Guild'))(this.client, data.d, data.shard_id); } From 46b8886e862d483047cc9e1678962f927200cb7f Mon Sep 17 00:00:00 2001 From: bdistin Date: Wed, 24 Jun 2020 11:17:08 -0500 Subject: [PATCH 3/3] Update GUILD_CREATE.ts --- src/actions/GUILD_CREATE.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/GUILD_CREATE.ts b/src/actions/GUILD_CREATE.ts index c036d828a7..37ad5cb77a 100644 --- a/src/actions/GUILD_CREATE.ts +++ b/src/actions/GUILD_CREATE.ts @@ -18,7 +18,7 @@ export default class CoreAction extends Action { } public build(data: GuildCreateDispatch): Guild { - // eslint-disable-next-line @typescript-eslint/naming-convention + // eslint-disable-next-line camelcase return new (extender.get('Guild'))(this.client, data.d, data.shard_id); }