1. Fix Interaction with ephemeral message
2. client.updateCookie()
3. clientUser.findFriend('test', 1234)
4. WebEmbed not working, sad
5. Update Document later ...
This commit is contained in:
March 7th 2022-04-10 19:03:40 +07:00
parent f361bed628
commit d900f7321c
7 changed files with 96 additions and 67 deletions

View File

@ -242,6 +242,49 @@ class Client extends BaseClient {
return this.readyAt ? Date.now() - this.readyAt : null; return this.readyAt ? Date.now() - this.readyAt : null;
} }
/**
* Update Cloudflare Cookie and Discord Fingerprint
*/
async updateCookie() {
/* Auto find fingerprint and add Cookie */
let cookie = '';
await require('axios')({
method: 'get',
url: 'https://discord.com/api/v9/experiments',
headers: this.options.http.headers,
})
.then((res) => {
if (!'set-cookie' in res.headers) return;
res.headers['set-cookie'].map((line) => {
line.split('; ').map((arr) => {
if (
arr.startsWith('Expires') ||
arr.startsWith('Path') ||
arr.startsWith('Domain') ||
arr.startsWith('HttpOnly') ||
arr.startsWith('Secure') ||
arr.startsWith('Max-Age') ||
arr.startsWith('SameSite')
) {
return;
} else {
cookie += `${arr}; `;
}
});
});
this.options.http.headers['Cookie'] = `${cookie}locale=en`;
this.options.http.headers['x-fingerprint'] = res.data.fingerprint;
this.emit(Events.DEBUG, `Added Cookie: ${cookie}`);
this.emit(Events.DEBUG, `Added Fingerprint: ${res.data.fingerprint}`);
})
.catch((err) => {
this.emit(
Events.DEBUG,
`Finding Cookie and Fingerprint failed: ${err.message}`,
);
});
}
/** /**
* Logs the client in, establishing a WebSocket connection to Discord. * Logs the client in, establishing a WebSocket connection to Discord.
* @param {string} [token=this.token] Token of the account to log in with * @param {string} [token=this.token] Token of the account to log in with
@ -261,43 +304,7 @@ class Client extends BaseClient {
); );
if (this.options.autoCookie) { if (this.options.autoCookie) {
/* Auto find fingerprint and add Cookie */ await this.updateCookie();
let cookie = '';
await require('axios')({
method: 'get',
url: 'https://discord.com/api/v9/experiments',
headers: this.options.http.headers,
})
.then((res) => {
if (!'set-cookie' in res.headers) return;
res.headers['set-cookie'].map((line) => {
line.split('; ').map((arr) => {
if (
arr.startsWith('Expires') ||
arr.startsWith('Path') ||
arr.startsWith('Domain') ||
arr.startsWith('HttpOnly') ||
arr.startsWith('Secure') ||
arr.startsWith('Max-Age') ||
arr.startsWith('SameSite')
) {
return;
} else {
cookie += `${arr}; `;
}
});
});
this.options.http.headers['Cookie'] = `${cookie}locale=en`;
this.options.http.headers['x-fingerprint'] = res.data.fingerprint;
this.emit(Events.DEBUG, `Added Cookie: ${cookie}`);
this.emit(Events.DEBUG, `Added Fingerprint: ${res.data.fingerprint}`);
})
.catch((err) => {
this.emit(
Events.DEBUG,
`Finding Cookie and Fingerprint failed: ${err.message}`,
);
});
} }
if (this.options.presence) { if (this.options.presence) {

View File

@ -1,17 +1,14 @@
'use strict'; 'use strict';
const CachedManager = require('./CachedManager');
const { default: Collection } = require('@discordjs/collection'); const { default: Collection } = require('@discordjs/collection');
const { Error, TypeError } = require('../errors/DJSError'); const { Error, TypeError } = require('../errors/DJSError');
const { remove } = require('lodash'); const { remove } = require('lodash');
const { localeObject, DMScanLevel, stickerAnimationMode } = require('../util/Constants') const { localeObject, DMScanLevel, stickerAnimationMode } = require('../util/Constants')
/** /**
* Manages API methods for users and stores their cache. * Manages API methods for users.
* @extends {CachedManager}
*/ */
class ClientUserSettingManager extends CachedManager { class ClientUserSettingManager {
constructor(client, iterable) { constructor(client, iterable) {
super(client); this.client = client;
// Raw data // Raw data
this.rawSetting = {}; this.rawSetting = {};
// Language // Language

View File

@ -156,9 +156,10 @@ class ClientUser extends User {
async setHypeSquad(type) { async setHypeSquad(type) {
const id = typeof type === 'string' ? HypeSquadOptions[type] : type; const id = typeof type === 'string' ? HypeSquadOptions[type] : type;
if (!id && id !== 0) throw new Error('Invalid HypeSquad type.'); if (!id && id !== 0) throw new Error('Invalid HypeSquad type.');
if (id !== 0) return await this.client.api.hypesquad.online.post({ if (id !== 0)
data: { house_id: id }, return await this.client.api.hypesquad.online.post({
}); data: { house_id: id },
});
else return await this.client.api.hypesquad.online.delete(); else return await this.client.api.hypesquad.online.delete();
} }
@ -178,7 +179,8 @@ class ClientUser extends User {
* @returns {Promise} * @returns {Promise}
*/ */
setDiscriminator(discriminator, password) { setDiscriminator(discriminator, password) {
if (!this.nitro) throw new Error('You must be a Nitro User to change your discriminator.'); if (!this.nitro)
throw new Error('You must be a Nitro User to change your discriminator.');
if (!password && !this.client.password) if (!password && !this.client.password)
throw new Error('A password is required to change a discriminator.'); throw new Error('A password is required to change a discriminator.');
return this.edit({ return this.edit({
@ -352,6 +354,22 @@ class ClientUser extends User {
setAFK(afk = true, shardId) { setAFK(afk = true, shardId) {
return this.setPresence({ afk, shardId }); return this.setPresence({ afk, shardId });
} }
/**
* Send Friend Request to the user
* @returns {Promise<User>} the user object
*/
async findFriend(username, discriminator) {
return await this.client.api
.users('@me')
.relationships.post({
data: {
username: username,
discriminator: parseInt(discriminator),
},
})
.then((_) => _);
}
} }
module.exports = ClientUser; module.exports = ClientUser;

View File

@ -183,6 +183,7 @@ class MessageButton extends BaseMessageComponent {
component_type: 2, // Button component_type: 2, // Button
custom_id: this.customId custom_id: this.customId
}, },
message_flags: message.flags.bitfield,
} }
} }
) )

View File

@ -231,24 +231,23 @@ class MessageSelectMenu extends BaseMessageComponent {
return false; return false;
}) })
if (check_) throw new RangeError("[SELECT_MENU_INVALID_VALUE] The value " + check_ + " is invalid. Please use a valid value " + validValue.join(', ')); if (check_) throw new RangeError("[SELECT_MENU_INVALID_VALUE] The value " + check_ + " is invalid. Please use a valid value " + validValue.join(', '));
await message.client.api.interactions.post( await message.client.api.interactions.post({
{ data: {
data: { type: 3, // ?
type: 3, // ? guild_id: message.guild?.id ?? null, // In DMs
guild_id: message.guild?.id ?? null, // In DMs channel_id: message.channel.id,
channel_id: message.channel.id, message_id: message.id,
message_id: message.id, application_id: message.author.id,
application_id: message.author.id, session_id: message.client.session_id,
session_id: message.client.session_id, data: {
data: { component_type: 3, // Select Menu
component_type: 3, // Select Menu custom_id: this.customId,
custom_id: this.customId, type: 3, // Select Menu
type: 3, // Select Menu values,
values, },
}, message_flags: message.flags.bitfield,
} },
} });
)
return true; return true;
} }
} }

