fix: ClientUser.notes return empty Collection
fix: Recieve messages from large servers #72
feat: checkUpdate return Debug event (not console.log)
feat: RelationshipAdd event, param type return RelationshipTypes
feat: online status when login
feat: fix documents
This commit is contained in:
March 7th
2022-06-06 00:42:08 +07:00
parent 04251a8b87
commit c165824419
10 changed files with 78 additions and 51 deletions

View File

@@ -1,6 +1,24 @@
'use strict';
const { Events, Status } = require('../../../util/Constants');
const { Events, Opcodes, Status } = require('../../../util/Constants');
// Receive messages in large guilds
const run = (client, guild) => {
client.ws.broadcast({
op: Opcodes.LAZY_REQUEST,
d: {
guild_id: guild.id,
typing: true,
threads: false,
activities: true,
thread_member_lists: [],
members: [],
channels: {
// [guild.channels.cache.first().id]: [[0, 99]],
},
},
});
};
module.exports = (client, { d: data }, shard) => {
let guild = client.guilds.cache.get(data.id);
@@ -8,6 +26,7 @@ module.exports = (client, { d: data }, shard) => {
if (!guild.available && !data.unavailable) {
// A newly available guild
guild._patch(data);
run(client, guild);
}
} else {
// A new guild
@@ -20,6 +39,7 @@ module.exports = (client, { d: data }, shard) => {
* @param {Guild} guild The created guild
*/
client.emit(Events.GUILD_CREATE, guild);
run(client, guild);
}
}
};

View File

