From cfa512c447469956d738df938137f97104734363 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 21:16:14 -0500 Subject: [PATCH 01/16] Make structures for data stores extensible --- src/index.js | 1 + src/stores/DataStore.js | 3 ++- src/util/Structures.js | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/util/Structures.js diff --git a/src/index.js b/src/index.js index de6a6e66c..90cf5b4c0 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ module.exports = { Permissions: require('./util/Permissions'), Snowflake: require('./util/Snowflake'), SnowflakeUtil: require('./util/Snowflake'), + Structures: require('./util/Structures'), Util: Util, util: Util, version: require('../package.json').version, diff --git a/src/stores/DataStore.js b/src/stores/DataStore.js index 398910d50..fc9aa414d 100644 --- a/src/stores/DataStore.js +++ b/src/stores/DataStore.js @@ -1,4 +1,5 @@ const Collection = require('../util/Collection'); +const Structures = require('../util/Structures'); /** * Manages the creation, retrieval and deletion of a specific data model. @@ -8,7 +9,7 @@ class DataStore extends Collection { constructor(client, iterable, holds) { super(); Object.defineProperty(this, 'client', { value: client }); - Object.defineProperty(this, 'holds', { value: holds }); + Object.defineProperty(this, 'holds', { value: Structures.get(holds.name) }); if (iterable) for (const item of iterable) this.create(item); } diff --git a/src/util/Structures.js b/src/util/Structures.js new file mode 100644 index 000000000..d09684c50 --- /dev/null +++ b/src/util/Structures.js @@ -0,0 +1,54 @@ +/** + * Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore}s. + * When extending a built-in structure, it is important to both get the class you're extending from here, + * and to set it here afterwards. + * @example + * const { Structures } = require('discord.js); + * + * class CoolGuild extends Structures.get('Guild') { + * constructor(client, data) { + * super(client, data); + * this.cool = true; + * } + * } + * + * Structures.set('Guild', CoolGuild); + */ +class Structures { + constructor() { + throw new Error(`The ${this.constructor.name} class may not be instantiated.`); + } + + /** + * Retrieves a structure class. + * @param {string} name Name of the base structure + * @returns {Function} + */ + static get(name) { + return structures[name]; + } + + /** + * Overrides a structure class. + * @param {string} name Name of the base structure + * @param {Function} custom Extended structure class to override with + */ + static set(name, custom) { + structures[name] = custom; + } +} + +const structures = { + Channel: require('./structures/Channel'), + Emoji: require('./structures/Emoji'), + GuildChannel: require('./structures/GuildChannel'), + GuildMember: require('./structures/GuildMember'), + Guild: require('./structures/Guild'), + Message: require('./structures/Message'), + Presence: require('./structures/Presence'), + Reaction: require('./structures/Reaction'), + Role: require('./structures/Role'), + User: require('./structures/User'), +}; + +module.exports = Structures; From c29804e3f891095a7d2837fc7b38d9cd85a22573 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 21:19:46 -0500 Subject: [PATCH 02/16] i aint do nuffin --- src/util/Structures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index d09684c50..8c137ff8e 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -3,7 +3,7 @@ * When extending a built-in structure, it is important to both get the class you're extending from here, * and to set it here afterwards. * @example - * const { Structures } = require('discord.js); + * const { Structures } = require('discord.js'); * * class CoolGuild extends Structures.get('Guild') { * constructor(client, data) { From 0291fe41d8d04c0c4ccb0b44274c9f6841d436a0 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 22:09:43 -0500 Subject: [PATCH 03/16] Fix structure paths --- src/util/Structures.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index 8c137ff8e..44586a96f 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -39,16 +39,16 @@ class Structures { } const structures = { - Channel: require('./structures/Channel'), - Emoji: require('./structures/Emoji'), - GuildChannel: require('./structures/GuildChannel'), - GuildMember: require('./structures/GuildMember'), - Guild: require('./structures/Guild'), - Message: require('./structures/Message'), - Presence: require('./structures/Presence'), - Reaction: require('./structures/Reaction'), - Role: require('./structures/Role'), - User: require('./structures/User'), + Channel: require('../structures/Channel'), + Emoji: require('../structures/Emoji'), + GuildChannel: require('../structures/GuildChannel'), + GuildMember: require('../structures/GuildMember'), + Guild: require('../structures/Guild'), + Message: require('../structures/Message'), + Presence: require('../structures/Presence'), + Reaction: require('../structures/Reaction'), + Role: require('../structures/Role'), + User: require('../structures/User'), }; module.exports = Structures; From dc379519d3c879d39cf94724d7876b285ef71e1a Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 22:30:37 -0500 Subject: [PATCH 04/16] Fix reaction structure name --- src/util/Structures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index 44586a96f..f63c884a5 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -45,8 +45,8 @@ const structures = { GuildMember: require('../structures/GuildMember'), Guild: require('../structures/Guild'), Message: require('../structures/Message'), + MessageReaction: require('../structures/MessageReaction'), Presence: require('../structures/Presence'), - Reaction: require('../structures/Reaction'), Role: require('../structures/Role'), User: require('../structures/User'), }; From 47dc8fd0466dbdc1af6c33f995fa9108c4a45841 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 22:41:45 -0500 Subject: [PATCH 05/16] Overhaul the way structures are extended --- src/util/Structures.js | 59 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index f63c884a5..8a22ee703 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -1,18 +1,5 @@ /** - * Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore}s. - * When extending a built-in structure, it is important to both get the class you're extending from here, - * and to set it here afterwards. - * @example - * const { Structures } = require('discord.js'); - * - * class CoolGuild extends Structures.get('Guild') { - * constructor(client, data) { - * super(client, data); - * this.cool = true; - * } - * } - * - * Structures.set('Guild', CoolGuild); + * Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore DataStores}. */ class Structures { constructor() { @@ -20,21 +7,41 @@ class Structures { } /** - * Retrieves a structure class. - * @param {string} name Name of the base structure - * @returns {Function} + * Extends a structure. + * @param {string} name Name of the structure class to extend + * @param {Function} extender Function that takes the base class to extend as its only parameter and returns the + * extended class/prototype + * @returns {Function} Extended class/prototype returned from the extender + * @example + * const { Structures } = require('discord.js'); + * + * Structures.extend('Guild', Guild => + * class CoolGuild extends Guild { + * constructor(client, data) { + * super(client, data); + * this.cool = true; + * } + * } + * ); */ - static get(name) { - return structures[name]; - } + extend(name, extender) { + if (!structures[name]) throw new RangeError(`"${name}" is not a valid extensible structure.`); + if (typeof extender !== 'function') { + throw new TypeError('The extender must be a function that returns the extended class.'); + } + + const custom = extender(structures[name]); + if (typeof custom !== 'function') { + throw new TypeError('The extender function should return the extended class/prototype.'); + } + if (Object.getPrototypeOf(custom) !== structures[name]) { + throw new Error( + 'The class/prototype returned from the extender function must extend the existing structure class/prototype.' + ); + } - /** - * Overrides a structure class. - * @param {string} name Name of the base structure - * @param {Function} custom Extended structure class to override with - */ - static set(name, custom) { structures[name] = custom; + return custom; } } From 6d53d893a80332ca3e437a166c5c41b8f30ce63a Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 22:46:38 -0500 Subject: [PATCH 06/16] Make Structures.extend static and tweak error messages --- src/util/Structures.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index 8a22ee703..d118ebb0a 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -24,19 +24,19 @@ class Structures { * } * ); */ - extend(name, extender) { + static extend(name, extender) { if (!structures[name]) throw new RangeError(`"${name}" is not a valid extensible structure.`); if (typeof extender !== 'function') { - throw new TypeError('The extender must be a function that returns the extended class.'); + throw new TypeError('The extender must be a function that returns the extended structure class/prototype.'); } const custom = extender(structures[name]); if (typeof custom !== 'function') { - throw new TypeError('The extender function should return the extended class/prototype.'); + throw new TypeError('The extender function must return the extended structure class/prototype.'); } if (Object.getPrototypeOf(custom) !== structures[name]) { throw new Error( - 'The class/prototype returned from the extender function must extend the existing structure class/prototype.' + "The class/prototype returned from the extender function doesn't extend the existing structure class/prototype." ); } From f004e6ccca17eb4ae8efdb32bcaf6164ad15c6b2 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 19 Nov 2017 23:00:56 -0500 Subject: [PATCH 07/16] Reimplement Structures.get --- src/stores/DataStore.js | 2 +- src/util/Structures.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/stores/DataStore.js b/src/stores/DataStore.js index fc9aa414d..35e326e82 100644 --- a/src/stores/DataStore.js +++ b/src/stores/DataStore.js @@ -9,7 +9,7 @@ class DataStore extends Collection { constructor(client, iterable, holds) { super(); Object.defineProperty(this, 'client', { value: client }); - Object.defineProperty(this, 'holds', { value: Structures.get(holds.name) }); + Object.defineProperty(this, 'holds', { value: Structures.get(holds) }); if (iterable) for (const item of iterable) this.create(item); } diff --git a/src/util/Structures.js b/src/util/Structures.js index d118ebb0a..dd2eca2ba 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -6,6 +6,17 @@ class Structures { throw new Error(`The ${this.constructor.name} class may not be instantiated.`); } + /** + * Retrieves a structure class. + * @param {string|Function} structure Name of the structure or a class/prototype function to use the name of + * @returns {Function} + */ + static get(structure) { + if (typeof structure === 'string') return structures[structure]; + if (typeof structure === 'function') return structures[structure.name]; + throw new TypeError(`Structure to retrieve must be a string or class/prototype function, not ${typeof structure}.`); + } + /** * Extends a structure. * @param {string} name Name of the structure class to extend From 63b0c8d5cc80e2f1b86541c51a62bb1cd7044872 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 00:23:41 -0500 Subject: [PATCH 08/16] Fix circular dependency --- src/stores/DataStore.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stores/DataStore.js b/src/stores/DataStore.js index 35e326e82..3c58b3899 100644 --- a/src/stores/DataStore.js +++ b/src/stores/DataStore.js @@ -1,5 +1,5 @@ const Collection = require('../util/Collection'); -const Structures = require('../util/Structures'); +let Structures; /** * Manages the creation, retrieval and deletion of a specific data model. @@ -8,6 +8,7 @@ const Structures = require('../util/Structures'); class DataStore extends Collection { constructor(client, iterable, holds) { super(); + if(!Structures) Structures = require('../util/Structures'); Object.defineProperty(this, 'client', { value: client }); Object.defineProperty(this, 'holds', { value: Structures.get(holds) }); if (iterable) for (const item of iterable) this.create(item); From 3728c718670d2e4f6002063eeec094b6f06b55a6 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 00:24:43 -0500 Subject: [PATCH 09/16] Fix missing space --- src/stores/DataStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/DataStore.js b/src/stores/DataStore.js index 3c58b3899..1a196e77d 100644 --- a/src/stores/DataStore.js +++ b/src/stores/DataStore.js @@ -8,7 +8,7 @@ let Structures; class DataStore extends Collection { constructor(client, iterable, holds) { super(); - if(!Structures) Structures = require('../util/Structures'); + if (!Structures) Structures = require('../util/Structures'); Object.defineProperty(this, 'client', { value: client }); Object.defineProperty(this, 'holds', { value: Structures.get(holds) }); if (iterable) for (const item of iterable) this.create(item); From a2a4c3c196e4b0eaaecd7553f70ded60e317f8a4 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 00:26:57 -0500 Subject: [PATCH 10/16] Fix Presence structure --- src/util/Structures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index dd2eca2ba..f83b29ffe 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -64,7 +64,7 @@ const structures = { Guild: require('../structures/Guild'), Message: require('../structures/Message'), MessageReaction: require('../structures/MessageReaction'), - Presence: require('../structures/Presence'), + Presence: require('../structures/Presence').Presence, Role: require('../structures/Role'), User: require('../structures/User'), }; From 1e0ee2f8fa419ec8e456cdef45d445a2b85d8f90 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 01:11:19 -0500 Subject: [PATCH 11/16] Replace Structures.extend with set --- src/stores/DataStore.js | 2 +- src/util/Structures.js | 49 ++++++++++++----------------------------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/stores/DataStore.js b/src/stores/DataStore.js index 1a196e77d..6f3e74146 100644 --- a/src/stores/DataStore.js +++ b/src/stores/DataStore.js @@ -10,7 +10,7 @@ class DataStore extends Collection { super(); if (!Structures) Structures = require('../util/Structures'); Object.defineProperty(this, 'client', { value: client }); - Object.defineProperty(this, 'holds', { value: Structures.get(holds) }); + Object.defineProperty(this, 'holds', { value: Structures.get(holds.name) }); if (iterable) for (const item of iterable) this.create(item); } diff --git a/src/util/Structures.js b/src/util/Structures.js index f83b29ffe..fd2e44584 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -8,51 +8,30 @@ class Structures { /** * Retrieves a structure class. - * @param {string|Function} structure Name of the structure or a class/prototype function to use the name of + * @param {string} structure Name of the structure to retrieve * @returns {Function} */ static get(structure) { if (typeof structure === 'string') return structures[structure]; - if (typeof structure === 'function') return structures[structure.name]; - throw new TypeError(`Structure to retrieve must be a string or class/prototype function, not ${typeof structure}.`); + throw new TypeError(`"structure" argument must be a string (received ${typeof structure})`); } /** - * Extends a structure. - * @param {string} name Name of the structure class to extend - * @param {Function} extender Function that takes the base class to extend as its only parameter and returns the - * extended class/prototype - * @returns {Function} Extended class/prototype returned from the extender - * @example - * const { Structures } = require('discord.js'); - * - * Structures.extend('Guild', Guild => - * class CoolGuild extends Guild { - * constructor(client, data) { - * super(client, data); - * this.cool = true; - * } - * } - * ); + * Replaces a structure class with an extended one. + * @param {string} structure Name of the structure to replace + * @param {Function} extended Extended structure class/prototype function to replace with */ - static extend(name, extender) { - if (!structures[name]) throw new RangeError(`"${name}" is not a valid extensible structure.`); - if (typeof extender !== 'function') { - throw new TypeError('The extender must be a function that returns the extended structure class/prototype.'); - } - - const custom = extender(structures[name]); - if (typeof custom !== 'function') { - throw new TypeError('The extender function must return the extended structure class/prototype.'); - } - if (Object.getPrototypeOf(custom) !== structures[name]) { - throw new Error( - "The class/prototype returned from the extender function doesn't extend the existing structure class/prototype." + static set(structure, extended) { + if (!structures[structure]) throw new RangeError(`"${structure}" is not a valid extensible structure.`); + if (typeof extended !== 'function') { + throw new TypeError( + `"extended" argument must be a structure class/prototype function (received ${typeof extended})` ); } - - structures[name] = custom; - return custom; + if (Object.getPrototypeOf(extended) !== structures[structure]) { + throw new Error('The class/prototype function provided doesn\'t extend the existing structure class/prototype.'); + } + structures[structure] = extended; } } From cf07b7e3425d78a1abf971f6f8ddd026cfa449c1 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 01:13:36 -0500 Subject: [PATCH 12/16] Re-add docs --- src/util/Structures.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/Structures.js b/src/util/Structures.js index fd2e44584..90c6f23b2 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -1,5 +1,7 @@ /** * Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore DataStores}. + * When extending a built-in structure, it is important to both get the class you're extending from here, + * and to set it here afterwards. */ class Structures { constructor() { @@ -20,6 +22,17 @@ class Structures { * Replaces a structure class with an extended one. * @param {string} structure Name of the structure to replace * @param {Function} extended Extended structure class/prototype function to replace with + * @example + * const { Structures } = require('discord.js'); + * + * class CoolGuild extends Structures.get('Guild') { + * constructor(client, data) { + * super(client, data); + * this.cool = true; + * } + * } + * + * Structures.set('Guild', CoolGuild); */ static set(structure, extended) { if (!structures[structure]) throw new RangeError(`"${structure}" is not a valid extensible structure.`); From f3817e328b7691ec87d9f5236524627f59b9107b Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Mon, 20 Nov 2017 01:37:19 -0500 Subject: [PATCH 13/16] JK, back to Structures.extend --- src/util/Structures.js | 44 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index 90c6f23b2..c81540586 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -1,7 +1,5 @@ /** * Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore DataStores}. - * When extending a built-in structure, it is important to both get the class you're extending from here, - * and to set it here afterwards. */ class Structures { constructor() { @@ -19,32 +17,46 @@ class Structures { } /** - * Replaces a structure class with an extended one. - * @param {string} structure Name of the structure to replace - * @param {Function} extended Extended structure class/prototype function to replace with + * Extends a structure. + * @param {string} structure Name of the structure class to extend + * @param {Function} extender Function that takes the base class to extend as its only parameter and returns the + * extended class/prototype + * @returns {Function} Extended class/prototype returned from the extender * @example * const { Structures } = require('discord.js'); * - * class CoolGuild extends Structures.get('Guild') { - * constructor(client, data) { - * super(client, data); - * this.cool = true; + * Structures.extend('Guild', Guild => { + * class CoolGuild extends Guild { + * constructor(client, data) { + * super(client, data); + * this.cool = true; + * } * } - * } * - * Structures.set('Guild', CoolGuild); + * return CoolGuild; + * }); */ - static set(structure, extended) { + static extend(structure, extender) { if (!structures[structure]) throw new RangeError(`"${structure}" is not a valid extensible structure.`); - if (typeof extended !== 'function') { + if (typeof extender !== 'function') { + const received = `(received ${typeof extender})`; throw new TypeError( - `"extended" argument must be a structure class/prototype function (received ${typeof extended})` + `"extender" argument must be a function that returns the extended structure class/prototype ${received}` ); } - if (Object.getPrototypeOf(extended) !== structures[structure]) { - throw new Error('The class/prototype function provided doesn\'t extend the existing structure class/prototype.'); + + const extended = extender(structures[structure]); + if (typeof extended !== 'function') { + throw new TypeError('The extender function must return the extended structure class/prototype.'); } + if (Object.getPrototypeOf(extended) !== structures[structure]) { + throw new Error( + 'The class/prototype returned from the extender function must extend the existing structure class/prototype.' + ); + } + structures[structure] = extended; + return extended; } } From dcf48e2225ce68c004c312fac7125dd85c0f2872 Mon Sep 17 00:00:00 2001 From: bdistin Date: Fri, 24 Nov 2017 21:42:02 -0600 Subject: [PATCH 14/16] Fix inconsistency with Channel Creation: CustomStructures (#2121) * Fix inconsistancy with Channel Creation * Because static get is a function, it thinks we are create a new instance based on that function, rather than the returned class... --- src/structures/Channel.js | 25 +++++++++++++++---------- src/util/Structures.js | 6 +++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/structures/Channel.js b/src/structures/Channel.js index 33b851f09..04867b118 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -66,32 +66,37 @@ class Channel extends Base { } static create(client, data, guild) { - const DMChannel = require('./DMChannel'); - const GroupDMChannel = require('./GroupDMChannel'); - const TextChannel = require('./TextChannel'); - const VoiceChannel = require('./VoiceChannel'); - const CategoryChannel = require('./CategoryChannel'); - const GuildChannel = require('./GuildChannel'); + const Structures = require('../util/Structures'); let channel; if (data.type === ChannelTypes.DM) { + const DMChannel = Structures.get('DMChannel'); channel = new DMChannel(client, data); } else if (data.type === ChannelTypes.GROUP) { + const GroupDMChannel = Structures.get('GroupDMChannel'); channel = new GroupDMChannel(client, data); } else { guild = guild || client.guilds.get(data.guild_id); if (guild) { switch (data.type) { - case ChannelTypes.TEXT: + case ChannelTypes.TEXT: { + const TextChannel = Structures.get('TextChannel'); channel = new TextChannel(guild, data); break; - case ChannelTypes.VOICE: + } + case ChannelTypes.VOICE: { + const VoiceChannel = Structures.get('VoiceChannel'); channel = new VoiceChannel(guild, data); break; - case ChannelTypes.CATEGORY: + } + case ChannelTypes.CATEGORY: { + const CategoryChannel = Structures.get('CategoryChannel'); channel = new CategoryChannel(guild, data); break; - default: + } + default: { + const GuildChannel = Structures.get('GuildChannel'); channel = new GuildChannel(guild, data); + } } guild.channels.set(channel.id, channel); } diff --git a/src/util/Structures.js b/src/util/Structures.js index c81540586..a1cb7e156 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -61,8 +61,12 @@ class Structures { } const structures = { - Channel: require('../structures/Channel'), Emoji: require('../structures/Emoji'), + DMChannel: require('../structures/DMChannel'), + GroupDMChannel: require('../structures/GroupDMChannel'), + TextChannel: require('../structures/TextChannel'), + VoiceChannel: require('../structures/VoiceChannel'), + CategoryChannel: require('../structures/CategoryChannel'), GuildChannel: require('../structures/GuildChannel'), GuildMember: require('../structures/GuildMember'), Guild: require('../structures/Guild'), From 7cd0a9525d49a520c1fd599a961fb22816d781d8 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 24 Nov 2017 23:05:00 -0500 Subject: [PATCH 15/16] Fix ClientUser not extending custom User --- src/client/websocket/packets/handlers/Ready.js | 3 ++- src/index.js | 7 ++++++- src/structures/ClientUser.js | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/websocket/packets/handlers/Ready.js b/src/client/websocket/packets/handlers/Ready.js index 4fc5363cf..b1a833d5f 100644 --- a/src/client/websocket/packets/handlers/Ready.js +++ b/src/client/websocket/packets/handlers/Ready.js @@ -1,6 +1,6 @@ const AbstractHandler = require('./AbstractHandler'); const { Events } = require('../../../../util/Constants'); -const ClientUser = require('../../../../structures/ClientUser'); +let ClientUser; class ReadyHandler extends AbstractHandler { handle(packet) { @@ -12,6 +12,7 @@ class ReadyHandler extends AbstractHandler { data.user.user_settings = data.user_settings; data.user.user_guild_settings = data.user_guild_settings; + if (!ClientUser) ClientUser = require('../../../../structures/ClientUser'); const clientUser = new ClientUser(client, data.user); client.user = clientUser; client.readyAt = new Date(); diff --git a/src/index.js b/src/index.js index 90cf5b4c0..1108f23f6 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,10 @@ module.exports = { CategoryChannel: require('./structures/CategoryChannel'), Channel: require('./structures/Channel'), ClientApplication: require('./structures/ClientApplication'), - ClientUser: require('./structures/ClientUser'), + get ClientUser() { + // This is a getter so that it properly extends any custom User class + return require('./structures/ClientUser'); + }, ClientUserChannelOverride: require('./structures/ClientUserChannelOverride'), ClientUserGuildSettings: require('./structures/ClientUserGuildSettings'), ClientUserSettings: require('./structures/ClientUserSettings'), @@ -81,3 +84,5 @@ module.exports = { WebSocket: require('./WebSocket'), }; + +Object. diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index ef6433924..b0b3452d4 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -1,4 +1,4 @@ -const User = require('./User'); +const Structures = require('../util/Structures'); const Collection = require('../util/Collection'); const ClientUserSettings = require('./ClientUserSettings'); const ClientUserGuildSettings = require('./ClientUserGuildSettings'); @@ -11,7 +11,7 @@ const Guild = require('./Guild'); * Represents the logged in client's Discord user. * @extends {User} */ -class ClientUser extends User { +class ClientUser extends Structures.get('User') { _patch(data) { super._patch(data); From be02875f05246f73ecc2b0cb58409426b2309dbb Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 24 Nov 2017 23:16:21 -0500 Subject: [PATCH 16/16] I don't even --- src/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/index.js b/src/index.js index 1108f23f6..244c6a5ea 100644 --- a/src/index.js +++ b/src/index.js @@ -84,5 +84,3 @@ module.exports = { WebSocket: require('./WebSocket'), }; - -Object.