Skip to content

Commit

Permalink
Revert "fix(Structures): remove Structures (discordjs#6027)"
Browse files Browse the repository at this point in the history
This reverts commit ab0b3b9.
  • Loading branch information
GamingGeek committed Oct 29, 2021
1 parent 761a901 commit 9462478
Show file tree
Hide file tree
Showing 11 changed files with 6,898 additions and 116 deletions.
3 changes: 2 additions & 1 deletion src/client/Client.js
Expand Up @@ -11,7 +11,6 @@ const ChannelManager = require('../managers/ChannelManager');
const GuildManager = require('../managers/GuildManager');
const UserManager = require('../managers/UserManager');
const ShardClientUtil = require('../sharding/ShardClientUtil');
const ClientPresence = require('../structures/ClientPresence');
const GuildPreview = require('../structures/GuildPreview');
const GuildTemplate = require('../structures/GuildTemplate');
const Invite = require('../structures/Invite');
Expand All @@ -25,6 +24,7 @@ const DataResolver = require('../util/DataResolver');
const Intents = require('../util/Intents');
const Options = require('../util/Options');
const Permissions = require('../util/Permissions');
const Structures = require('../util/Structures');

/**
* The main hub for interacting with the Discord API, and the starting point for any bot.
Expand Down Expand Up @@ -135,6 +135,7 @@ class Client extends BaseClient {
*/
this.channels = new ChannelManager(this);

const ClientPresence = Structures.get('ClientPresence');
/**
* The presence of the Client
* @private
Expand Down
16 changes: 6 additions & 10 deletions src/client/actions/InteractionCreate.js
@@ -1,12 +1,8 @@
'use strict';

const Action = require('./Action');
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
const ButtonInteraction = require('../../structures/ButtonInteraction');
const CommandInteraction = require('../../structures/CommandInteraction');
const ContextMenuInteraction = require('../../structures/ContextMenuInteraction');
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');
const Structures = require('../../util/Structures');

let deprecationEmitted = false;

Expand All @@ -22,11 +18,11 @@ class InteractionCreateAction extends Action {
case InteractionTypes.APPLICATION_COMMAND:
switch (data.data.type) {
case ApplicationCommandTypes.CHAT_INPUT:
InteractionType = CommandInteraction;
InteractionType = Structures.get('CommandInteraction');
break;
case ApplicationCommandTypes.USER:
case ApplicationCommandTypes.MESSAGE:
InteractionType = ContextMenuInteraction;
InteractionType = Structures.get('ContextMenuInteraction');
break;
default:
client.emit(
Expand All @@ -39,10 +35,10 @@ class InteractionCreateAction extends Action {
case InteractionTypes.MESSAGE_COMPONENT:
switch (data.data.component_type) {
case MessageComponentTypes.BUTTON:
InteractionType = ButtonInteraction;
InteractionType = Structures.get('ButtonInteraction');
break;
case MessageComponentTypes.SELECT_MENU:
InteractionType = SelectMenuInteraction;
InteractionType = Structures.get('SelectMenuInteraction');
break;
default:
client.emit(
Expand All @@ -53,7 +49,7 @@ class InteractionCreateAction extends Action {
}
break;
case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE:
InteractionType = AutocompleteInteraction;
InteractionType = Structures.get('AutocompleteInteraction');
break;
default:
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
Expand Down
3 changes: 2 additions & 1 deletion src/client/actions/VoiceStateUpdate.js
@@ -1,14 +1,15 @@
'use strict';

const Action = require('./Action');
const VoiceState = require('../../structures/VoiceState');
const { Events } = require('../../util/Constants');
const Structures = require('../../util/Structures');

class VoiceStateUpdate extends Action {
handle(data) {
const client = this.client;
const guild = client.guilds.cache.get(data.guild_id);
if (guild) {
const VoiceState = Structures.get('VoiceState');
// Update the state
const oldState =
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -133,6 +133,7 @@ exports.StageInstance = require('./structures/StageInstance');
exports.Sticker = require('./structures/Sticker');
exports.StickerPack = require('./structures/StickerPack');
exports.StoreChannel = require('./structures/StoreChannel');
exports.Structures = require('./util/Structures');
exports.Team = require('./structures/Team');
exports.TeamMember = require('./structures/TeamMember');
exports.TextChannel = require('./structures/TextChannel');
Expand Down
6 changes: 5 additions & 1 deletion src/managers/DataManager.js
Expand Up @@ -3,6 +3,8 @@
const BaseManager = require('./BaseManager');
const { Error } = require('../errors');

let Structures;

/**
* Manages the API methods of a data model along with a collection of instances.
* @extends {BaseManager}
Expand All @@ -12,14 +14,16 @@ class DataManager extends BaseManager {
constructor(client, holds) {
super(client);

if (!Structures) Structures = require('../util/Structures');

/**
* The data structure belonging to this manager.
* @name DataManager#holds
* @type {Function}
* @private
* @readonly
*/
Object.defineProperty(this, 'holds', { value: holds });
Object.defineProperty(this, 'holds', { value: Structures.get(holds.name) ?? holds });
}

