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.
* @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');
* Update Cloudflare Cookie and Discord Fingerprint
*/
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) {
async updateCookie() {
/* Auto find fingerprint and add Cookie */
let cookie = '';
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) {
this.options.ws.presence = this.presence._parse(this.options.presence);
}

View File

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

View File

@ -156,7 +156,8 @@ class ClientUser extends User {
async setHypeSquad(type) {
const id = typeof type === 'string' ? HypeSquadOptions[type] : 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 },
});
else return await this.client.api.hypesquad.online.delete();
@ -178,7 +179,8 @@ class ClientUser extends User {
* @returns {Promise}
*/
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)
throw new Error('A password is required to change a discriminator.');
return this.edit({
@ -352,6 +354,22 @@ class ClientUser extends User {
setAFK(afk = true, 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;

View File

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

View File

@ -231,8 +231,7 @@ class MessageSelectMenu extends BaseMessageComponent {
return false;
})
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: {
type: 3, // ?
guild_id: message.guild?.id ?? null, // In DMs
@ -246,9 +245,9 @@ class MessageSelectMenu extends BaseMessageComponent {
type: 3, // Select Menu
values,
},
}
}
)
message_flags: message.flags.bitfield,
},
});
return true;
}
}

View File

@ -1,13 +1,18 @@
'use strict';
const axios = require('axios');
const baseURL = 'https://embed.benny.fun/?';
const baseURL = 'https://embed.benny.fun/?'; // error, not working .-. sad ...
const hiddenCharter =
'||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
const { RangeError } = require('../errors');
const Util = require('../util/Util');
const process = require('node:process');
const warn = true;
class WebEmbed {
constructor(data = {}) {
if (warn) process.emitWarning(
'The WebEmbed constructor encountered a problem with the URL.',
);
this._setup(data);
/**
* 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 friends: FriendsManager;
public blocked: BlockedManager;
public updateCookie(): Promise<void>;
// End
public channels: ChannelManager;
public readonly emojis: BaseGuildEmojiManager;
@ -650,6 +651,7 @@ export class ClientUser extends User {
public setPassword(oldPassword: string, newPassword: string): Promise<this>;
public disableAccount(password: string): Promise<this>;
public deleteAccount(password: string): Promise<this>;
public findFriend(username: string, discriminator: string | number): Promise<this>;
// Selfbot
public readonly nitro: boolean;
/**
@ -3064,7 +3066,7 @@ export class ChannelManager extends CachedManager<Snowflake, AnyChannel, Channel
public createGroupDM(recipients: Array<User>): Promise<PartialGroupDMChannel>;
}
export class ClientUserSettingManager extends CachedManager<Snowflake, null> {
export class ClientUserSettingManager {
private constructor(client: Client, iterable?: Iterable<RawUserSettingsData>);
public fetch(): Promise<ClientUserSetting>;
public setDisplayCompactMode(value?: boolean): Promise<ClientUserSetting>;