fix(RelationshipManager): change sendFriendRequest to hopefully reduce account bans
This commit is contained in:
@@ -126,6 +126,19 @@ class RelationshipManager extends BaseManager {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a {@link UserResolvable} to a {@link User} username.
|
||||||
|
* @param {UserResolvable} user The UserResolvable to identify
|
||||||
|
* @returns {?string}
|
||||||
|
*/
|
||||||
|
resolveUsername(user) {
|
||||||
|
if (user instanceof ThreadMember) return user.member.user.username;
|
||||||
|
if (user instanceof GuildMember) return user.user.username;
|
||||||
|
if (user instanceof Message) return user.author.username;
|
||||||
|
if (user instanceof User) return user.username;
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains a user from Discord, or the user cache if it's already available.
|
* Obtains a user from Discord, or the user cache if it's already available.
|
||||||
* @param {UserResolvable} [user] The user to fetch
|
* @param {UserResolvable} [user] The user to fetch
|
||||||
@@ -164,7 +177,7 @@ class RelationshipManager extends BaseManager {
|
|||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
await this.client.api.users['@me'].relationships[id].delete({
|
await this.client.api.users['@me'].relationships[id].delete({
|
||||||
DiscordContext: { location: 'Friends' },
|
DiscordContext: { location: 'ContextMenu' },
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -183,17 +196,22 @@ class RelationshipManager extends BaseManager {
|
|||||||
*/
|
*/
|
||||||
async sendFriendRequest(options) {
|
async sendFriendRequest(options) {
|
||||||
if (options?.user) {
|
if (options?.user) {
|
||||||
const id = this.resolveId(options.user);
|
const username = this.resolveUsername(options.user);
|
||||||
await this.client.api.users['@me'].relationships[id].put({
|
await this.client.api.users['@me'].relationships.post({
|
||||||
data: {},
|
versioned: true,
|
||||||
DiscordContext: { location: 'ContextMenu' },
|
data: {
|
||||||
|
username,
|
||||||
|
discriminator: null,
|
||||||
|
},
|
||||||
|
DiscordContext: { location: 'Add Friend' },
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
await this.client.api.users['@me'].relationships.post({
|
await this.client.api.users['@me'].relationships.post({
|
||||||
|
versioned: true,
|
||||||
data: {
|
data: {
|
||||||
username: options.username,
|
username: options.username,
|
||||||
discriminator: options.discriminator,
|
discriminator: null,
|
||||||
},
|
},
|
||||||
DiscordContext: { location: 'Add Friend' },
|
DiscordContext: { location: 'Add Friend' },
|
||||||
});
|
});
|
||||||
@@ -213,9 +231,7 @@ class RelationshipManager extends BaseManager {
|
|||||||
// Check if outgoing request
|
// Check if outgoing request
|
||||||
if (this.cache.get(id) === RelationshipTypes.PENDING_OUTGOING) return Promise.resolve(false);
|
if (this.cache.get(id) === RelationshipTypes.PENDING_OUTGOING) return Promise.resolve(false);
|
||||||
await this.client.api.users['@me'].relationships[id].put({
|
await this.client.api.users['@me'].relationships[id].put({
|
||||||
data: {
|
data: {},
|
||||||
type: RelationshipTypes.FRIEND,
|
|
||||||
},
|
|
||||||
DiscordContext: { location: 'Friends' },
|
DiscordContext: { location: 'Friends' },
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user