mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
add way more friend shit (#815)
This commit is contained in:
committed by
Schuyler Cebulskie
parent
9f7c630796
commit
422b90c711
File diff suppressed because one or more lines are too long
@@ -658,6 +658,24 @@ class RESTMethods {
|
|||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockUser(user) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('put', `${Constants.Endpoints.relationships('@me')}/${user.id}`, true, { type: 2 })
|
||||||
|
.then(() => {
|
||||||
|
resolve(user);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
unblockUser(user) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('delete', `${Constants.Endpoints.relationships('@me')}/${user.id}`, true)
|
||||||
|
.then(() => {
|
||||||
|
resolve(user);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RESTMethods;
|
module.exports = RESTMethods;
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ class WebSocketPacketManager {
|
|||||||
this.register(Constants.WSEvents.MESSAGE_DELETE_BULK, 'MessageDeleteBulk');
|
this.register(Constants.WSEvents.MESSAGE_DELETE_BULK, 'MessageDeleteBulk');
|
||||||
this.register(Constants.WSEvents.CHANNEL_PINS_UPDATE, 'ChannelPinsUpdate');
|
this.register(Constants.WSEvents.CHANNEL_PINS_UPDATE, 'ChannelPinsUpdate');
|
||||||
this.register(Constants.WSEvents.GUILD_SYNC, 'GuildSync');
|
this.register(Constants.WSEvents.GUILD_SYNC, 'GuildSync');
|
||||||
|
this.register(Constants.WSEvents.RELATIONSHIP_ADD, 'RelationshipAdd');
|
||||||
|
this.register(Constants.WSEvents.RELATIONSHIP_REMOVE, 'RelationshipRemove');
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
get client() {
|
||||||
|
|||||||
@@ -17,8 +17,12 @@ class ReadyHandler extends AbstractHandler {
|
|||||||
for (const privateDM of data.private_channels) client.dataManager.newChannel(privateDM);
|
for (const privateDM of data.private_channels) client.dataManager.newChannel(privateDM);
|
||||||
|
|
||||||
for (const relation of data.relationships) {
|
for (const relation of data.relationships) {
|
||||||
const friend = client.dataManager.newUser(relation.user);
|
const user = client.dataManager.newUser(relation.user);
|
||||||
client.user.friends.set(friend.id, friend);
|
if (relation.type === 1) {
|
||||||
|
client.user.friends.set(user.id, user);
|
||||||
|
} else if (relation.type === 2) {
|
||||||
|
client.user.blocked.set(user.id, user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.presences = data.presences || [];
|
data.presences = data.presences || [];
|
||||||
|
|||||||
19
src/client/websocket/packets/handlers/RelationshipAdd.js
Normal file
19
src/client/websocket/packets/handlers/RelationshipAdd.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const AbstractHandler = require('./AbstractHandler');
|
||||||
|
|
||||||
|
class RelationshipAddHandler extends AbstractHandler {
|
||||||
|
handle(packet) {
|
||||||
|
const client = this.packetManager.client;
|
||||||
|
const data = packet.d;
|
||||||
|
if (data.type === 1) {
|
||||||
|
client.fetchUser(data.id).then(user => {
|
||||||
|
client.user.friends.set(user.id, user);
|
||||||
|
});
|
||||||
|
} else if (data.type === 2) {
|
||||||
|
client.fetchUser(data.id).then(user => {
|
||||||
|
client.user.blocked.set(user.id, user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RelationshipAddHandler;
|
||||||
19
src/client/websocket/packets/handlers/RelationshipRemove.js
Normal file
19
src/client/websocket/packets/handlers/RelationshipRemove.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const AbstractHandler = require('./AbstractHandler');
|
||||||
|
|
||||||
|
class RelationshipRemoveHandler extends AbstractHandler {
|
||||||
|
handle(packet) {
|
||||||
|
const client = this.packetManager.client;
|
||||||
|
const data = packet.d;
|
||||||
|
if (data.type === 2) {
|
||||||
|
if (client.user.blocked.has(data.id)) {
|
||||||
|
client.user.blocked.delete(data.id);
|
||||||
|
}
|
||||||
|
} else if (data.type === 1) {
|
||||||
|
if (client.user.friends.has(data.id)) {
|
||||||
|
client.user.friends.delete(data.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RelationshipRemoveHandler;
|
||||||
@@ -29,6 +29,13 @@ class ClientUser extends User {
|
|||||||
* @type {Collection<string, User>}
|
* @type {Collection<string, User>}
|
||||||
*/
|
*/
|
||||||
this.friends = new Collection();
|
this.friends = new Collection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Collection of blocked users for the logged in user.
|
||||||
|
* <warn>This is only filled for user accounts, not bot accounts!</warn>
|
||||||
|
* @type {Collection<string, User>}
|
||||||
|
*/
|
||||||
|
this.blocked = new Collection();
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(data) {
|
edit(data) {
|
||||||
|
|||||||
@@ -135,6 +135,38 @@ class User {
|
|||||||
return this.client.rest.methods.deleteChannel(this);
|
return this.client.rest.methods.deleteChannel(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a friend request to the user
|
||||||
|
* @returns {Promise<User>}
|
||||||
|
*/
|
||||||
|
addFriend() {
|
||||||
|
return this.client.rest.methods.addFriend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the user from your friends
|
||||||
|
* @returns {Promise<User>}
|
||||||
|
*/
|
||||||
|
removeFriend() {
|
||||||
|
return this.client.rest.methods.removeFriend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks the user
|
||||||
|
* @returns {Promise<User>}
|
||||||
|
*/
|
||||||
|
block() {
|
||||||
|
return this.client.rest.methods.blockUser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unblocks the user
|
||||||
|
* @returns {Promise<User>}
|
||||||
|
*/
|
||||||
|
unblock() {
|
||||||
|
return this.client.rest.methods.unblockUser(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
|
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
|
||||||
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
||||||
|
|||||||
@@ -226,6 +226,8 @@ exports.WSEvents = {
|
|||||||
FRIEND_ADD: 'RELATIONSHIP_ADD',
|
FRIEND_ADD: 'RELATIONSHIP_ADD',
|
||||||
FRIEND_REMOVE: 'RELATIONSHIP_REMOVE',
|
FRIEND_REMOVE: 'RELATIONSHIP_REMOVE',
|
||||||
VOICE_SERVER_UPDATE: 'VOICE_SERVER_UPDATE',
|
VOICE_SERVER_UPDATE: 'VOICE_SERVER_UPDATE',
|
||||||
|
RELATIONSHIP_ADD: 'RELATIONSHIP_ADD',
|
||||||
|
RELATIONSHIP_REMOVE: 'RELATIONSHIP_REMOVE',
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.MessageTypes = {
|
exports.MessageTypes = {
|
||||||
|
|||||||
Reference in New Issue
Block a user