update
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const Action = require('./Action');
|
||||
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
|
||||
const ButtonInteraction = require('../../structures/ButtonInteraction');
|
||||
const CommandInteraction = require('../../structures/CommandInteraction');
|
||||
const MessageContextMenuInteraction = require('../../structures/MessageContextMenuInteraction');
|
||||
const ModalSubmitInteraction = require('../../structures/ModalSubmitInteraction');
|
||||
const {
|
||||
ChannelSelectInteraction,
|
||||
MentionableSelectInteraction,
|
||||
RoleSelectInteraction,
|
||||
SelectMenuInteraction,
|
||||
UserSelectInteraction,
|
||||
} = require('../../structures/SelectMenuInteraction');
|
||||
const UserContextMenuInteraction = require('../../structures/UserContextMenuInteraction');
|
||||
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class InteractionCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
// Resolve and cache partial channels for Interaction#channel getter
|
||||
const channel = this.getChannel(data);
|
||||
// Do not emit this for interactions that cache messages that are non-text-based.
|
||||
let InteractionType;
|
||||
switch (data.type) {
|
||||
case InteractionTypes.APPLICATION_COMMAND:
|
||||
switch (data.data.type) {
|
||||
case ApplicationCommandTypes.CHAT_INPUT:
|
||||
InteractionType = CommandInteraction;
|
||||
break;
|
||||
case ApplicationCommandTypes.USER:
|
||||
InteractionType = UserContextMenuInteraction;
|
||||
break;
|
||||
case ApplicationCommandTypes.MESSAGE:
|
||||
InteractionType = MessageContextMenuInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InteractionTypes.MESSAGE_COMPONENT:
|
||||
if (channel && !channel.isText()) return;
|
||||
switch (data.data.component_type) {
|
||||
case MessageComponentTypes.BUTTON:
|
||||
InteractionType = ButtonInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.STRING_SELECT:
|
||||
InteractionType = SelectMenuInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.CHANNEL_SELECT:
|
||||
InteractionType = ChannelSelectInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.MENTIONABLE_SELECT:
|
||||
InteractionType = MentionableSelectInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.ROLE_SELECT:
|
||||
InteractionType = RoleSelectInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.USER_SELECT:
|
||||
InteractionType = UserSelectInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE:
|
||||
InteractionType = AutocompleteInteraction;
|
||||
break;
|
||||
case InteractionTypes.MODAL_SUBMIT:
|
||||
InteractionType = ModalSubmitInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`[INTERACTION] Received [BOT] / Send (Selfbot) interactionID ${data.id} with unknown type: ${data.type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const interaction = new InteractionType(client, data);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interactionCreate
|
||||
* @param {InteractionResponseBody | Interaction} interaction The interaction which was created.
|
||||
*/
|
||||
client.emit(Events.INTERACTION_CREATE, interaction);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interaction
|
||||
* @param {Interaction} interaction The interaction which was created
|
||||
* @deprecated Use {@link Client#event:interactionCreate} instead
|
||||
*/
|
||||
if (client.emit('interaction', interaction) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The interaction event is deprecated. Use interactionCreate instead', 'DeprecationWarning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InteractionCreateAction;
|
@@ -1,16 +0,0 @@
|
||||
'use strict';
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
/**
|
||||
* @typedef {Object} InteractionResponseBody
|
||||
* @property {Snowflake} id Interaction ID
|
||||
* @property {Snowflake} nonce nonce in POST /interactions
|
||||
*/
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
if (client.user.bot) {
|
||||
client.actions.InteractionCreate.handle(data);
|
||||
} else {
|
||||
client.emit(Events.INTERACTION_CREATE, data);
|
||||
}
|
||||
};
|
@@ -1,18 +0,0 @@
|
||||
'use strict';
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
/**
|
||||
* Emitted whenever client user send interaction and error
|
||||
* @event Client#interactionFailure
|
||||
* @param {InteractionResponseBody} data data
|
||||
*/
|
||||
client.emit(Events.INTERACTION_FAILURE, data);
|
||||
client.emit('interactionResponse', {
|
||||
status: false,
|
||||
metadata: client._interactionCache.get(data.nonce),
|
||||
error: 'No response from bot',
|
||||
});
|
||||
// Delete cache
|
||||
client._interactionCache.delete(data.nonce);
|
||||
};
|
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
const Modal = require('../../../structures/Modal');
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
/**
|
||||
* Emitted whenever client user receive interaction.showModal()
|
||||
|
@@ -1,30 +0,0 @@
|
||||
'use strict';
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
/**
|
||||
* Emitted whenever client user send interaction and success
|
||||
* @event Client#interactionSuccess
|
||||
* @param {InteractionResponseBody} data data
|
||||
*/
|
||||
client.emit(Events.INTERACTION_SUCCESS, data);
|
||||
// Get channel data
|
||||
const cache = client._interactionCache.get(data.nonce);
|
||||
if (!cache) return;
|
||||
const channel = cache.guildId
|
||||
? client.guilds.cache.get(cache.guildId)?.channels.cache.get(cache.channelId)
|
||||
: client.channels.cache.get(cache.channelId);
|
||||
// Set data
|
||||
const interaction = {
|
||||
...cache,
|
||||
...data,
|
||||
};
|
||||
const data_ = channel.interactions._add(interaction);
|
||||
client.emit('interactionResponse', {
|
||||
status: true,
|
||||
metadata: data_,
|
||||
error: 'Success',
|
||||
});
|
||||
// Delete cache
|
||||
// client._interactionCache.delete(data.nonce);
|
||||
};
|
@@ -1,17 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { Events, RelationshipTypes } = require('../../../util/Constants');
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
if (data.user) {
|
||||
client.users._add(data.user);
|
||||
}
|
||||
client.relationships.cache.set(data.id, data.type);
|
||||
client.relationships.friendNicknames.set(data.id, data.nickname);
|
||||
client.relationships.sinceCache.set(data.id, new Date(data.since || 0));
|
||||
/**
|
||||
* Emitted whenever a relationship is updated.
|
||||
* Emitted when a relationship is created, relevant to the current user.
|
||||
* @event Client#relationshipAdd
|
||||
* @param {Snowflake} user The userID that was updated
|
||||
* @param {RelationshipTypes} type The new relationship type
|
||||
* @param {Snowflake} user Target userId
|
||||
* @param {boolean} shouldNotify Whether the client should notify the user of this relationship's creation
|
||||
*/
|
||||
client.emit(Events.RELATIONSHIP_ADD, data.id, RelationshipTypes[data.type]);
|
||||
client.emit(Events.RELATIONSHIP_ADD, data.id, Boolean(data.should_notify));
|
||||
};
|
||||
|
@@ -1,15 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const { Events, RelationshipTypes } = require('../../../util/Constants');
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
client.relationships.cache.delete(data.id);
|
||||
client.user.friendNicknames.delete(data.id);
|
||||
client.relationships.friendNicknames.delete(data.id);
|
||||
client.relationships.sinceCache.delete(data.id);
|
||||
/**
|
||||
* Emitted whenever a relationship is delete.
|
||||
* Emitted when a relationship is removed, relevant to the current user.
|
||||
* @event Client#relationshipRemove
|
||||
* @param {Snowflake} user The userID that was updated
|
||||
* @param {RelationshipTypes} type The type of the old relationship
|
||||
* @param {string | null} nickname The nickname of the user in this relationship (1-32 characters)
|
||||
*/
|
||||
client.emit(Events.RELATIONSHIP_REMOVE, data.id, RelationshipTypes[data.type]);
|
||||
client.emit(Events.RELATIONSHIP_REMOVE, data.id, data.type, data.nickname);
|
||||
};
|
||||
|
@@ -1,18 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const { Events, RelationshipTypes } = require('../../../util/Constants');
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
client.relationships.cache.set(data.id, data.type);
|
||||
/**
|
||||
* Emitted whenever a relationship is updated.
|
||||
* @typedef {Object} RelationshipUpdateObject
|
||||
* @property {RelationshipTypes} type The type of relationship
|
||||
* @property {Date} since When the user requested a relationship
|
||||
* @property {string | null} nickname The nickname of the user in this relationship (1-32 characters)
|
||||
*/
|
||||
/**
|
||||
* Emitted when a relationship is updated, relevant to the current user (e.g. friend nickname changed).
|
||||
* <info>This is not sent when the type of a relationship changes; see {@link Client#relationshipAdd} and {@link Client#relationshipRemove} for that.</info>
|
||||
* @event Client#relationshipUpdate
|
||||
* @param {Snowflake} user The userID that was updated
|
||||
* @param {RelationshipTypes} type The new relationship type
|
||||
* @param {Object} data The raw data
|
||||
* @param {RelationshipUpdateObject} oldData Old data
|
||||
* @param {RelationshipUpdateObject} newData New data
|
||||
*/
|
||||
if ('nickname' in data) {
|
||||
client.user.friendNicknames.set(data.id, data.nickname);
|
||||
}
|
||||
client.emit(Events.RELATIONSHIP_UPDATE, data.id, RelationshipTypes[data.type], data);
|
||||
const oldType = client.relationships.cache.get(data.id);
|
||||
const oldSince = client.relationships.sinceCache.get(data.id);
|
||||
const oldNickname = client.relationships.friendNicknames.get(data.id);
|
||||
// Update
|
||||
if (data.type) client.relationships.cache.set(data.id, data.type);
|
||||
if (data.nickname) client.relationships.friendNicknames.set(data.id, data.nickname);
|
||||
if (data.since) client.relationships.sinceCache.set(data.id, new Date(data.since || 0));
|
||||
client.emit(
|
||||
Events.RELATIONSHIP_UPDATE,
|
||||
data.id,
|
||||
{
|
||||
type: oldType,
|
||||
nickname: oldNickname,
|
||||
since: oldSince,
|
||||
},
|
||||
{
|
||||
type: data.type,
|
||||
nickname: data.nickname,
|
||||
since: new Date(data.since || 0),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user