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

@ -243,24 +243,9 @@ class Client extends BaseClient {
} }
/** /**
* Logs the client in, establishing a WebSocket connection to Discord. * Update Cloudflare Cookie and Discord Fingerprint
* @param {string} [token=this.token] Token of the account to log in with
* @returns {Promise<string>} Token of the account used
* @example
* client.login('my token');
*/ */
async login(token = this.token) { async updateCookie() {
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
this.emit(
Events.DEBUG,
`Provided token: ${token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
.join('.')}`,
);
if (this.options.autoCookie) {
/* Auto find fingerprint and add Cookie */ /* Auto find fingerprint and add Cookie */
let cookie = ''; let cookie = '';
await require('axios')({ await require('axios')({
@ -300,6 +285,28 @@ class Client extends BaseClient {
}); });
} }
/**
* Logs the client in, establishing a WebSocket connection to Discord.
* @param {string} [token=this.token] Token of the account to log in with
* @returns {Promise<string>} Token of the account used
* @example
* client.login('my token');
*/
async login(token = this.token) {
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
this.emit(
Events.DEBUG,
`Provided token: ${token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
.join('.')}`,
);
if (this.options.autoCookie) {
await this.updateCookie();
}
if (this.options.presence) { if (this.options.presence) {
this.options.ws.presence = this.presence._parse(this.options.presence); this.options.ws.presence = this.presence._parse(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,7 +156,8 @@ 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)
return await this.client.api.hypesquad.online.post({
data: { house_id: id }, 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,8 +231,7 @@ 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
@ -246,9 +245,9 @@ class MessageSelectMenu extends BaseMessageComponent {
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>;