Skip to content

Commit

Permalink
refactor: Make constants enums top level and PascalCase (#7379)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitor <milagre.vitor@gmail.com>
Co-authored-by: almeidx <almeidx@pm.me>
  • Loading branch information
3 people committed Feb 5, 2022
1 parent cd2f566 commit d8184f9
Show file tree
Hide file tree
Showing 81 changed files with 625 additions and 640 deletions.
10 changes: 6 additions & 4 deletions packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const StickerPack = require('../structures/StickerPack');
const VoiceRegion = require('../structures/VoiceRegion');
const Webhook = require('../structures/Webhook');
const Widget = require('../structures/Widget');
const { Events, InviteScopes, Status } = require('../util/Constants');
const { InviteScopes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Events = require('../util/Events');
const IntentsBitField = require('../util/IntentsBitField');
const Options = require('../util/Options');
const PermissionsBitField = require('../util/PermissionsBitField');
const Status = require('../util/Status');
const Sweepers = require('../util/Sweepers');

/**
Expand Down Expand Up @@ -213,7 +215,7 @@ class Client extends BaseClient {
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
this.rest.setToken(token);
this.emit(
Events.DEBUG,
Events.Debug,
`Provided token: ${token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
Expand All @@ -224,7 +226,7 @@ class Client extends BaseClient {
this.options.ws.presence = this.presence._parse(this.options.presence);
}

this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
this.emit(Events.Debug, 'Preparing to connect to the gateway...');

try {
await this.ws.connect();
Expand All @@ -241,7 +243,7 @@ class Client extends BaseClient {
* @returns {boolean}
*/
isReady() {
return this.ws.status === Status.READY;
return this.ws.status === Status.Ready;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/ChannelCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class ChannelCreateAction extends Action {
handle(data) {
Expand All @@ -14,7 +14,7 @@ class ChannelCreateAction extends Action {
* @event Client#channelCreate
* @param {GuildChannel} channel The channel that was created
*/
client.emit(Events.CHANNEL_CREATE, channel);
client.emit(Events.ChannelCreate, channel);
}
return { channel };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/ChannelDelete.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class ChannelDeleteAction extends Action {
handle(data) {
Expand All @@ -15,7 +15,7 @@ class ChannelDeleteAction extends Action {
* @event Client#channelDelete
* @param {DMChannel|GuildChannel} channel The channel that was deleted
*/
client.emit(Events.CHANNEL_DELETE, channel);
client.emit(Events.ChannelDelete, channel);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildBanAdd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildBanAdd extends Action {
handle(data) {
Expand All @@ -13,7 +13,7 @@ class GuildBanAdd extends Action {
* @event Client#guildBanAdd
* @param {GuildBan} ban The ban that occurred
*/
if (guild) client.emit(Events.GUILD_BAN_ADD, guild.bans._add(data));
if (guild) client.emit(Events.GuildBanAdd, guild.bans._add(data));
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildBanRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

class GuildBanRemove extends Action {
handle(data) {
Expand All @@ -17,7 +17,7 @@ class GuildBanRemove extends Action {
if (guild) {
const ban = guild.bans.cache.get(data.user.id) ?? new GuildBan(client, data, guild);
guild.bans.cache.delete(ban.user.id);
client.emit(Events.GUILD_BAN_REMOVE, ban);
client.emit(Events.GuildBanRemove, ban);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/client/actions/GuildDelete.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildDeleteAction extends Action {
handle(data) {
Expand All @@ -18,7 +18,7 @@ class GuildDeleteAction extends Action {
* @event Client#guildUnavailable
* @param {Guild} guild The guild that has become unavailable
*/
client.emit(Events.GUILD_UNAVAILABLE, guild);
client.emit(Events.GuildUnavailable, guild);

// Stops the GuildDelete packet thinking a guild was actually deleted,
// handles emitting of event itself
Expand All @@ -36,7 +36,7 @@ class GuildDeleteAction extends Action {
* @event Client#guildDelete
* @param {Guild} guild The guild that was deleted
*/
client.emit(Events.GUILD_DELETE, guild);
client.emit(Events.GuildDelete, guild);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildEmojiCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildEmojiCreateAction extends Action {
handle(guild, createdEmoji) {
Expand All @@ -12,7 +12,7 @@ class GuildEmojiCreateAction extends Action {
* @event Client#emojiCreate
* @param {GuildEmoji} emoji The emoji that was created
*/
if (!already) this.client.emit(Events.GUILD_EMOJI_CREATE, emoji);
if (!already) this.client.emit(Events.GuildEmojiCreate, emoji);
return { emoji };
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildEmojiDelete.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildEmojiDeleteAction extends Action {
handle(emoji) {
Expand All @@ -11,7 +11,7 @@ class GuildEmojiDeleteAction extends Action {
* @event Client#emojiDelete
* @param {GuildEmoji} emoji The emoji that was deleted
*/
this.client.emit(Events.GUILD_EMOJI_DELETE, emoji);
this.client.emit(Events.GuildEmojiDelete, emoji);
return { emoji };
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildEmojiUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildEmojiUpdateAction extends Action {
handle(current, data) {
Expand All @@ -12,7 +12,7 @@ class GuildEmojiUpdateAction extends Action {
* @param {GuildEmoji} oldEmoji The old emoji
* @param {GuildEmoji} newEmoji The new emoji
*/
this.client.emit(Events.GUILD_EMOJI_UPDATE, old, current);
this.client.emit(Events.GuildEmojiUpdate, old, current);
return { emoji: current };
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildIntegrationsUpdate extends Action {
handle(data) {
Expand All @@ -12,7 +12,7 @@ class GuildIntegrationsUpdate extends Action {
* @event Client#guildIntegrationsUpdate
* @param {Guild} guild The guild whose integrations were updated
*/
if (guild) client.emit(Events.GUILD_INTEGRATIONS_UPDATE, guild);
if (guild) client.emit(Events.GuildIntegrationsUpdate, guild);
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/discord.js/src/client/actions/GuildMemberRemove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const Action = require('./Action');
const { Events, Status } = require('../../util/Constants');
const Events = require('../../util/Events');
const Status = require('../../util/Status');

class GuildMemberRemoveAction extends Action {
handle(data, shard) {
Expand All @@ -18,7 +19,7 @@ class GuildMemberRemoveAction extends Action {
* @event Client#guildMemberRemove
* @param {GuildMember} member The member that has left/been kicked from the guild
*/
if (shard.status === Status.READY) client.emit(Events.GUILD_MEMBER_REMOVE, member);
if (shard.status === Status.Ready) client.emit(Events.GuildMemberRemove, member);
}
guild.voiceStates.cache.delete(data.user.id);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/discord.js/src/client/actions/GuildMemberUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const Action = require('./Action');
const { Status, Events } = require('../../util/Constants');
const Events = require('../../util/Events');
const Status = require('../../util/Status');

class GuildMemberUpdateAction extends Action {
handle(data, shard) {
Expand All @@ -26,15 +27,15 @@ class GuildMemberUpdateAction extends Action {
* @param {GuildMember} oldMember The member before the update
* @param {GuildMember} newMember The member after the update
*/
if (shard.status === Status.READY && !member.equals(old)) client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
if (shard.status === Status.Ready && !member.equals(old)) client.emit(Events.GuildMemberUpdate, old, member);
} else {
const newMember = guild.members._add(data);
/**
* Emitted whenever a member becomes available in a large guild.
* @event Client#guildMemberAvailable
* @param {GuildMember} member The member that became available
*/
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, newMember);
this.client.emit(Events.GuildMemberAvailable, newMember);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildRoleCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildRoleCreate extends Action {
handle(data) {
Expand All @@ -16,7 +16,7 @@ class GuildRoleCreate extends Action {
* @event Client#roleCreate
* @param {Role} role The role that was created
*/
if (!already) client.emit(Events.GUILD_ROLE_CREATE, role);
if (!already) client.emit(Events.GuildRoleCreate, role);
}
return { role };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildRoleDelete.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildRoleDeleteAction extends Action {
handle(data) {
Expand All @@ -18,7 +18,7 @@ class GuildRoleDeleteAction extends Action {
* @event Client#roleDelete
* @param {Role} role The role that was deleted
*/
client.emit(Events.GUILD_ROLE_DELETE, role);
client.emit(Events.GuildRoleDelete, role);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/actions/GuildRoleUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildRoleUpdateAction extends Action {
handle(data) {
Expand All @@ -20,7 +20,7 @@ class GuildRoleUpdateAction extends Action {
* @param {Role} oldRole The role before the update
* @param {Role} newRole The role after the update
*/
client.emit(Events.GUILD_ROLE_UPDATE, old, role);
client.emit(Events.GuildRoleUpdate, old, role);
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildScheduledEventCreateAction extends Action {
handle(data) {
Expand All @@ -15,7 +15,7 @@ class GuildScheduledEventCreateAction extends Action {
* @event Client#guildScheduledEventCreate
* @param {GuildScheduledEvent} guildScheduledEvent The created guild scheduled event
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_CREATE, guildScheduledEvent);
client.emit(Events.GuildScheduledEventCreate, guildScheduledEvent);

return { guildScheduledEvent };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildScheduledEventDeleteAction extends Action {
handle(data) {
Expand All @@ -18,7 +18,7 @@ class GuildScheduledEventDeleteAction extends Action {
* @event Client#guildScheduledEventDelete
* @param {GuildScheduledEvent} guildScheduledEvent The deleted guild scheduled event
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_DELETE, guildScheduledEvent);
client.emit(Events.GuildScheduledEventDelete, guildScheduledEvent);

return { guildScheduledEvent };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildScheduledEventUpdateAction extends Action {
handle(data) {
Expand All @@ -18,7 +18,7 @@ class GuildScheduledEventUpdateAction extends Action {
* @param {?GuildScheduledEvent} oldGuildScheduledEvent The guild scheduled event object before the update
* @param {GuildScheduledEvent} newGuildScheduledEvent The guild scheduled event object after the update
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_UPDATE, oldGuildScheduledEvent, newGuildScheduledEvent);
client.emit(Events.GuildScheduledEventUpdate, oldGuildScheduledEvent, newGuildScheduledEvent);

return { oldGuildScheduledEvent, newGuildScheduledEvent };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

class GuildScheduledEventUserAddAction extends Action {
handle(data) {
Expand All @@ -19,7 +19,7 @@ class GuildScheduledEventUserAddAction extends Action {
* @param {GuildScheduledEvent} guildScheduledEvent The guild scheduled event
* @param {User} user The user who subscribed
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_USER_ADD, guildScheduledEvent, user);
client.emit(Events.GuildScheduledEventUserAdd, guildScheduledEvent, user);

return { guildScheduledEvent, user };
}
Expand Down
Loading

0 comments on commit d8184f9

Please sign in to comment.