@@ -8,30 +8,31 @@ const Discord = require('../../../index');
const { Events, Opcodes } = require('../../../util/Constants');
const { Networking } = require('../../../util/Voice');
async function checkUpdate() {
async function checkUpdate(client) {
const res_ = await axios.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`);
const lastest_tag = res_.data['dist-tags'].latest;
// Checking if the package is outdated
// Stable version
if (lastest_tag !== Discord.version && Discord.version.includes('-') == false) {
return console.log(`${chalk.yellowBright('[WARNING]')} New Discord.js-selfbot-v13 version.
Old Version: ${chalk.redBright(Discord.version)} => New Version: ${chalk.greenBright(lastest_tag)}`);
return client.emit(
Events.DEBUG,
`${chalk.yellowBright('[WARNING]')} New Discord.js-selfbot-v13 version.
Old Version: ${chalk.redBright(Discord.version)} => New Version: ${chalk.greenBright(lastest_tag)}`,
);
}
/*
Removed:
console.log(
client.emit(
Events.DEBUG,
`${chalk.greenBright('[OK]')} Discord.js-selfbot-v13 is up to date. Version: ${chalk.blueBright(Discord.version)}`,
);
*/
return null;
}
module.exports = (client, { d: data }, shard) => {
if (client.options.checkUpdate) {
try {
checkUpdate();
checkUpdate(client);
} catch (e) {
console.log(`${chalk.redBright('[Fail]')} Check Update error:`, e.message);
client.emit(Events.DEBUG, `${chalk.redBright('[Fail]')} Check Update error: ${e.message}`);
}
}
@@ -82,9 +83,7 @@ module.exports = (client, { d: data }, shard) => {
client.user.connectedAccounts = data.connected_accounts ?? [];
for (const [userid, note] of Object.entries(data.notes ?? {})) {
client.user.notes.set(userid, note);
}
client.user._patchNote(data.notes);
for (const private_channel of data.private_channels) {
client.channels._add(private_channel);
@@ -118,7 +117,7 @@ module.exports = (client, { d: data }, shard) => {
client.guilds._add(guild);
}
// Receive messages in large guilds [Test]
// Receive messages in large guilds
client.guilds.cache.map(guild => {
client.ws.broadcast({
op: Opcodes.LAZY_REQUEST,

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const { Events, Relationship } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
if (data.user) {
@@ -11,7 +11,7 @@ module.exports = (client, { d: data }) => {
* Emitted whenever a relationship is updated.
* @event Client#relationshipAdd
* @param {UserId} user The userID that was updated
* @param {Number} type The new relationship type
* @param {RelationshipType} type The new relationship type
*/
client.emit(Events.RELATIONSHIP_ADD, data.id, data.type);
client.emit(Events.RELATIONSHIP_ADD, data.id, Relationship[data.type]);
};

View File

@@ -14,17 +14,6 @@ class ClientUser extends User {
_patch(data) {
super._patch(data);
/*
Add: notes
*/
/**
* The notes cache of the client user.
* @type {Collection<Snowflake, Message>}
* @private
*/
this.notes = new Collection();
// This.messageMentions = new Collection();
if ('verified' in data) {
/**
* Whether or not this account has been verified
@@ -67,11 +56,23 @@ class ClientUser extends User {
/**
* Email address of the client user.
* @type {?string}
* @deprecated
* @see https://discord.com/developers/docs/resources/user#user-object
*/
}
/**
* Patch note
* @param {Object} data Note data
* @private
*/
_patchNote(data) {
/**
* The notes cache of the client user.
* @type {Collection<Snowflake, string>}
* @private
*/
this.notes = data ? new Collection(Object.entries(data)) : new Collection();
}
/**
* Represents the client user's presence
* @type {ClientPresence}
@@ -163,10 +164,10 @@ class ClientUser extends User {
/**
* Set HyperSquad House
* @param {HypeSquadOptions<number|string>} type
* `LEAVE`: 0
* `HOUSE_BRAVERY`: 1
* `HOUSE_BRILLIANCE`: 2
* `HOUSE_BALANCE`: 3
* * `LEAVE`: 0
* * `HOUSE_BRAVERY`: 1
* * `HOUSE_BRILLIANCE`: 2
* * `HOUSE_BALANCE`: 3
* @returns {Promise<void>}
* @example
* // Set HyperSquad HOUSE_BRAVERY

View File

@@ -207,7 +207,8 @@ class User extends Base {
/**
* Get profile from Discord, if client is in a server with the target.
* @returns {Promise<User>} the user object
* @type {User}
* @returns {Promise<User>}
*/
async getProfile() {
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
@@ -217,8 +218,9 @@ class User extends Base {
}
/**
* Friends the user and send Request [If no request]
* @returns {Promise<User>} the user object
* Friends the user [If incoming request]
* @type {boolean}
* @returns {Promise<boolean>}
*/
setFriend() {
return this.client.relationships.addFriend(this);
@@ -226,14 +228,16 @@ class User extends Base {
/**
* Send Friend Request to the user
* @returns {Promise<User>} the user object
* @type {boolean}
* @returns {Promise<boolean>}
*/
sendFriendRequest() {
return this.client.relationships.sendFriendRequest(this.username, this.discriminator);
}
/**
* Blocks the user
* @returns {Promise<User>} the user object
* @type {boolean}
* @returns {Promise<boolean>}
*/
setBlock() {
return this.client.relationships.addBlocked(this);
@@ -241,7 +245,8 @@ class User extends Base {
/**
* Removes the user from your blocks list
* @returns {Promise<User>} the user object
* @type {boolean}
* @returns {Promise<boolean>}
*/
unBlock() {
return this.client.relationships.deleteBlocked(this);
@@ -249,7 +254,8 @@ class User extends Base {
/**
* Removes the user from your friends list
* @returns {Promise<User>} the user object
* @type {boolean}
* @returns {Promise<boolean>}
*/
unFriend() {
return this.client.relationships.deleteFriend(this);

View File

@@ -76,7 +76,7 @@ const JSONBig = require('json-bigint');
* @property {string[]} [userAgentSuffix] An array of additional bot info to be appended to the end of the required
* [User Agent](https://discord.com/developers/docs/reference#user-agent) header
* @property {PresenceData} [presence={}] Presence data to use upon login
* @property {IntentsResolvable} [intents] Intents to enable for this connection
* @property {IntentsResolvable} [intents=131071] Intents to enable for this connection (but not using)
* @property {number} [waitGuildTimeout=0] Time in milliseconds that Clients with the GUILDS intent should wait for
* missing guilds to be received before starting the bot. If not specified, the default is 15 seconds.
* @property {SweeperOptions} [sweepers={}] Options for cache sweeping
@@ -138,7 +138,7 @@ class Options extends null {
static createDefault() {
return {
jsonTransformer: object => JSONBig.stringify(object),
checkUpdate: false,
checkUpdate: true,
readyStatus: true,
autoCookie: true,
patchVoice: true,
@@ -148,7 +148,7 @@ class Options extends null {
messageCacheLifetime: 0,
messageSweepInterval: 0,
invalidRequestWarningInterval: 0,
intents: 65535,
intents: 131071,
partials: ['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT'], // Enable the partials
restWsBridgeTimeout: 5_000,
restRequestTimeout: 15_000,
@@ -158,7 +158,7 @@ class Options extends null {
restSweepInterval: 60,
failIfNotExists: false,
userAgentSuffix: [],
presence: { status: 'invisible', since: 0, activities: [], afk: false },
presence: { status: 'online', since: 0, activities: [], afk: false },
sweepers: {},
ws: {
large_threshold: 50,
@@ -214,7 +214,7 @@ class Options extends null {
os_version: '10.0.22000',
os_arch: 'x64',
system_locale: 'en-US',
client_build_number: 122087,
client_build_number: 127546,
client_event_source: null,
}),
'ascii',