Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Structures): remove Structures #6027

Merged
merged 2 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 @@ -22,7 +23,6 @@ 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 @@ -119,7 +119,6 @@ class Client extends BaseClient {
*/
this.channels = new ChannelManager(this);

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

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

let deprecationEmitted = false;

Expand All @@ -16,15 +18,15 @@ class InteractionCreateAction extends Action {
let InteractionType;
switch (data.type) {
case InteractionTypes.APPLICATION_COMMAND:
InteractionType = Structures.get('CommandInteraction');
InteractionType = CommandInteraction;
break;
case InteractionTypes.MESSAGE_COMPONENT:
switch (data.data.component_type) {
case MessageComponentTypes.BUTTON:
InteractionType = Structures.get('ButtonInteraction');
InteractionType = ButtonInteraction;
break;
case MessageComponentTypes.SELECT_MENU:
InteractionType = Structures.get('SelectMenuInteraction');
InteractionType = SelectMenuInteraction;
break;
default:
client.emit(
Expand Down
3 changes: 1 addition & 2 deletions src/client/actions/VoiceStateUpdate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'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: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
Options: require('./util/Options'),
Permissions: require('./util/Permissions'),
SnowflakeUtil: require('./util/SnowflakeUtil'),
Structures: require('./util/Structures'),
SystemChannelFlags: require('./util/SystemChannelFlags'),
ThreadMemberFlags: require('./util/ThreadMemberFlags'),
UserFlags: require('./util/UserFlags'),
Expand Down
6 changes: 1 addition & 5 deletions src/managers/DataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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 @@ -14,16 +12,14 @@ 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: Structures.get(holds.name) ?? holds });
Object.defineProperty(this, 'holds', { value: holds });
}

/**
Expand Down
26 changes: 17 additions & 9 deletions src/structures/Channel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'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 } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');

Expand Down Expand Up @@ -120,11 +128,18 @@ class Channel extends Base {
}

static create(client, data, guild) {
const Structures = require('../util/Structures');
if (!CategoryChannel) CategoryChannel = require('./CategoryChannel');
if (!DMChannel) DMChannel = require('./DMChannel');
if (!NewsChannel) NewsChannel = require('./NewsChannel');
if (!StageChannel) StageChannel = require('./StageChannel');
if (!StoreChannel) StoreChannel = require('./StoreChannel');
if (!TextChannel) TextChannel = require('./TextChannel');
if (!ThreadChannel) ThreadChannel = require('./ThreadChannel');
if (!VoiceChannel) VoiceChannel = require('./VoiceChannel');

let channel;
if (!data.guild_id && !guild) {
if ((data.recipients && data.type !== ChannelTypes.GROUP) || data.type === ChannelTypes.DM) {
const DMChannel = Structures.get('DMChannel');
channel = new DMChannel(client, data);
} else if (data.type === ChannelTypes.GROUP) {
const PartialGroupDMChannel = require('./PartialGroupDMChannel');
Expand All @@ -136,39 +151,32 @@ class Channel extends Base {
if (guild) {
switch (data.type) {
case ChannelTypes.TEXT: {
const TextChannel = Structures.get('TextChannel');
channel = new TextChannel(guild, data);
break;
}
case ChannelTypes.VOICE: {
const VoiceChannel = Structures.get('VoiceChannel');
channel = new VoiceChannel(guild, data);
break;
}
case ChannelTypes.CATEGORY: {
const CategoryChannel = Structures.get('CategoryChannel');
channel = new CategoryChannel(guild, data);
break;
}
case ChannelTypes.NEWS: {
const NewsChannel = Structures.get('NewsChannel');
channel = new NewsChannel(guild, data);
break;
}
case ChannelTypes.STORE: {
const StoreChannel = Structures.get('StoreChannel');
channel = new StoreChannel(guild, data);
break;
}
case ChannelTypes.STAGE: {
const StageChannel = Structures.get('StageChannel');
channel = new StageChannel(guild, data);
break;
}
case ChannelTypes.NEWS_THREAD:
case ChannelTypes.PUBLIC_THREAD:
case ChannelTypes.PRIVATE_THREAD: {
const ThreadChannel = Structures.get('ThreadChannel');
channel = new ThreadChannel(guild, data);
channel.parent?.threads.cache.set(channel.id, channel);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/structures/ClientUser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'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 Structures.get('User') {
class ClientUser extends User {
constructor(client, data) {
super(client, data);
this._typing = new Map();
Expand Down
7 changes: 2 additions & 5 deletions src/structures/GuildMember.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const Base = require('./Base');
const { Presence } = require('./Presence');
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 @@ -130,8 +131,6 @@ 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 @@ -159,8 +158,6 @@ class GuildMember extends Base {
* @readonly
*/
get presence() {
if (!Structures) Structures = require('../util/Structures');
const Presence = Structures.get('Presence');
return (
this.guild.presences.cache.get(this.id) ??
new Presence(this.client, {
Expand Down
5 changes: 1 addition & 4 deletions src/structures/User.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

const Base = require('./Base');
const { Presence } = require('./Presence');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const UserFlags = require('../util/UserFlags');

let Structures;

/**
* Represents a user on Discord.
* @implements {TextBasedChannel}
Expand Down Expand Up @@ -153,8 +152,6 @@ class User extends Base {
for (const guild of this.client.guilds.cache.values()) {
if (guild.presences.cache.has(this.id)) return guild.presences.cache.get(this.id);
}
if (!Structures) Structures = require('../util/Structures');
const Presence = Structures.get('Presence');
return new Presence(this.client, { user: { id: this.id } });
}

Expand Down
122 changes: 0 additions & 122 deletions src/util/Structures.js

This file was deleted.

Loading