Change logs:
+ New Event:
> relationshipAdd: user.id, type
> relationshipRemove: user.id
> client.relationships: RelationshipsManager
> User.relationships
> Update Document .-.
- DEPRECATED
> client.blocked
> client.friends
> clientUser.findFriend
> User.blocked
> User.friend
> some console.log()
This commit is contained in:
March 7th 2022-04-12 12:46:08 +07:00
parent 89d8b08a08
commit f73525f278
14 changed files with 297 additions and 163 deletions

View File

@ -93,6 +93,7 @@ User {
Code: Code:
```js ```js
// You can use client.relationships to manage your friends and blocked users.
GuildMember.user.setFriend(); GuildMember.user.setFriend();
User.unFriend(); User.unFriend();
Message.member.user.sendFriendRequest(); Message.member.user.sendFriendRequest();
@ -208,6 +209,7 @@ And you can change the status 5 times every 20 seconds!
await client.user.setHypeSquad('HOUSE_BRAVERY'); await client.user.setHypeSquad('HOUSE_BRAVERY');
await client.user.setHypeSquad('HOUSE_BRILLIANCE'); await client.user.setHypeSquad('HOUSE_BRILLIANCE');
await client.user.setHypeSquad('HOUSE_BALANCE'); await client.user.setHypeSquad('HOUSE_BALANCE');
await client.user.setHypeSquad('LEAVE');
// Set Note to User // Set Note to User
await user.setNote('Hello World'); await user.setNote('Hello World');
// Set Username // Set Username

View File

@ -1,6 +1,6 @@
{ {
"name": "discord.js-selfbot-v13", "name": "discord.js-selfbot-v13",
"version": "1.3.2", "version": "1.3.3",
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",

View File

@ -29,8 +29,7 @@ const Options = require('../util/Options');
const Permissions = require('../util/Permissions'); const Permissions = require('../util/Permissions');
const Sweepers = require('../util/Sweepers'); const Sweepers = require('../util/Sweepers');
// Patch // Patch
const FriendsManager = require('../managers/FriendsManager'); const RelationshipsManager = require('../managers/RelationshipsManager');
const BlockedManager = require('../managers/BlockedManager');
const ClientUserSettingManager = require('../managers/ClientUserSettingManager'); const ClientUserSettingManager = require('../managers/ClientUserSettingManager');
/** /**
@ -129,8 +128,7 @@ class Client extends BaseClient {
/** Patch /** Patch
* *
*/ */
this.friends = new FriendsManager(this); this.relationships = new RelationshipsManager(this);
this.blocked = new BlockedManager(this);
this.setting = new ClientUserSettingManager(this); this.setting = new ClientUserSettingManager(this);
/** /**
* All of the guilds the client is currently handling, mapped by their ids - * All of the guilds the client is currently handling, mapped by their ids -

View File

@ -38,9 +38,9 @@ module.exports = (client, { d: data }, shard) => {
// console.log(data); // console.log(data);
if (client.options.checkUpdate) { if (client.options.checkUpdate) {
try { try {
checkUpdate() checkUpdate();
} catch (e) { } catch (e) {
console.log(e) console.log(e);
} }
}; };
client.session_id = data.session_id; client.session_id = data.session_id;
@ -52,11 +52,6 @@ module.exports = (client, { d: data }, shard) => {
client.users.cache.set(client.user.id, client.user); client.users.cache.set(client.user.id, client.user);
} }
console.log(`
${chalk.yellow(
`Can you take a look at this notice and give me your opinion?\nhttps://github.com/aiko-chan-ai/discord.js-selfbot-v13/issues/29`,
)}`);
client.user.setAFK(false); client.user.setAFK(false);
client.setting.fetch().then(async (res) => { client.setting.fetch().then(async (res) => {
@ -88,13 +83,7 @@ ${chalk.yellow(
client.guilds._add(guild); client.guilds._add(guild);
} }
for (const r of data.relationships) { client.relationships._setup(data.relationships);
if (r.type == 1) {
client.friends.cache.set(r.id, new User(client, r.user));
} else if (r.type == 2) {
client.blocked.cache.set(r.id, new User(client, r.user));
}
}
shard.checkReady(); shard.checkReady();
}; };

View File

@ -0,0 +1,15 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
data.user ? client.users._add(data.user) : null;
client.relationships.cache.set(data.id, data.type);
/**
* Emitted whenever a relationship is updated.
* @event Client#relationshipUpdate
* @param {UserID} user The userID that was updated
* @param {Number} type The new relationship type
*/
client.emit(Events.RELATIONSHIP_ADD, data.id, data.type);
};

View File

@ -0,0 +1,13 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
client.relationships.cache.delete(data.id);
/**
* Emitted whenever a relationship is updated.
* @event Client#relationshipUpdate
* @param {UserID} user The userID that was updated
*/
client.emit(Events.RELATIONSHIP_REMOVE, data.id);
};

View File

@ -3,6 +3,8 @@
const handlers = Object.fromEntries([ const handlers = Object.fromEntries([
['READY', require('./READY')], ['READY', require('./READY')],
['RESUMED', require('./RESUMED')], ['RESUMED', require('./RESUMED')],
['RELATIONSHIP_ADD', require('./RELATIONSHIP_ADD')],
['RELATIONSHIP_REMOVE', require('./RELATIONSHIP_REMOVE')],
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')], ['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')],
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')], ['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')],
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')], ['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')],

View File

@ -65,6 +65,7 @@ exports.UserManager = require('./managers/UserManager');
exports.VoiceStateManager = require('./managers/VoiceStateManager'); exports.VoiceStateManager = require('./managers/VoiceStateManager');
exports.WebSocketManager = require('./client/websocket/WebSocketManager'); exports.WebSocketManager = require('./client/websocket/WebSocketManager');
exports.WebSocketShard = require('./client/websocket/WebSocketShard'); exports.WebSocketShard = require('./client/websocket/WebSocketShard');
exports.RelationshipsManager = require('./managers/RelationshipsManager');
// Structures // Structures
exports.Activity = require('./structures/Presence').Activity; exports.Activity = require('./structures/Presence').Activity;

View File

@ -432,7 +432,6 @@ class GuildMemberManager extends CachedManager {
}, },
}); });
} else { } else {
console.log('send lazy quest')
let channel; let channel;
let channels = this.guild.channels.cache.filter(c => c.isText()); let channels = this.guild.channels.cache.filter(c => c.isText());
channels = channels.filter(c => c.permissionsFor(this.guild.me).has('VIEW_CHANNEL')); channels = channels.filter(c => c.permissionsFor(this.guild.me).has('VIEW_CHANNEL'));

View File

@ -0,0 +1,115 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const { GuildMember } = require('../structures/GuildMember');
const { Message } = require('../structures/Message');
const ThreadMember = require('../structures/ThreadMember');
const User = require('../structures/User');
const { RelationshipTypes } = require('../util/Constants');
/**
* Manages API methods for users and stores their cache.
*/
class RelationshipsManager {
constructor(client, users) {
this.client = client;
this.cache = new Collection();
this._setup(users);
}
_setup(users) {
if (!Array.isArray(users)) return;
for (const relationShip of users) {
this.cache.set(relationShip.id, relationShip.type);
}
}
/**
* Resolves a {@link UserResolvable} to a {@link User} id.
* @param {UserResolvable} user The UserResolvable to identify
* @returns {?Snowflake}
*/
resolveId(user) {
if (user instanceof ThreadMember) return user.id;
if (user instanceof GuildMember) return user.user.id;
if (user instanceof Message) return user.author.id;
if (user instanceof User) return user.id;
return user;
}
/**
* Obtains a user from Discord, or the user cache if it's already available.
* @param {UserResolvable} user The user to fetch
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<User>}
*/
async fetch(user, { cache = true, force = false } = {}) {
const id = this.resolveId(user);
if (!force) {
const existing = this.cache.get(id);
if (existing && !existing.partial) return existing;
}
const data = await this.client.api.users['@me'].relationships.get();
await this._setup(data);
return this.cache.get(id);
}
// some option .-.
async deleteFriend(user) {
const id = this.resolveId(user);
// check if already friends
if (this.cache.get(id) !== RelationshipTypes.FRIEND) return false;
await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data
return true;
}
async deleteBlocked(user) {
const id = this.resolveId(user);
// check if already blocked
if (this.cache.get(id) !== RelationshipTypes.BLOCKED) return false;
await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data
return true;
}
async sendFriendRequest(username, discriminator) {
await this.client.api.users('@me').relationships.post({
data: {
username,
discriminator: parseInt(discriminator),
},
});
return true;
}
async addFriend(user) {
const id = this.resolveId(user);
// check if already friends
if (this.cache.get(id) === RelationshipTypes.FRIEND) return false;
// check if outgoing request
if (this.cache.get(id) === RelationshipTypes.OUTGOING_REQUEST) return false;
await this.client.api
.users['@me'].relationships[id].put({
data: {
type: RelationshipTypes.FRIEND,
},
});
return true;
}
async addBlocked(user) {
const id = this.resolveId(user);
// check
if (this.cache.get(id) === RelationshipTypes.BLOCKED) return false;
await this.client.api
.users['@me'].relationships[id].put({
data: {
type: RelationshipTypes.BLOCKED,
},
});
return true;
}
}
module.exports = RelationshipsManager;

View File

@ -7,6 +7,7 @@ const SnowflakeUtil = require('../util/SnowflakeUtil');
const UserFlags = require('../util/UserFlags'); const UserFlags = require('../util/UserFlags');
const { default: Collection } = require('@discordjs/collection'); const { default: Collection } = require('@discordjs/collection');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager'); const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const { Relationship } = require('../util/Constants');
/** /**
* Represents a user on Discord. * Represents a user on Discord.
@ -129,18 +130,12 @@ class User extends Base {
} }
/** /**
* Friend ? * Check relationship status
* @readonly * @readonly
*/ */
get friend() { get relationships() {
return this.client.friends.cache.has(this.id); const i = this.client.relationships.cache.get(this.id) ?? 0;
} return Relationship[parseInt(i)];
/**
* Blocked ?
* @readonly
*/
get blocked() {
return this.client.blocked.cache.has(this.id);
} }
// Code written by https://github.com/aiko-chan-ai // Code written by https://github.com/aiko-chan-ai
@ -185,10 +180,7 @@ class User extends Base {
* @returns {Promise<User>} the user object * @returns {Promise<User>} the user object
*/ */
async setFriend() { async setFriend() {
return await this.client.api return this.client.relationships.addFriend(this);
.user('@me')
.relationships[this.id].put({ data: { type: 1 } })
.then((_) => _);
} }
/** /**
@ -196,25 +188,14 @@ class User extends Base {
* @returns {Promise<User>} the user object * @returns {Promise<User>} the user object
*/ */
async sendFriendRequest() { async sendFriendRequest() {
return await this.client.api return this.client.relationships.sendFriendRequest(this.username, this.discriminator);
.users('@me')
.relationships.post({
data: {
username: this.username,
discriminator: parseInt(this.discriminator),
},
})
.then((_) => _);
} }
/** /**
* Blocks the user * Blocks the user
* @returns {Promise<User>} the user object * @returns {Promise<User>} the user object
*/ */
async setBlock() { async setBlock() {
return this.client.api return this.client.relationships.addBlocked(this);
.users('@me')
.relationships[this.id].put({ data: { type: 2 } })
.then((_) => _);
} }
/** /**
@ -222,19 +203,15 @@ class User extends Base {
* @returns {Promise<User>} the user object * @returns {Promise<User>} the user object
*/ */
async unBlock() { async unBlock() {
return this.client.api return this.client.relationships.deleteBlocked(this);
.users('@me')
.relationships[this.id].delete.then((_) => _);
} }
/** /**
* Removes the user from your friends list * Removes the user from your friends list
* @returns {Promise<User>} the user object * @returns {Promise<User>} the user object
*/ */
async unFriend() { unFriend() {
return this.client.api return this.client.relationships.deleteFriend(this);
.users('@me')
.relationships[this.id].delete.then((_) => _);
} }
/** /**

View File

@ -369,6 +369,8 @@ exports.Events = {
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete', GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete',
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd', GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd',
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove', GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove',
RELATIONSHIP_ADD: 'relationshipAdd',
RELATIONSHIP_REMOVE: 'relationshipRemove',
}; };
exports.ShardEvents = { exports.ShardEvents = {
@ -1310,6 +1312,26 @@ exports.PrivacyLevels = createEnum([null, 'PUBLIC', 'GUILD_ONLY']);
*/ */
exports.GuildScheduledEventPrivacyLevels = createEnum([null, null, 'GUILD_ONLY']); exports.GuildScheduledEventPrivacyLevels = createEnum([null, null, 'GUILD_ONLY']);
/**
* Relationship Enum
* * FRIEND
* * BLOCKED
* * INCOMING_REQUEST
* * OUTGOING_REQUEST
* @typedef {string} RelationshipType
* @see {@link https://luna.gitlab.io/discord-unofficial-docs/relationships.html}
*/
exports.RelationshipTypes = createEnum([null, 'FRIEND', 'BLOCKED', 'INCOMING_REQUEST', 'OUTGOING_REQUEST']);
exports.Relationship = {
0: 'NONE',
1: 'FRIEND',
2: 'BLOCKED',
3: 'INCOMING_REQUEST',
4: 'OUTGOING_REQUEST',
};
/** /**
* The premium tier (Server Boost level) of a guild: * The premium tier (Server Boost level) of a guild:
* * NONE * * NONE

7
typings/enums.d.ts vendored
View File

@ -22,6 +22,13 @@ export const enum stickerAnimationMode {
NEVER = 2, NEVER = 2,
} }
export const enum relationshipsType {
FRIEND = 1,
BLOCKED = 2,
INCOMING_REQUEST = 3,
OUTGOING_REQUEST = 4,
}
export const enum localeSetting { export const enum localeSetting {
DANISH = 'da', DANISH = 'da',
GERMAN = 'de', GERMAN = 'de',

38
typings/index.d.ts vendored
View File

@ -62,6 +62,10 @@ import {
ApplicationCommandPermissionTypes, ApplicationCommandPermissionTypes,
ApplicationCommandTypes, ApplicationCommandTypes,
ChannelTypes, ChannelTypes,
relationshipsType,
localeSetting,
stickerAnimationMode,
DMScanLevel,
DefaultMessageNotificationLevels, DefaultMessageNotificationLevels,
ExplicitContentFilterLevels, ExplicitContentFilterLevels,
InteractionResponseTypes, InteractionResponseTypes,
@ -548,8 +552,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public application: If<Ready, ClientApplication>; public application: If<Ready, ClientApplication>;
// Added // Added
public setting: ClientUserSettingManager; public setting: ClientUserSettingManager;
public friends: FriendsManager; public relationships: RelationshipsManager;
public blocked: BlockedManager;
public updateCookie(): Promise<void>; public updateCookie(): Promise<void>;
// End // End
public channels: ChannelManager; public channels: ChannelManager;
@ -651,7 +654,6 @@ export class ClientUser extends User {
public setPassword(oldPassword: string, newPassword: string): Promise<this>; public setPassword(oldPassword: string, newPassword: string): Promise<this>;
public disableAccount(password: string): Promise<this>; public disableAccount(password: string): Promise<this>;
public deleteAccount(password: string): Promise<this>; public deleteAccount(password: string): Promise<this>;
public findFriend(username: string, discriminator: string | number): Promise<this>;
// Selfbot // Selfbot
public readonly nitro: boolean; public readonly nitro: boolean;
/** /**
@ -2468,8 +2470,7 @@ export class User extends PartialTextBasedChannel(Base) {
public banner: string | null | undefined; public banner: string | null | undefined;
public bot: boolean; public bot: boolean;
public readonly createdAt: Date; public readonly createdAt: Date;
public readonly friend: Boolean; public readonly relationships: relationshipsType;
public readonly blocked: Boolean;
public readonly createdTimestamp: number; public readonly createdTimestamp: number;
public discriminator: string; public discriminator: string;
public readonly defaultAvatarURL: string; public readonly defaultAvatarURL: string;
@ -3369,24 +3370,17 @@ export class UserManager extends CachedManager<Snowflake, User, UserResolvable>
public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>; public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>;
} }
export class FriendsManager extends CachedManager<Snowflake, User, UserResolvable> { export class RelationshipsManager {
private constructor(client: Client, iterable?: Iterable<RawUserData>); private constructor(client: Client, users?: Array<RawRelationship>);
private dmChannel(userId: Snowflake): DMChannel | null; public cache: Collection<Snowflake, relationshipsType>;
public createDM(user: UserResolvable, options?: BaseFetchOptions): Promise<DMChannel>; public client: Client;
public deleteDM(user: UserResolvable): Promise<DMChannel>; private _setup(users: Array<RawRelationship>): null;
public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<User>; public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<User>;
public fetchFlags(user: UserResolvable, options?: BaseFetchOptions): Promise<UserFlags>; public deleteFriend(user: UserResolvable): Promise<User>;
public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>; public deleteBlocked(user: UserResolvable): Promise<User>;
} public sendFriendRequest(username: User.username, discriminator: User.discriminator): Promise<User>;
public addFriend(user: UserResolvable): Promise<User>;
export class BlockedManager extends CachedManager<Snowflake, User, UserResolvable> { public addBlocked(user: UserResolvable): Promise<User>;
private constructor(client: Client, iterable?: Iterable<RawUserData>);
private dmChannel(userId: Snowflake): DMChannel | null;
public createDM(user: UserResolvable, options?: BaseFetchOptions): Promise<DMChannel>;
public deleteDM(user: UserResolvable): Promise<DMChannel>;
public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<User>;
public fetchFlags(user: UserResolvable, options?: BaseFetchOptions): Promise<UserFlags>;
public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>;
} }
export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, typeof VoiceState> { export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, typeof VoiceState> {