View File

@ -1,13 +1,18 @@
'use strict'; 'use strict';
const axios = require('axios'); const axios = require('axios');
const baseURL = 'https://embed.benny.fun/?'; const baseURL = 'https://embed.benny.fun/?'; // error, not working .-. sad ...
const hiddenCharter = const hiddenCharter =
'||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
const { RangeError } = require('../errors'); const { RangeError } = require('../errors');
const Util = require('../util/Util'); const Util = require('../util/Util');
const process = require('node:process');
const warn = true;
class WebEmbed { class WebEmbed {
constructor(data = {}) { constructor(data = {}) {
if (warn) process.emitWarning(
'The WebEmbed constructor encountered a problem with the URL.',
);
this._setup(data); this._setup(data);
/** /**
* Shorten the link * Shorten the link

4
typings/index.d.ts vendored
View File

@ -550,6 +550,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public setting: ClientUserSettingManager; public setting: ClientUserSettingManager;
public friends: FriendsManager; public friends: FriendsManager;
public blocked: BlockedManager; public blocked: BlockedManager;
public updateCookie(): Promise<void>;
// End // End
public channels: ChannelManager; public channels: ChannelManager;
public readonly emojis: BaseGuildEmojiManager; public readonly emojis: BaseGuildEmojiManager;
@ -650,6 +651,7 @@ 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;
/** /**
@ -3064,7 +3066,7 @@ export class ChannelManager extends CachedManager<Snowflake, AnyChannel, Channel
public createGroupDM(recipients: Array<User>): Promise<PartialGroupDMChannel>; public createGroupDM(recipients: Array<User>): Promise<PartialGroupDMChannel>;
} }
export class ClientUserSettingManager extends CachedManager<Snowflake, null> { export class ClientUserSettingManager {
private constructor(client: Client, iterable?: Iterable<RawUserSettingsData>); private constructor(client: Client, iterable?: Iterable<RawUserSettingsData>);
public fetch(): Promise<ClientUserSetting>; public fetch(): Promise<ClientUserSetting>;
public setDisplayCompactMode(value?: boolean): Promise<ClientUserSetting>; public setDisplayCompactMode(value?: boolean): Promise<ClientUserSetting>;