mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
refactor(actions): removed unnecessary actions (#10666)
Removed actions that were only being used in their respective websocket handlers. The remaining actions either were either being used elsewhere or were using methods from the `GenericAction` class. Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
This commit is contained in:
@@ -11,36 +11,20 @@ class ActionsManager {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
this.register(require('./ApplicationCommandPermissionsUpdate'));
|
|
||||||
this.register(require('./AutoModerationActionExecution'));
|
|
||||||
this.register(require('./AutoModerationRuleCreate'));
|
|
||||||
this.register(require('./AutoModerationRuleDelete'));
|
|
||||||
this.register(require('./AutoModerationRuleUpdate'));
|
|
||||||
this.register(require('./ChannelCreate'));
|
this.register(require('./ChannelCreate'));
|
||||||
this.register(require('./ChannelDelete'));
|
this.register(require('./ChannelDelete'));
|
||||||
this.register(require('./ChannelUpdate'));
|
this.register(require('./ChannelUpdate'));
|
||||||
this.register(require('./EntitlementCreate'));
|
|
||||||
this.register(require('./EntitlementDelete'));
|
|
||||||
this.register(require('./EntitlementUpdate'));
|
|
||||||
this.register(require('./GuildAuditLogEntryCreate'));
|
|
||||||
this.register(require('./GuildBanAdd'));
|
|
||||||
this.register(require('./GuildBanRemove'));
|
|
||||||
this.register(require('./GuildChannelsPositionUpdate'));
|
this.register(require('./GuildChannelsPositionUpdate'));
|
||||||
this.register(require('./GuildDelete'));
|
|
||||||
this.register(require('./GuildEmojiCreate'));
|
this.register(require('./GuildEmojiCreate'));
|
||||||
this.register(require('./GuildEmojiDelete'));
|
this.register(require('./GuildEmojiDelete'));
|
||||||
this.register(require('./GuildEmojiUpdate'));
|
this.register(require('./GuildEmojiUpdate'));
|
||||||
this.register(require('./GuildEmojisUpdate'));
|
this.register(require('./GuildEmojisUpdate'));
|
||||||
this.register(require('./GuildIntegrationsUpdate'));
|
|
||||||
this.register(require('./GuildMemberRemove'));
|
this.register(require('./GuildMemberRemove'));
|
||||||
this.register(require('./GuildMemberUpdate'));
|
this.register(require('./GuildMemberUpdate'));
|
||||||
this.register(require('./GuildRoleCreate'));
|
this.register(require('./GuildRoleCreate'));
|
||||||
this.register(require('./GuildRoleDelete'));
|
this.register(require('./GuildRoleDelete'));
|
||||||
this.register(require('./GuildRoleUpdate'));
|
|
||||||
this.register(require('./GuildRolesPositionUpdate'));
|
this.register(require('./GuildRolesPositionUpdate'));
|
||||||
this.register(require('./GuildScheduledEventCreate'));
|
|
||||||
this.register(require('./GuildScheduledEventDelete'));
|
this.register(require('./GuildScheduledEventDelete'));
|
||||||
this.register(require('./GuildScheduledEventUpdate'));
|
|
||||||
this.register(require('./GuildScheduledEventUserAdd'));
|
this.register(require('./GuildScheduledEventUserAdd'));
|
||||||
this.register(require('./GuildScheduledEventUserRemove'));
|
this.register(require('./GuildScheduledEventUserRemove'));
|
||||||
this.register(require('./GuildStickerCreate'));
|
this.register(require('./GuildStickerCreate'));
|
||||||
@@ -49,8 +33,6 @@ class ActionsManager {
|
|||||||
this.register(require('./GuildStickersUpdate'));
|
this.register(require('./GuildStickersUpdate'));
|
||||||
this.register(require('./GuildUpdate'));
|
this.register(require('./GuildUpdate'));
|
||||||
this.register(require('./InteractionCreate'));
|
this.register(require('./InteractionCreate'));
|
||||||
this.register(require('./InviteCreate'));
|
|
||||||
this.register(require('./InviteDelete'));
|
|
||||||
this.register(require('./MessageCreate'));
|
this.register(require('./MessageCreate'));
|
||||||
this.register(require('./MessageDelete'));
|
this.register(require('./MessageDelete'));
|
||||||
this.register(require('./MessageDeleteBulk'));
|
this.register(require('./MessageDeleteBulk'));
|
||||||
@@ -61,19 +43,13 @@ class ActionsManager {
|
|||||||
this.register(require('./MessageReactionRemoveAll'));
|
this.register(require('./MessageReactionRemoveAll'));
|
||||||
this.register(require('./MessageReactionRemoveEmoji'));
|
this.register(require('./MessageReactionRemoveEmoji'));
|
||||||
this.register(require('./MessageUpdate'));
|
this.register(require('./MessageUpdate'));
|
||||||
this.register(require('./PresenceUpdate'));
|
|
||||||
this.register(require('./StageInstanceCreate'));
|
this.register(require('./StageInstanceCreate'));
|
||||||
this.register(require('./StageInstanceDelete'));
|
this.register(require('./StageInstanceDelete'));
|
||||||
this.register(require('./StageInstanceUpdate'));
|
this.register(require('./StageInstanceUpdate'));
|
||||||
this.register(require('./ThreadCreate'));
|
this.register(require('./ThreadCreate'));
|
||||||
this.register(require('./ThreadDelete'));
|
|
||||||
this.register(require('./ThreadListSync'));
|
|
||||||
this.register(require('./ThreadMemberUpdate'));
|
|
||||||
this.register(require('./ThreadMembersUpdate'));
|
this.register(require('./ThreadMembersUpdate'));
|
||||||
this.register(require('./TypingStart'));
|
this.register(require('./TypingStart'));
|
||||||
this.register(require('./UserUpdate'));
|
this.register(require('./UserUpdate'));
|
||||||
this.register(require('./VoiceStateUpdate'));
|
|
||||||
this.register(require('./WebhooksUpdate'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register(Action) {
|
register(Action) {
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The data received in the {@link Client#event:applicationCommandPermissionsUpdate} event
|
|
||||||
* @typedef {Object} ApplicationCommandPermissionsUpdateData
|
|
||||||
* @property {Snowflake} id The id of the command or global entity that was updated
|
|
||||||
* @property {Snowflake} guildId The id of the guild in which permissions were updated
|
|
||||||
* @property {Snowflake} applicationId The id of the application that owns the command or entity being updated
|
|
||||||
* @property {ApplicationCommandPermissions[]} permissions The updated permissions
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ApplicationCommandPermissionsUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
/**
|
|
||||||
* Emitted whenever permissions for an application command in a guild were updated.
|
|
||||||
* <warn>This includes permission updates for other applications in addition to the logged in client,
|
|
||||||
* check `data.applicationId` to verify which application the update is for</warn>
|
|
||||||
* @event Client#applicationCommandPermissionsUpdate
|
|
||||||
* @param {ApplicationCommandPermissionsUpdateData} data The updated permissions
|
|
||||||
*/
|
|
||||||
client.emit(Events.ApplicationCommandPermissionsUpdate, {
|
|
||||||
permissions: data.permissions,
|
|
||||||
id: data.id,
|
|
||||||
guildId: data.guild_id,
|
|
||||||
applicationId: data.application_id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ApplicationCommandPermissionsUpdateAction;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class AutoModerationActionExecutionAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const { client } = this;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
/**
|
|
||||||
* Emitted whenever an auto moderation rule is triggered.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
|
||||||
* @event Client#autoModerationActionExecution
|
|
||||||
* @param {AutoModerationActionExecution} autoModerationActionExecution The data of the execution
|
|
||||||
*/
|
|
||||||
client.emit(Events.AutoModerationActionExecution, new AutoModerationActionExecution(data, guild));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AutoModerationActionExecutionAction;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class AutoModerationRuleCreateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const { client } = this;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
const autoModerationRule = guild.autoModerationRules._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an auto moderation rule is created.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
|
||||||
* @event Client#autoModerationRuleCreate
|
|
||||||
* @param {AutoModerationRule} autoModerationRule The created auto moderation rule
|
|
||||||
*/
|
|
||||||
client.emit(Events.AutoModerationRuleCreate, autoModerationRule);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AutoModerationRuleCreateAction;
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class AutoModerationRuleDeleteAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const { client } = this;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
const autoModerationRule = guild.autoModerationRules.cache.get(data.id);
|
|
||||||
|
|
||||||
if (autoModerationRule) {
|
|
||||||
guild.autoModerationRules.cache.delete(autoModerationRule.id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an auto moderation rule is deleted.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
|
||||||
* @event Client#autoModerationRuleDelete
|
|
||||||
* @param {AutoModerationRule} autoModerationRule The deleted auto moderation rule
|
|
||||||
*/
|
|
||||||
client.emit(Events.AutoModerationRuleDelete, autoModerationRule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AutoModerationRuleDeleteAction;
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class AutoModerationRuleUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const { client } = this;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
const oldAutoModerationRule = guild.autoModerationRules.cache.get(data.id)?._clone() ?? null;
|
|
||||||
const newAutoModerationRule = guild.autoModerationRules._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an auto moderation rule gets updated.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
|
||||||
* @event Client#autoModerationRuleUpdate
|
|
||||||
* @param {?AutoModerationRule} oldAutoModerationRule The auto moderation rule before the update
|
|
||||||
* @param {AutoModerationRule} newAutoModerationRule The auto moderation rule after the update
|
|
||||||
*/
|
|
||||||
client.emit(Events.AutoModerationRuleUpdate, oldAutoModerationRule, newAutoModerationRule);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AutoModerationRuleUpdateAction;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class EntitlementCreateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
|
|
||||||
const entitlement = client.application.entitlements._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an entitlement is created.
|
|
||||||
* @event Client#entitlementCreate
|
|
||||||
* @param {Entitlement} entitlement The entitlement that was created
|
|
||||||
*/
|
|
||||||
client.emit(Events.EntitlementCreate, entitlement);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = EntitlementCreateAction;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class EntitlementDeleteAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
|
|
||||||
const entitlement = client.application.entitlements._add(data, false);
|
|
||||||
|
|
||||||
client.application.entitlements.cache.delete(entitlement.id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an entitlement is deleted.
|
|
||||||
* <warn>Entitlements are not deleted when they expire.
|
|
||||||
* This is only triggered when Discord issues a refund or deletes the entitlement manually.</warn>
|
|
||||||
* @event Client#entitlementDelete
|
|
||||||
* @param {Entitlement} entitlement The entitlement that was deleted
|
|
||||||
*/
|
|
||||||
client.emit(Events.EntitlementDelete, entitlement);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = EntitlementDeleteAction;
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class EntitlementUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
|
|
||||||
const oldEntitlement = client.application.entitlements.cache.get(data.id)?._clone() ?? null;
|
|
||||||
const newEntitlement = client.application.entitlements._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
|
|
||||||
* @event Client#entitlementUpdate
|
|
||||||
* @param {?Entitlement} oldEntitlement The entitlement before the update
|
|
||||||
* @param {Entitlement} newEntitlement The entitlement after the update
|
|
||||||
*/
|
|
||||||
client.emit(Events.EntitlementUpdate, oldEntitlement, newEntitlement);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = EntitlementUpdateAction;
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const GuildAuditLogsEntry = require('../../structures/GuildAuditLogsEntry');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildAuditLogEntryCreateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
let auditLogEntry;
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
auditLogEntry = new GuildAuditLogsEntry(guild, data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild audit log entry is created.
|
|
||||||
* @event Client#guildAuditLogEntryCreate
|
|
||||||
* @param {GuildAuditLogsEntry} auditLogEntry The entry that was created
|
|
||||||
* @param {Guild} guild The guild where the entry was created
|
|
||||||
*/
|
|
||||||
client.emit(Events.GuildAuditLogEntryCreate, auditLogEntry, guild);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { auditLogEntry };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildAuditLogEntryCreateAction;
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildBanAdd extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a member is banned from a guild.
|
|
||||||
* @event Client#guildBanAdd
|
|
||||||
* @param {GuildBan} ban The ban that occurred
|
|
||||||
*/
|
|
||||||
if (guild) client.emit(Events.GuildBanAdd, guild.bans._add(data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildBanAdd;
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const GuildBan = require('../../structures/GuildBan');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildBanRemove extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a member is unbanned from a guild.
|
|
||||||
* @event Client#guildBanRemove
|
|
||||||
* @param {GuildBan} ban The ban that was removed
|
|
||||||
*/
|
|
||||||
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.GuildBanRemove, ban);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildBanRemove;
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildDeleteAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
|
|
||||||
let guild = client.guilds.cache.get(data.id);
|
|
||||||
if (guild) {
|
|
||||||
if (data.unavailable) {
|
|
||||||
// Guild is unavailable
|
|
||||||
guild.available = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild becomes unavailable, likely due to a server outage.
|
|
||||||
* @event Client#guildUnavailable
|
|
||||||
* @param {Guild} guild The guild that has become unavailable
|
|
||||||
*/
|
|
||||||
client.emit(Events.GuildUnavailable, guild);
|
|
||||||
|
|
||||||
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
|
||||||
// handles emitting of event itself
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
|
|
||||||
client.voice.adapters.get(data.id)?.destroy();
|
|
||||||
|
|
||||||
// Delete guild
|
|
||||||
client.guilds.cache.delete(guild.id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild kicks the client or the guild is deleted/left.
|
|
||||||
* @event Client#guildDelete
|
|
||||||
* @param {Guild} guild The guild that was deleted
|
|
||||||
*/
|
|
||||||
client.emit(Events.GuildDelete, guild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildDeleteAction;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildIntegrationsUpdate extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild integration is updated
|
|
||||||
* @event Client#guildIntegrationsUpdate
|
|
||||||
* @param {Guild} guild The guild whose integrations were updated
|
|
||||||
*/
|
|
||||||
if (guild) client.emit(Events.GuildIntegrationsUpdate, guild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildIntegrationsUpdate;
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildRoleUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
let old = null;
|
|
||||||
|
|
||||||
const role = guild.roles.cache.get(data.role.id);
|
|
||||||
if (role) {
|
|
||||||
old = role._update(data.role);
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild role is updated.
|
|
||||||
* @event Client#roleUpdate
|
|
||||||
* @param {Role} oldRole The role before the update
|
|
||||||
* @param {Role} newRole The role after the update
|
|
||||||
*/
|
|
||||||
client.emit(Events.GuildRoleUpdate, old, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
old,
|
|
||||||
updated: role,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
old: null,
|
|
||||||
updated: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildRoleUpdateAction;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildScheduledEventCreateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
if (guild) {
|
|
||||||
const guildScheduledEvent = guild.scheduledEvents._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild scheduled event is created.
|
|
||||||
* @event Client#guildScheduledEventCreate
|
|
||||||
* @param {GuildScheduledEvent} guildScheduledEvent The created guild scheduled event
|
|
||||||
*/
|
|
||||||
client.emit(Events.GuildScheduledEventCreate, guildScheduledEvent);
|
|
||||||
|
|
||||||
return { guildScheduledEvent };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildScheduledEventCreateAction;
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class GuildScheduledEventUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
const oldGuildScheduledEvent = guild.scheduledEvents.cache.get(data.id)?._clone() ?? null;
|
|
||||||
const newGuildScheduledEvent = guild.scheduledEvents._add(data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild scheduled event gets updated.
|
|
||||||
* @event Client#guildScheduledEventUpdate
|
|
||||||
* @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.GuildScheduledEventUpdate, oldGuildScheduledEvent, newGuildScheduledEvent);
|
|
||||||
|
|
||||||
return { oldGuildScheduledEvent, newGuildScheduledEvent };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = GuildScheduledEventUpdateAction;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class InviteCreateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const channel = client.channels.cache.get(data.channel_id);
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
if (!channel) return false;
|
|
||||||
|
|
||||||
const inviteData = Object.assign(data, { channel, guild });
|
|
||||||
const invite = guild.invites._add(inviteData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted when an invite is created.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
|
||||||
* @event Client#inviteCreate
|
|
||||||
* @param {Invite} invite The invite that was created
|
|
||||||
*/
|
|
||||||
client.emit(Events.InviteCreate, invite);
|
|
||||||
return { invite };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = InviteCreateAction;
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Invite = require('../../structures/Invite');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class InviteDeleteAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const channel = client.channels.cache.get(data.channel_id);
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
if (!channel) return false;
|
|
||||||
|
|
||||||
const inviteData = Object.assign(data, { channel, guild });
|
|
||||||
const invite = new Invite(client, inviteData);
|
|
||||||
guild.invites.cache.delete(invite.code);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted when an invite is deleted.
|
|
||||||
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
|
||||||
* @event Client#inviteDelete
|
|
||||||
* @param {Invite} invite The invite that was deleted
|
|
||||||
*/
|
|
||||||
client.emit(Events.InviteDelete, invite);
|
|
||||||
return { invite };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = InviteDeleteAction;
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
const Partials = require('../util/Partials');
|
|
||||||
|
|
||||||
class PresenceUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
let user = this.client.users.cache.get(data.user.id);
|
|
||||||
if (!user && ('username' in data.user || this.client.options.partials.includes(Partials.User))) {
|
|
||||||
user = this.client.users._add(data.user);
|
|
||||||
}
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
if (data.user.username) {
|
|
||||||
if (!user._equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
|
|
||||||
}
|
|
||||||
|
|
||||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
|
|
||||||
let member = guild.members.cache.get(user.id);
|
|
||||||
if (!member && data.status !== 'offline') {
|
|
||||||
member = guild.members._add({
|
|
||||||
user,
|
|
||||||
deaf: false,
|
|
||||||
mute: false,
|
|
||||||
});
|
|
||||||
this.client.emit(Events.GuildMemberAvailable, member);
|
|
||||||
}
|
|
||||||
const newPresence = guild.presences._add(Object.assign(data, { guild }));
|
|
||||||
if (this.client.listenerCount(Events.PresenceUpdate) && !newPresence.equals(oldPresence)) {
|
|
||||||
/**
|
|
||||||
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
|
|
||||||
* @event Client#presenceUpdate
|
|
||||||
* @param {?Presence} oldPresence The presence before the update, if one at all
|
|
||||||
* @param {Presence} newPresence The presence after the update
|
|
||||||
*/
|
|
||||||
this.client.emit(Events.PresenceUpdate, oldPresence, newPresence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = PresenceUpdateAction;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class ThreadDeleteAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const thread = client.channels.cache.get(data.id);
|
|
||||||
|
|
||||||
if (thread) {
|
|
||||||
client.channels._remove(thread.id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a thread is deleted.
|
|
||||||
* @event Client#threadDelete
|
|
||||||
* @param {ThreadChannel} thread The thread that was deleted
|
|
||||||
*/
|
|
||||||
client.emit(Events.ThreadDelete, thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { thread };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ThreadDeleteAction;
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const { Collection } = require('@discordjs/collection');
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class ThreadListSyncAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
if (!guild) return {};
|
|
||||||
|
|
||||||
if (data.channel_ids) {
|
|
||||||
for (const id of data.channel_ids) {
|
|
||||||
const channel = client.channels.cache.get(id);
|
|
||||||
if (channel) this.removeStale(channel);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const channel of guild.channels.cache.values()) {
|
|
||||||
this.removeStale(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const syncedThreads = data.threads.reduce((coll, rawThread) => {
|
|
||||||
const thread = client.channels._add(rawThread);
|
|
||||||
return coll.set(thread.id, thread);
|
|
||||||
}, new Collection());
|
|
||||||
|
|
||||||
for (const rawMember of Object.values(data.members)) {
|
|
||||||
// Discord sends the thread id as id in this object
|
|
||||||
const thread = client.channels.cache.get(rawMember.id);
|
|
||||||
if (thread) {
|
|
||||||
thread.members._add(rawMember);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever the client user gains access to a text or announcement channel that contains threads
|
|
||||||
* @event Client#threadListSync
|
|
||||||
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
|
|
||||||
* @param {Guild} guild The guild that the threads were synced in
|
|
||||||
*/
|
|
||||||
client.emit(Events.ThreadListSync, syncedThreads, guild);
|
|
||||||
|
|
||||||
return {
|
|
||||||
syncedThreads,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
removeStale(channel) {
|
|
||||||
channel.threads?.cache.forEach(thread => {
|
|
||||||
if (!thread.archived) {
|
|
||||||
this.client.channels._remove(thread.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ThreadListSyncAction;
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class ThreadMemberUpdateAction extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
// Discord sends the thread id as id in this object
|
|
||||||
const thread = client.channels.cache.get(data.id);
|
|
||||||
if (thread) {
|
|
||||||
const member = thread.members.cache.get(data.user_id);
|
|
||||||
if (!member) {
|
|
||||||
const newMember = thread.members._add(data);
|
|
||||||
return { newMember };
|
|
||||||
}
|
|
||||||
const old = member._update(data);
|
|
||||||
/**
|
|
||||||
* Emitted whenever the client user's thread member is updated.
|
|
||||||
* @event Client#threadMemberUpdate
|
|
||||||
* @param {ThreadMember} oldMember The member before the update
|
|
||||||
* @param {ThreadMember} newMember The member after the update
|
|
||||||
*/
|
|
||||||
client.emit(Events.ThreadMemberUpdate, old, member);
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ThreadMemberUpdateAction;
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const VoiceState = require('../../structures/VoiceState');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class VoiceStateUpdate extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
|
||||||
if (guild) {
|
|
||||||
// Update the state
|
|
||||||
const oldState =
|
|
||||||
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
|
|
||||||
|
|
||||||
const newState = guild.voiceStates._add(data);
|
|
||||||
|
|
||||||
// Get the member
|
|
||||||
let member = guild.members.cache.get(data.user_id);
|
|
||||||
if (member && data.member) {
|
|
||||||
member._patch(data.member);
|
|
||||||
} else if (data.member?.user && data.member.joined_at) {
|
|
||||||
member = guild.members._add(data.member);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit event
|
|
||||||
if (member?.user.id === client.user.id) {
|
|
||||||
client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`);
|
|
||||||
client.voice.onVoiceStateUpdate(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
|
||||||
* @event Client#voiceStateUpdate
|
|
||||||
* @param {VoiceState} oldState The voice state before the update
|
|
||||||
* @param {VoiceState} newState The voice state after the update
|
|
||||||
*/
|
|
||||||
client.emit(Events.VoiceStateUpdate, oldState, newState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = VoiceStateUpdate;
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Action = require('./Action');
|
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
|
||||||
class WebhooksUpdate extends Action {
|
|
||||||
handle(data) {
|
|
||||||
const client = this.client;
|
|
||||||
const channel = client.channels.cache.get(data.channel_id);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted whenever a channel has its webhooks changed.
|
|
||||||
* @event Client#webhooksUpdate
|
|
||||||
* @param {TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
|
||||||
* The channel that had a webhook update
|
|
||||||
*/
|
|
||||||
client.emit(Events.WebhooksUpdate, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = WebhooksUpdate;
|
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.ApplicationCommandPermissionsUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
/**
|
||||||
|
* Emitted whenever permissions for an application command in a guild were updated.
|
||||||
|
* <warn>This includes permission updates for other applications in addition to the logged in client,
|
||||||
|
* check `data.applicationId` to verify which application the update is for</warn>
|
||||||
|
* @event Client#applicationCommandPermissionsUpdate
|
||||||
|
* @param {ApplicationCommandPermissionsUpdateData} data The updated permissions
|
||||||
|
*/
|
||||||
|
client.emit(Events.ApplicationCommandPermissionsUpdate, {
|
||||||
|
permissions: data.permissions,
|
||||||
|
id: data.id,
|
||||||
|
guildId: data.guild_id,
|
||||||
|
applicationId: data.application_id,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const AutoModerationActionExecution = require('../../../structures/AutoModerationActionExecution.js');
|
||||||
client.actions.AutoModerationActionExecution.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an auto moderation rule is triggered.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||||
|
* @event Client#autoModerationActionExecution
|
||||||
|
* @param {AutoModerationActionExecution} autoModerationActionExecution The data of the execution
|
||||||
|
*/
|
||||||
|
client.emit(Events.AutoModerationActionExecution, new AutoModerationActionExecution(data, guild));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events');
|
||||||
client.actions.AutoModerationRuleCreate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const autoModerationRule = guild.autoModerationRules._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an auto moderation rule is created.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||||
|
* @event Client#autoModerationRuleCreate
|
||||||
|
* @param {AutoModerationRule} autoModerationRule The created auto moderation rule
|
||||||
|
*/
|
||||||
|
client.emit(Events.AutoModerationRuleCreate, autoModerationRule);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.AutoModerationRuleDelete.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const autoModerationRule = guild.autoModerationRules.cache.get(data.id);
|
||||||
|
if (!autoModerationRule) return;
|
||||||
|
|
||||||
|
guild.autoModerationRules.cache.delete(autoModerationRule.id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an auto moderation rule is deleted.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||||
|
* @event Client#autoModerationRuleDelete
|
||||||
|
* @param {AutoModerationRule} autoModerationRule The deleted auto moderation rule
|
||||||
|
*/
|
||||||
|
client.emit(Events.AutoModerationRuleDelete, autoModerationRule);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.AutoModerationRuleUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const oldAutoModerationRule = guild.autoModerationRules.cache.get(data.id)?._clone() ?? null;
|
||||||
|
const newAutoModerationRule = guild.autoModerationRules._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an auto moderation rule gets updated.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||||
|
* @event Client#autoModerationRuleUpdate
|
||||||
|
* @param {?AutoModerationRule} oldAutoModerationRule The auto moderation rule before the update
|
||||||
|
* @param {AutoModerationRule} newAutoModerationRule The auto moderation rule after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.AutoModerationRuleUpdate, oldAutoModerationRule, newAutoModerationRule);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.EntitlementCreate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const entitlement = client.application.entitlements._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an entitlement is created.
|
||||||
|
* @event Client#entitlementCreate
|
||||||
|
* @param {Entitlement} entitlement The entitlement that was created
|
||||||
|
*/
|
||||||
|
client.emit(Events.EntitlementCreate, entitlement);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.EntitlementDelete.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const entitlement = client.application.entitlements._add(data, false);
|
||||||
|
|
||||||
|
client.application.entitlements.cache.delete(entitlement.id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an entitlement is deleted.
|
||||||
|
* <warn>Entitlements are not deleted when they expire.
|
||||||
|
* This is only triggered when Discord issues a refund or deletes the entitlement manually.</warn>
|
||||||
|
* @event Client#entitlementDelete
|
||||||
|
* @param {Entitlement} entitlement The entitlement that was deleted
|
||||||
|
*/
|
||||||
|
client.emit(Events.EntitlementDelete, entitlement);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.EntitlementUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const oldEntitlement = client.application.entitlements.cache.get(data.id)?._clone() ?? null;
|
||||||
|
const newEntitlement = client.application.entitlements._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
|
||||||
|
* @event Client#entitlementUpdate
|
||||||
|
* @param {?Entitlement} oldEntitlement The entitlement before the update
|
||||||
|
* @param {Entitlement} newEntitlement The entitlement after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.EntitlementUpdate, oldEntitlement, newEntitlement);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const GuildAuditLogsEntry = require('../../../structures/GuildAuditLogsEntry.js');
|
||||||
client.actions.GuildAuditLogEntryCreate.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const auditLogEntry = new GuildAuditLogsEntry(guild, data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild audit log entry is created.
|
||||||
|
* @event Client#guildAuditLogEntryCreate
|
||||||
|
* @param {GuildAuditLogsEntry} auditLogEntry The entry that was created
|
||||||
|
* @param {Guild} guild The guild where the entry was created
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildAuditLogEntryCreate, auditLogEntry, guild);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildBanAdd.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a member is banned from a guild.
|
||||||
|
* @event Client#guildBanAdd
|
||||||
|
* @param {GuildBan} ban The ban that occurred
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildBanAdd, guild.bans._add(data));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const GuildBan = require('../../../structures/GuildBan.js');
|
||||||
client.actions.GuildBanRemove.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const ban = guild.bans.cache.get(data.user.id) ?? new GuildBan(client, data, guild);
|
||||||
|
|
||||||
|
guild.bans.cache.delete(ban.user.id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a member is unbanned from a guild.
|
||||||
|
* @event Client#guildBanRemove
|
||||||
|
* @param {GuildBan} ban The ban that was removed
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildBanRemove, ban);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,35 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildDelete.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
if (data.unavailable) {
|
||||||
|
guild.available = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild becomes unavailable, likely due to a server outage.
|
||||||
|
* @event Client#guildUnavailable
|
||||||
|
* @param {Guild} guild The guild that has become unavailable
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildUnavailable, guild);
|
||||||
|
|
||||||
|
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
||||||
|
// handles emitting of event itself
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const channel of guild.channels.cache.values()) client.channels._remove(channel.id);
|
||||||
|
client.voice.adapters.get(data.id)?.destroy();
|
||||||
|
|
||||||
|
client.guilds.cache.delete(guild.id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild kicks the client or the guild is deleted/left.
|
||||||
|
* @event Client#guildDelete
|
||||||
|
* @param {Guild} guild The guild that was deleted
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildDelete, guild);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildIntegrationsUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild integration is updated
|
||||||
|
* @event Client#guildIntegrationsUpdate
|
||||||
|
* @param {Guild} guild The guild whose integrations were updated
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildIntegrationsUpdate, guild);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildRoleUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const role = guild.roles.cache.get(data.role.id);
|
||||||
|
if (!role) return;
|
||||||
|
|
||||||
|
const old = role._update(data.role);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild role is updated.
|
||||||
|
* @event Client#roleUpdate
|
||||||
|
* @param {Role} oldRole The role before the update
|
||||||
|
* @param {Role} newRole The role after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildRoleUpdate, old, role);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildScheduledEventCreate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const guildScheduledEvent = guild.scheduledEvents._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild scheduled event is created.
|
||||||
|
* @event Client#guildScheduledEventCreate
|
||||||
|
* @param {GuildScheduledEvent} guildScheduledEvent The created guild scheduled event
|
||||||
|
*/
|
||||||
|
client.emit(Events.GuildScheduledEventCreate, guildScheduledEvent);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.GuildScheduledEventUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const oldGuildScheduledEvent = guild.scheduledEvents.cache.get(data.id)?._clone() ?? null;
|
||||||
|
const newGuildScheduledEvent = guild.scheduledEvents._add(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild scheduled event gets updated.
|
||||||
|
* @event Client#guildScheduledEventUpdate
|
||||||
|
* @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.GuildScheduledEventUpdate, oldGuildScheduledEvent, newGuildScheduledEvent);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.InviteCreate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const channel = client.channels.cache.get(data.channel_id);
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const inviteData = Object.assign(data, { channel, guild });
|
||||||
|
const invite = guild.invites._add(inviteData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when an invite is created.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
||||||
|
* @event Client#inviteCreate
|
||||||
|
* @param {Invite} invite The invite that was created
|
||||||
|
*/
|
||||||
|
client.emit(Events.InviteCreate, invite);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Invite = require('../../../structures/Invite.js');
|
||||||
client.actions.InviteDelete.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const channel = client.channels.cache.get(data.channel_id);
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const inviteData = Object.assign(data, { channel, guild });
|
||||||
|
const invite = new Invite(client, inviteData);
|
||||||
|
|
||||||
|
guild.invites.cache.delete(invite.code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when an invite is deleted.
|
||||||
|
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
||||||
|
* @event Client#inviteDelete
|
||||||
|
* @param {Invite} invite The invite that was deleted
|
||||||
|
*/
|
||||||
|
client.emit(Events.InviteDelete, invite);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,43 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.PresenceUpdate.handle(packet.d);
|
const Partials = require('../../../util/Partials.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
let user = client.users.cache.get(data.user.id);
|
||||||
|
if (!user && ('username' in data.user || client.options.partials.includes(Partials.User))) {
|
||||||
|
user = client.users._add(data.user);
|
||||||
|
}
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
if (data.user.username) {
|
||||||
|
if (!user._equals(data.user)) client.actions.UserUpdate.handle(data.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
|
||||||
|
|
||||||
|
let member = guild.members.cache.get(user.id);
|
||||||
|
if (!member && data.status !== 'offline') {
|
||||||
|
member = guild.members._add({
|
||||||
|
user,
|
||||||
|
deaf: false,
|
||||||
|
mute: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
client.emit(Events.GuildMemberAvailable, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newPresence = guild.presences._add(Object.assign(data, { guild }));
|
||||||
|
if (client.listenerCount(Events.PresenceUpdate) > 0 && !newPresence.equals(oldPresence)) {
|
||||||
|
/**
|
||||||
|
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
|
||||||
|
* @event Client#presenceUpdate
|
||||||
|
* @param {?Presence} oldPresence The presence before the update, if one at all
|
||||||
|
* @param {Presence} newPresence The presence after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.PresenceUpdate, oldPresence, newPresence);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.ThreadDelete.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const thread = client.channels.cache.get(data.id);
|
||||||
|
if (!thread) return;
|
||||||
|
|
||||||
|
client.channels._remove(thread.id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a thread is deleted.
|
||||||
|
* @event Client#threadDelete
|
||||||
|
* @param {ThreadChannel} thread The thread that was deleted
|
||||||
|
*/
|
||||||
|
client.emit(Events.ThreadDelete, thread);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,49 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const { Collection } = require('@discordjs/collection');
|
||||||
client.actions.ThreadListSync.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
if (data.channel_ids) {
|
||||||
|
for (const id of data.channel_ids) {
|
||||||
|
const channel = client.channels.cache.get(id);
|
||||||
|
if (channel) removeStaleThreads(client, channel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const channel of guild.channels.cache.values()) {
|
||||||
|
removeStaleThreads(client, channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const syncedThreads = data.threads.reduce((coll, rawThread) => {
|
||||||
|
const thread = client.channels._add(rawThread);
|
||||||
|
return coll.set(thread.id, thread);
|
||||||
|
}, new Collection());
|
||||||
|
|
||||||
|
for (const rawMember of Object.values(data.members)) {
|
||||||
|
// Discord sends the thread id as id in this object
|
||||||
|
const thread = client.channels.cache.get(rawMember.id);
|
||||||
|
if (thread) {
|
||||||
|
thread.members._add(rawMember);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever the client user gains access to a text or announcement channel that contains threads
|
||||||
|
* @event Client#threadListSync
|
||||||
|
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
|
||||||
|
* @param {Guild} guild The guild that the threads were synced in
|
||||||
|
*/
|
||||||
|
client.emit(Events.ThreadListSync, syncedThreads, guild);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function removeStaleThreads(client, channel) {
|
||||||
|
channel.threads?.cache.forEach(thread => {
|
||||||
|
if (!thread.archived) {
|
||||||
|
client.channels._remove(thread.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.ThreadMemberUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
// Discord sends the thread id as id in this object
|
||||||
|
const thread = client.channels.cache.get(data.id);
|
||||||
|
if (!thread) return;
|
||||||
|
|
||||||
|
const member = thread.members.cache.get(data.user_id);
|
||||||
|
if (!member) {
|
||||||
|
thread.members._add(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const old = member._update(data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever the client user's thread member is updated.
|
||||||
|
* @event Client#threadMemberUpdate
|
||||||
|
* @param {ThreadMember} oldMember The member before the update
|
||||||
|
* @param {ThreadMember} newMember The member after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.ThreadMemberUpdate, old, member);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,37 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const VoiceState = require('../../../structures/VoiceState.js');
|
||||||
client.actions.VoiceStateUpdate.handle(packet.d);
|
const Events = require('../../../util/Events.js');
|
||||||
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
// Update the state
|
||||||
|
const oldState =
|
||||||
|
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
|
||||||
|
|
||||||
|
const newState = guild.voiceStates._add(data);
|
||||||
|
|
||||||
|
// Get the member
|
||||||
|
let member = guild.members.cache.get(data.user_id);
|
||||||
|
if (member && data.member) {
|
||||||
|
member._patch(data.member);
|
||||||
|
} else if (data.member?.user && data.member.joined_at) {
|
||||||
|
member = guild.members._add(data.member);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit event
|
||||||
|
if (member?.user.id === client.user.id) {
|
||||||
|
client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`);
|
||||||
|
client.voice.onVoiceStateUpdate(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||||
|
* @event Client#voiceStateUpdate
|
||||||
|
* @param {VoiceState} oldState The voice state before the update
|
||||||
|
* @param {VoiceState} newState The voice state after the update
|
||||||
|
*/
|
||||||
|
client.emit(Events.VoiceStateUpdate, oldState, newState);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
const Events = require('../../../util/Events.js');
|
||||||
client.actions.WebhooksUpdate.handle(packet.d);
|
|
||||||
|
module.exports = (client, { d: data }) => {
|
||||||
|
const channel = client.channels.cache.get(data.channel_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted whenever a channel has its webhooks changed.
|
||||||
|
* @event Client#webhooksUpdate
|
||||||
|
* @param {TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
||||||
|
* The channel that had a webhook update
|
||||||
|
*/
|
||||||
|
client.emit(Events.WebhooksUpdate, channel);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user