/**
Expand Down
28 changes: 10 additions & 18 deletions src/structures/Channel.js
@@ -1,14 +1,6 @@
'use strict';

const Base = require('./Base');
let CategoryChannel;
let DMChannel;
let NewsChannel;
let StageChannel;
let StoreChannel;
let TextChannel;
let ThreadChannel;
let VoiceChannel;
const { ChannelTypes, ThreadChannelTypes, VoiceBasedChannelTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');

Expand Down Expand Up @@ -132,21 +124,14 @@ class Channel extends Base {
}

static create(client, data, guild, { allowUnknownGuild, fromInteraction } = {}) {
CategoryChannel ??= require('./CategoryChannel');
DMChannel ??= require('./DMChannel');
NewsChannel ??= require('./NewsChannel');
StageChannel ??= require('./StageChannel');
StoreChannel ??= require('./StoreChannel');
TextChannel ??= require('./TextChannel');
ThreadChannel ??= require('./ThreadChannel');
VoiceChannel ??= require('./VoiceChannel');

const Structures = require('../util/Structures');
let channel;
if (!data.guild_id && !guild) {
if ((data.recipients && data.type !== ChannelTypes.GROUP_DM) || data.type === ChannelTypes.DM) {
const DMChannel = Structures.get('DMChannel');
channel = new DMChannel(client, data);
} else if (data.type === ChannelTypes.GROUP_DM) {
const PartialGroupDMChannel = require('./PartialGroupDMChannel');
const PartialGroupDMChannel = Structures.get('PartialGroupDMChannel');
channel = new PartialGroupDMChannel(client, data);
}
} else {
Expand All @@ -155,32 +140,39 @@ class Channel extends Base {
if (guild || allowUnknownGuild) {
switch (data.type) {
case ChannelTypes.GUILD_TEXT: {
const TextChannel = Structures.get('TextChannel');
channel = new TextChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_VOICE: {
const VoiceChannel = Structures.get('VoiceChannel');
channel = new VoiceChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_CATEGORY: {
const CategoryChannel = Structures.get('CategoryChannel');
channel = new CategoryChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_NEWS: {
const NewsChannel = Structures.get('NewsChannel');
channel = new NewsChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_STORE: {
const StoreChannel = Structures.get('StoreChannel');
channel = new StoreChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_STAGE_VOICE: {
const StageChannel = Structures.get('StageChannel');
channel = new StageChannel(guild, data, client);
break;
}
case ChannelTypes.GUILD_NEWS_THREAD:
case ChannelTypes.GUILD_PUBLIC_THREAD:
case ChannelTypes.GUILD_PRIVATE_THREAD: {
const ThreadChannel = Structures.get('ThreadChannel');
channel = new ThreadChannel(guild, data, client, fromInteraction);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
Expand Down
9 changes: 7 additions & 2 deletions src/structures/ClientUser.js
@@ -1,13 +1,18 @@
'use strict';

const User = require('./User');
const DataResolver = require('../util/DataResolver');
const Structures = require('../util/Structures');

/**
* Represents the logged in client's Discord user.
* @extends {User}
*/
class ClientUser extends User {
class ClientUser extends Structures.get('User') {
constructor(client, data) {
super(client, data);
this._typing = new Map();
}

_patch(data) {
super._patch(data);

Expand Down
16 changes: 14 additions & 2 deletions src/structures/GuildMember.js
@@ -1,11 +1,11 @@
'use strict';

const Base = require('./Base');
const VoiceState = require('./VoiceState');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors');
const GuildMemberRoleManager = require('../managers/GuildMemberRoleManager');
const Permissions = require('../util/Permissions');
let Structures;

/**
* Represents a member of a guild on Discord.
Expand Down Expand Up @@ -113,6 +113,8 @@ class GuildMember extends Base {
* @readonly
*/
get voice() {
if (!Structures) Structures = require('../util/Structures');
const VoiceState = Structures.get('VoiceState');
return this.guild.voiceStates.cache.get(this.id) ?? new VoiceState(this.guild, { user_id: this.id });
}

Expand Down Expand Up @@ -160,7 +162,17 @@ class GuildMember extends Base {
* @readonly
*/
get presence() {
return this.guild.presences.resolve(this.id);
if (!Structures) Structures = require('../util/Structures');
const Presence = Structures.get('Presence');
return (
this.guild.presences.cache.get(this.id) ??
new Presence(this.client, {
user: {
id: this.id,
},
guild: this.guild,
})
);
}

/**
Expand Down

0 comments on commit 9462478

Please sign in to comment.