This commit is contained in:
Elysia
2024-01-08 20:41:56 +07:00
parent f19c8e0aa6
commit 924c442ad4
11 changed files with 202 additions and 565 deletions

View File

@@ -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);
}
};

View File

@@ -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);
};

View File

@@ -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()

View File

@@ -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);
};

View File

@@ -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));
};

View File

@@ -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);
};

View File

@@ -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),
},
);
};