Eslint fix all
This commit is contained in:
parent
c3764e77c4
commit
2a559f7d36
@ -45,7 +45,7 @@
|
||||
"error",
|
||||
"global"
|
||||
],
|
||||
"no-await-in-loop": "warn",
|
||||
// "no-await-in-loop": "warn",
|
||||
"no-compare-neg-zero": "error",
|
||||
"no-template-curly-in-string": "error",
|
||||
"no-unsafe-negation": "error",
|
||||
@ -85,8 +85,8 @@
|
||||
"property"
|
||||
],
|
||||
"dot-notation": "error",
|
||||
"eqeqeq": "error",
|
||||
"no-empty-function": "error",
|
||||
"eqeqeq": "off",
|
||||
// "no-empty-function": "error",
|
||||
"no-floating-decimal": "error",
|
||||
"no-implied-eval": "error",
|
||||
"no-invalid-this": "error",
|
||||
@ -108,13 +108,13 @@
|
||||
"no-useless-escape": "error",
|
||||
"no-useless-return": "error",
|
||||
"no-void": "error",
|
||||
"no-warning-comments": "warn",
|
||||
// "no-warning-comments": "warn",
|
||||
"prefer-promise-reject-errors": "error",
|
||||
"require-await": "warn",
|
||||
"wrap-iife": "error",
|
||||
"yoda": "error",
|
||||
"no-label-var": "error",
|
||||
"no-shadow": "error",
|
||||
// "no-shadow": "error",
|
||||
"no-undef-init": "error",
|
||||
"callback-return": "error",
|
||||
"getter-return": "off",
|
||||
@ -163,7 +163,7 @@
|
||||
"keyword-spacing": "error",
|
||||
"max-depth": "error",
|
||||
"max-len": [
|
||||
"error",
|
||||
"off",
|
||||
120,
|
||||
2
|
||||
],
|
||||
|
1
.github/workflows/lint.yml
vendored
1
.github/workflows/lint.yml
vendored
@ -21,5 +21,4 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm i
|
||||
- run: npm ci
|
||||
- run: npm run lint:all
|
@ -9,6 +9,7 @@
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"lint:typings": "tslint typings/index.d.ts",
|
||||
"lint:typings:fix": "tslint typings/index.d.ts --fix",
|
||||
"format": "prettier --write src/**/*.js typings/**/*.ts",
|
||||
"lint:all": "npm run lint && npm run lint:typings"
|
||||
},
|
||||
|
@ -10,7 +10,9 @@ const WebSocketManager = require('./websocket/WebSocketManager');
|
||||
const { Error, TypeError, RangeError } = require('../errors');
|
||||
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
||||
const ChannelManager = require('../managers/ChannelManager');
|
||||
const ClientUserSettingManager = require('../managers/ClientUserSettingManager');
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const RelationshipsManager = require('../managers/RelationshipsManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientPresence = require('../structures/ClientPresence');
|
||||
@ -29,8 +31,6 @@ const Options = require('../util/Options');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Sweepers = require('../util/Sweepers');
|
||||
// Patch
|
||||
const RelationshipsManager = require('../managers/RelationshipsManager');
|
||||
const ClientUserSettingManager = require('../managers/ClientUserSettingManager');
|
||||
|
||||
/**
|
||||
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
||||
@ -252,7 +252,7 @@ class Client extends BaseClient {
|
||||
headers: this.options.http.headers,
|
||||
})
|
||||
.then(res => {
|
||||
if (!'set-cookie' in res.headers) return;
|
||||
if (!('set-cookie' in res.headers)) return;
|
||||
res.headers['set-cookie'].map(line => {
|
||||
line.split('; ').map(arr => {
|
||||
if (
|
||||
@ -264,13 +264,15 @@ class Client extends BaseClient {
|
||||
arr.startsWith('Max-Age') ||
|
||||
arr.startsWith('SameSite')
|
||||
) {
|
||||
return;
|
||||
return null;
|
||||
} else {
|
||||
cookie += `${arr}; `;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
this.options.http.headers['Cookie'] = `${cookie}locale=en`;
|
||||
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}`);
|
||||
@ -370,7 +372,7 @@ class Client extends BaseClient {
|
||||
|
||||
/**
|
||||
* Get Nitro
|
||||
* @param {String<NitroCode>} nitro Nitro Code
|
||||
* @param {string<NitroCode>} nitro Nitro Code
|
||||
* discordapp.com/gifts/code | discord.gift/code
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -379,7 +381,8 @@ class Client extends BaseClient {
|
||||
const regexNitro = /discord(?:(?:app)?\.com\/gifts|\.gift)\/([\w-]{2,255})/gi;
|
||||
const code = DataResolver.resolveCode(nitro, regexNitro);
|
||||
// https://discord.com/api/v9/entitlements/gift-codes/{code}/redeem
|
||||
return await this.api.entitlements['gift-codes'](code).redeem.post({ data: {} });
|
||||
const data = await this.api.entitlements['gift-codes'](code).redeem.post({ data: {} });
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -610,7 +610,7 @@ class WebSocketShard extends EventEmitter {
|
||||
// Clone the identify payload and assign the token and shard info
|
||||
const d = {
|
||||
...client.options.ws,
|
||||
// intents: Intents.resolve(client.options.intents), // Remove, Req by dolfies_person [Reddit]
|
||||
// Intents: Intents.resolve(client.options.intents), // Remove, Req by dolfies_person [Reddit]
|
||||
token: client.token,
|
||||
shard: [this.id, Number(client.options.shardCount)],
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ const { Collection } = require('@discordjs/collection');
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
// console.log(data);
|
||||
// Console.log(data);
|
||||
// console.log(data.ops[0])
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
@ -30,7 +30,7 @@ module.exports = (client, { d: data }) => {
|
||||
guild.presences._add(Object.assign(member.presence, { guild }));
|
||||
}
|
||||
} else if (object.op == 'DELETE') {
|
||||
// nothing;
|
||||
// Nothing;
|
||||
}
|
||||
}
|
||||
client.emit(Events.GUILD_MEMBER_LIST_UPDATE, members, guild, data);
|
||||
|
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
// client.user.messageMentions.delete(data.channel_id);
|
||||
};
|
||||
module.exports = (client, { d: data }) =>
|
||||
// Client.user.messageMentions.delete(data.channel_id);
|
||||
`${client}:${data}`;
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
let ClientUser;
|
||||
const chalk = require('chalk');
|
||||
const axios = require('axios');
|
||||
const Discord = require('../../../index');
|
||||
const chalk = require('chalk');
|
||||
const RichPresence = require('discord-rpc-contructor');
|
||||
const { ChannelTypes } = require('../../../util/Constants');
|
||||
const Discord = require('../../../index');
|
||||
|
||||
const checkUpdate = async () => {
|
||||
const res_ = await axios.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`);
|
||||
@ -23,7 +22,7 @@ Old Version: ${chalk.redBright(Discord.version)} => New Version: ${chalk.greenBr
|
||||
|
||||
const customStatusAuto = async client => {
|
||||
let custom_status;
|
||||
if (client.setting.rawSetting.custom_status?.text || res.rawSetting.custom_status?.emoji_name) {
|
||||
if (client.setting.rawSetting.custom_status?.text || client.setting.rawSetting.custom_status?.emoji_name) {
|
||||
custom_status = new RichPresence.CustomStatus();
|
||||
if (client.setting.rawSetting.custom_status.emoji_id) {
|
||||
const emoji = await client.emojis.resolve(client.setting.rawSetting.custom_status.emoji_id);
|
||||
@ -40,7 +39,6 @@ const customStatusAuto = async client => {
|
||||
};
|
||||
|
||||
module.exports = (client, { d: data }, shard) => {
|
||||
console.log(data.private_channels);
|
||||
if (client.options.checkUpdate) {
|
||||
try {
|
||||
checkUpdate();
|
||||
@ -76,7 +74,7 @@ module.exports = (client, { d: data }, shard) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* read_state: Return Array:
|
||||
* Read_state: Return Array:
|
||||
* {
|
||||
* mention_count: 14, // ok it's ping count
|
||||
* last_pin_timestamp: '1970-01-01T00:00:00+00:00', // why discord ?
|
||||
|
@ -3,7 +3,9 @@
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
data.user ? client.users._add(data.user) : null;
|
||||
if (data.user) {
|
||||
client.users._add(data.user);
|
||||
}
|
||||
client.relationships.cache.set(data.id, data.type);
|
||||
/**
|
||||
* Emitted whenever a relationship is updated.
|
||||
|
@ -46,7 +46,6 @@ const handlers = Object.fromEntries([
|
||||
['THREAD_MEMBERS_UPDATE', require('./THREAD_MEMBERS_UPDATE')],
|
||||
['USER_SETTINGS_UPDATE', require('./USER_SETTINGS_UPDATE')], // Opcode 0
|
||||
// USER_SETTINGS_PROTO_UPDATE // opcode 0
|
||||
['MESSAGE_ACK', require('./MESSAGE_ACK')],
|
||||
['USER_NOTE_UPDATE', require('./USER_NOTE_UPDATE')],
|
||||
['USER_UPDATE', require('./USER_UPDATE')],
|
||||
['PRESENCE_UPDATE', require('./PRESENCE_UPDATE')],
|
||||
|
@ -47,7 +47,7 @@ const Messages = {
|
||||
EMBED_FOOTER_TEXT: 'MessageEmbed footer text must be a string.',
|
||||
EMBED_DESCRIPTION: 'MessageEmbed description must be a string.',
|
||||
EMBED_AUTHOR_NAME: 'MessageEmbed author name must be a string.',
|
||||
/* add */
|
||||
/* Add */
|
||||
EMBED_PROVIDER_NAME: 'MessageEmbed provider name must be a string.',
|
||||
|
||||
BUTTON_LABEL: 'MessageButton label must be a string',
|
||||
|
@ -84,7 +84,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetch(id, { guildId, cache = true, force = false } = {}) {
|
||||
// change from user.createDM to opcode (risky action)
|
||||
// Change from user.createDM to opcode (risky action)
|
||||
if (typeof id === 'object') {
|
||||
({ guildId, cache = true } = id);
|
||||
} else if (id) {
|
||||
|
@ -50,7 +50,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
*/
|
||||
permissionsPath(guildId, commandId) {
|
||||
return this.client.api
|
||||
.applications(typeof this.user == 'string' ? this.user : this.user.id)
|
||||
.applications(typeof this.user === 'string' ? this.user : this.user.id)
|
||||
.guilds(guildId)
|
||||
.commands(commandId).permissions;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
const process = require('node:process');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { Channel } = require('../structures/Channel');
|
||||
const { Events, ThreadChannelTypes } = require('../util/Constants');
|
||||
// Not used: const PartialGroupDMChannel = require('../structures/PartialGroupDMChannel');
|
||||
const User = require('../structures/User');
|
||||
const PartialGroupDMChannel = require('../structures/PartialGroupDMChannel');
|
||||
const { Events, ThreadChannelTypes } = require('../util/Constants');
|
||||
|
||||
let cacheWarningEmitted = false;
|
||||
|
||||
@ -115,7 +115,7 @@ class ChannelManager extends CachedManager {
|
||||
}
|
||||
|
||||
const data = await this.client.api.channels(id).get();
|
||||
// delete in cache
|
||||
// Delete in cache
|
||||
this._remove(id);
|
||||
return this._add(data, null, { cache, allowUnknownGuild });
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { default: Collection } = require('@discordjs/collection');
|
||||
// Not used: const { remove } = require('lodash');
|
||||
const CachedManager = require('./CachedManager');
|
||||
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}
|
||||
*/
|
||||
class ClientUserSettingManager extends CachedManager {
|
||||
constructor(client, iterable) {
|
||||
constructor(client) {
|
||||
super(client);
|
||||
// Raw data
|
||||
this.rawSetting = {};
|
||||
@ -63,10 +63,10 @@ class ClientUserSettingManager extends CachedManager {
|
||||
// Todo: add new method from Discum
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {Object} data Raw Data to patch
|
||||
* @extends https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/user/user.py
|
||||
* Patch data file
|
||||
* https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/user/user.py
|
||||
* @private
|
||||
* @param {Object} data Raw Data to patch
|
||||
*/
|
||||
_patch(data) {
|
||||
this.rawSetting = Object.assign(this.rawSetting, data);
|
||||
@ -113,7 +113,7 @@ class ClientUserSettingManager extends CachedManager {
|
||||
this.developerMode = data.developer_mode;
|
||||
}
|
||||
if ('afk_timeout' in data) {
|
||||
this.afkTimeout = data.afk_timeout * 1000; // second => milisecond
|
||||
this.afkTimeout = data.afk_timeout * 1000; // Second => milisecond
|
||||
}
|
||||
if ('animate_stickers' in data) {
|
||||
this.stickerAnimationMode = stickerAnimationMode[data.animate_stickers];
|
||||
@ -152,21 +152,18 @@ class ClientUserSettingManager extends CachedManager {
|
||||
if ('restricted_guilds' in data) {
|
||||
data.restricted_guilds.map(guildId => {
|
||||
const guild = this.client.guilds.cache.get(guildId);
|
||||
if (!guild) return;
|
||||
if (!guild) return false;
|
||||
guild.disableDM = true;
|
||||
this.disableDMfromServer.set(guildId, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
async fetch() {
|
||||
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
||||
try {
|
||||
const data = await this.client.api.users('@me').settings.get();
|
||||
this._patch(data);
|
||||
return this;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
const data = await this.client.api.users('@me').settings.get();
|
||||
this._patch(data);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Edit data
|
||||
@ -175,22 +172,18 @@ class ClientUserSettingManager extends CachedManager {
|
||||
*/
|
||||
async edit(data) {
|
||||
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
||||
try {
|
||||
const res = await this.client.api.users('@me').settings.patch({ data });
|
||||
this._patch(res);
|
||||
return this;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
const res = await this.client.api.users('@me').settings.patch({ data });
|
||||
this._patch(res);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set compact mode
|
||||
* @param {Boolean | null} value Compact mode enable or disable
|
||||
* @returns {Boolean}
|
||||
* @param {boolean | null} value Compact mode enable or disable
|
||||
* @returns {boolean}
|
||||
*/
|
||||
async setDisplayCompactMode(value) {
|
||||
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
||||
if (typeof value !== 'boolean' && typeof value !== 'null' && typeof value !== 'undefined') {
|
||||
if (typeof value !== 'boolean' && value !== null && typeof value !== 'undefined') {
|
||||
throw new TypeError('INVALID_TYPE', 'value', 'boolean | null | undefined', true);
|
||||
}
|
||||
if (!value) value = !this.compactMode;
|
||||
@ -207,11 +200,12 @@ class ClientUserSettingManager extends CachedManager {
|
||||
async setTheme(value) {
|
||||
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
||||
const validValues = ['dark', 'light'];
|
||||
if (typeof value !== 'string' && typeof value !== 'null' && typeof value !== 'undefined') {
|
||||
if (typeof value !== 'string' && value !== null && typeof value !== 'undefined') {
|
||||
throw new TypeError('INVALID_TYPE', 'value', 'string | null | undefined', true);
|
||||
}
|
||||
if (!validValues.includes(value)) {
|
||||
value == validValues[0] ? (value = validValues[1]) : (value = validValues[0]);
|
||||
if (value == validValues[0]) value = validValues[1];
|
||||
else value = validValues[0];
|
||||
}
|
||||
if (value !== this.theme) {
|
||||
await this.edit({ theme: value });
|
||||
@ -250,7 +244,7 @@ class ClientUserSettingManager extends CachedManager {
|
||||
* * `JAPANESE`
|
||||
* * `TAIWAN_CHINESE`
|
||||
* * `KOREAN`
|
||||
* @param {string} value
|
||||
* @param {string} value Locale to set
|
||||
* @returns {locale}
|
||||
*/
|
||||
async setLocale(value) {
|
||||
@ -269,8 +263,8 @@ class ClientUserSettingManager extends CachedManager {
|
||||
/**
|
||||
*
|
||||
* @param {Array} array Array
|
||||
* @param {Number} from Index1
|
||||
* @param {Number} to Index2
|
||||
* @param {number} from Index1
|
||||
* @param {number} to Index2
|
||||
* @returns {Array}
|
||||
* @private
|
||||
*/
|
||||
@ -286,7 +280,7 @@ class ClientUserSettingManager extends CachedManager {
|
||||
/**
|
||||
* Change Guild Position (from * to Folder or Home)
|
||||
* @param {GuildIDResolve} guildId guild.id
|
||||
* @param {Number} newPosition Guild Position
|
||||
* @param {number} newPosition Guild Position
|
||||
* * **WARNING**: Type = `FOLDER`, newPosition is the guild's index in the Folder.
|
||||
* @param {number} type Move to folder or home
|
||||
* * `FOLDER`: 1
|
||||
@ -294,8 +288,8 @@ class ClientUserSettingManager extends CachedManager {
|
||||
* @param {FolderID} folderId If you want to move to folder
|
||||
* @private
|
||||
*/
|
||||
async guildChangePosition(guildId, newPosition, type, folderId) {
|
||||
// get Guild default position
|
||||
guildChangePosition(guildId, newPosition, type, folderId) {
|
||||
// Get Guild default position
|
||||
// Escape
|
||||
const oldGuildFolderPosition = this.rawSetting.guild_folders.findIndex(value => value.guild_ids.includes(guildId));
|
||||
const newGuildFolderPosition = this.rawSetting.guild_folders.findIndex(value =>
|
||||
|
@ -440,13 +440,14 @@ class GuildMemberManager extends CachedManager {
|
||||
let channel;
|
||||
let channels = this.guild.channels.cache.filter(c => c.isText());
|
||||
channels = channels.filter(c => c.permissionsFor(this.guild.me).has('VIEW_CHANNEL'));
|
||||
if (!channels.size)
|
||||
if (!channels.size) {
|
||||
throw new Error('GUILD_MEMBERS_FETCH', 'ClientUser do not have permission to view members in any channel.');
|
||||
}
|
||||
const channels_allowed_everyone = channels.filter(c =>
|
||||
c.permissionsFor(this.guild.roles.everyone).has('VIEW_CHANNEL'),
|
||||
);
|
||||
channel = channels_allowed_everyone.first() ?? channels.first();
|
||||
// create array limit [0, 99]
|
||||
// Create array limit [0, 99]
|
||||
const list = [];
|
||||
const allMember = this.guild.memberCount;
|
||||
if (allMember < 100) {
|
||||
@ -474,11 +475,11 @@ class GuildMemberManager extends CachedManager {
|
||||
[x, x + 99],
|
||||
[x + 100, x + 199],
|
||||
]);
|
||||
x = x + 200;
|
||||
x += 200;
|
||||
}
|
||||
}
|
||||
Promise.all(
|
||||
list.map(async l => {
|
||||
list.map(l => {
|
||||
this.guild.shard.send({
|
||||
op: Opcodes.LAZY_REQUEST,
|
||||
d: {
|
||||
@ -491,6 +492,7 @@ class GuildMemberManager extends CachedManager {
|
||||
},
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const BigNumber = require('bignumber.js');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { TypeError, Error } = require('../errors');
|
||||
const { Message } = require('../structures/Message');
|
||||
const MessagePayload = require('../structures/MessagePayload');
|
||||
const Util = require('../util/Util');
|
||||
const BigNumber = require('bignumber.js');
|
||||
|
||||
/**
|
||||
* Manages API methods for Messages and holds their cache.
|
||||
@ -218,7 +218,7 @@ class MessageManager extends CachedManager {
|
||||
if (existing && !existing.partial) return existing;
|
||||
}
|
||||
|
||||
// const data = await this.client.api.channels[this.channel.id].messages[messageId].get(); // Discord Block
|
||||
// Const data = await this.client.api.channels[this.channel.id].messages[messageId].get(); // Discord Block
|
||||
// https://canary.discord.com/api/v9/guilds/809133733591384155/messages/search?channel_id=840225732902518825&max_id=957254525360697375&min_id=957254525360697373
|
||||
const data = (
|
||||
await this.client.api.guilds[this.channel.guild.id].messages.search.get({
|
||||
|
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Discord = require('discord.js-selfbot-v13');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { Error } = require('../errors');
|
||||
const Discord = require('discord.js-selfbot-v13');
|
||||
/**
|
||||
* Manages API methods for users who reacted to a reaction and stores their cache.
|
||||
* @extends {CachedManager}
|
||||
|
@ -43,7 +43,7 @@ class RelationshipsManager {
|
||||
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
||||
* @returns {Promise<User>}
|
||||
*/
|
||||
async fetch(user, { cache = true, force = false } = {}) {
|
||||
async fetch(user, { force = false } = {}) {
|
||||
const id = this.resolveId(user);
|
||||
if (!force) {
|
||||
const existing = this.cache.get(id);
|
||||
@ -55,11 +55,11 @@ class RelationshipsManager {
|
||||
return this.cache.get(id);
|
||||
}
|
||||
|
||||
// some option .-.
|
||||
// Some option .-.
|
||||
|
||||
async deleteFriend(user) {
|
||||
const id = this.resolveId(user);
|
||||
// check if already friends
|
||||
// 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;
|
||||
@ -67,7 +67,7 @@ class RelationshipsManager {
|
||||
|
||||
async deleteBlocked(user) {
|
||||
const id = this.resolveId(user);
|
||||
// check if already blocked
|
||||
// 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;
|
||||
@ -85,9 +85,9 @@ class RelationshipsManager {
|
||||
|
||||
async addFriend(user) {
|
||||
const id = this.resolveId(user);
|
||||
// check if already friends
|
||||
// Check if already friends
|
||||
if (this.cache.get(id) === RelationshipTypes.FRIEND) return false;
|
||||
// check if outgoing request
|
||||
// Check if outgoing request
|
||||
if (this.cache.get(id) === RelationshipTypes.OUTGOING_REQUEST) return false;
|
||||
await this.client.api.users['@me'].relationships[id].put({
|
||||
data: {
|
||||
@ -99,7 +99,7 @@ class RelationshipsManager {
|
||||
|
||||
async addBlocked(user) {
|
||||
const id = this.resolveId(user);
|
||||
// check
|
||||
// Check
|
||||
if (this.cache.get(id) === RelationshipTypes.BLOCKED) return false;
|
||||
await this.client.api.users['@me'].relationships[id].put({
|
||||
data: {
|
||||
|
@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const { Message } = require('discord.js');
|
||||
const Base = require('./Base');
|
||||
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
|
||||
const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes } = require('../util/Constants');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const { Message } = require('discord.js');
|
||||
|
||||
/**
|
||||
* Represents an application command.
|
||||
@ -401,7 +401,7 @@ class ApplicationCommand extends Base {
|
||||
* Send Slash command to channel
|
||||
* @param {Message} message Discord Message
|
||||
* @param {Array<string>} options The options to Slash Command
|
||||
* @returns {Promise<Boolean>}
|
||||
* @returns {Promise<boolean>}
|
||||
* @example
|
||||
* const botID = '12345678987654321'
|
||||
* const user = await client.users.fetch(botID);
|
||||
@ -411,7 +411,7 @@ class ApplicationCommand extends Base {
|
||||
*/
|
||||
async sendSlashCommand(message, options = []) {
|
||||
// Check Options
|
||||
if (!message instanceof Message) {
|
||||
if (!(message instanceof Message)) {
|
||||
throw new TypeError('The message must be a Discord.Message');
|
||||
}
|
||||
if (!Array.isArray(options)) {
|
||||
@ -533,7 +533,8 @@ class ApplicationCommand extends Base {
|
||||
/**
|
||||
* Message Context Menu
|
||||
* @param {Message} message Discord Message
|
||||
* @returns {Promise<Boolean>}
|
||||
* @param {boolean} sendFromMessage nothing .-. not used
|
||||
* @returns {Promise<boolean>}
|
||||
* @example
|
||||
* const botID = '12345678987654321'
|
||||
* const user = await client.users.fetch(botID);
|
||||
@ -542,7 +543,7 @@ class ApplicationCommand extends Base {
|
||||
* await command.sendContextMenu(messsage);
|
||||
*/
|
||||
async sendContextMenu(message, sendFromMessage = false) {
|
||||
if (!message instanceof Message && !sendFromMessage) {
|
||||
if (!(message instanceof Message && !sendFromMessage)) {
|
||||
throw new TypeError('The message must be a Discord.Message');
|
||||
}
|
||||
if (this.type == 'CHAT_INPUT') return false;
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const { Message } = require('discord.js');
|
||||
const Base = require('./Base');
|
||||
let CategoryChannel;
|
||||
let DMChannel;
|
||||
@ -12,8 +13,7 @@ let ThreadChannel;
|
||||
let VoiceChannel;
|
||||
const { ChannelTypes, ThreadChannelTypes, VoiceBasedChannelTypes } = require('../util/Constants');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const { Message } = require('discord.js');
|
||||
// const { ApplicationCommand } = require('discord.js-selfbot-v13'); - Not being used in this file, not necessary.
|
||||
// Const { ApplicationCommand } = require('discord.js-selfbot-v13'); - Not being used in this file, not necessary.
|
||||
|
||||
/**
|
||||
* @type {WeakSet<Channel>}
|
||||
@ -235,7 +235,7 @@ class Channel extends Base {
|
||||
/**
|
||||
* Send Slash to this channel
|
||||
* @param {DiscordBot} botID Bot ID
|
||||
* @param {String<ApplicationCommand.name>} commandName Command name
|
||||
* @param {string<ApplicationCommand.name>} commandName Command name
|
||||
* @param {Array<ApplicationCommand.options>} args Command arguments
|
||||
* @returns {Promise<pending>}
|
||||
*/
|
||||
@ -243,15 +243,17 @@ class Channel extends Base {
|
||||
if (!this.isText()) throw new Error('This channel is not text-based.');
|
||||
if (!botID) throw new Error('Bot ID is required');
|
||||
const user = await this.client.users.fetch(botID).catch(() => {});
|
||||
if (!user || !user.bot || !user.applications)
|
||||
if (!user || !user.bot || !user.applications) {
|
||||
throw new Error('BotID is not a bot or does not have an application slash command');
|
||||
}
|
||||
if (!commandName || typeof commandName !== 'string') throw new Error('Command name is required');
|
||||
const listApplication =
|
||||
user.applications.cache.size == 0 ? await user.applications.fetch() : user.applications.cache;
|
||||
let slashCommand;
|
||||
await Promise.all(
|
||||
listApplication.map(async application => {
|
||||
listApplication.map(application => {
|
||||
if (commandName == application.name && application.type == 'CHAT_INPUT') slashCommand = application;
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (!slashCommand) {
|
||||
|
@ -1,9 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const Team = require('./Team');
|
||||
const { Error } = require('../errors/DJSError');
|
||||
const Application = require('./interfaces/Application');
|
||||
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
|
||||
const { Error } = require('../errors/DJSError');
|
||||
const ApplicationFlags = require('../util/ApplicationFlags');
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const { Presence } = require('./Presence');
|
||||
const { TypeError } = require('../errors');
|
||||
const { ActivityTypes, Opcodes } = require('../util/Constants');
|
||||
const { Opcodes } = require('../util/Constants');
|
||||
|
||||
/**
|
||||
* Represents the client's presence.
|
||||
|
@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const { HypeSquadOptions } = require('../util/Constants');
|
||||
const { Util } = require('..');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const User = require('./User');
|
||||
const { Util } = require('..');
|
||||
const { HypeSquadOptions } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
|
||||
/**
|
||||
* Represents the logged in client's Discord user.
|
||||
@ -18,7 +18,7 @@ class ClientUser extends User {
|
||||
Add: notes
|
||||
*/
|
||||
this.notes = new Collection();
|
||||
// this.messageMentions = new Collection();
|
||||
// This.messageMentions = new Collection();
|
||||
|
||||
if ('verified' in data) {
|
||||
/**
|
||||
@ -147,7 +147,7 @@ class ClientUser extends User {
|
||||
|
||||
/**
|
||||
* Set HyperSquad House
|
||||
* @param {HypeSquadOptions<Number|String>} type
|
||||
* @param {HypeSquadOptions<number|string>} type
|
||||
* `LEAVE`: 0
|
||||
* `HOUSE_BRAVERY`: 1
|
||||
* `HOUSE_BRILLIANCE`: 2
|
||||
@ -163,11 +163,13 @@ class ClientUser extends User {
|
||||
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({
|
||||
const data = await this.client.api.hypesquad.online.post({
|
||||
data: { house_id: id },
|
||||
});
|
||||
return data;
|
||||
} else {
|
||||
return await this.client.api.hypesquad.online.delete();
|
||||
const data = await this.client.api.hypesquad.online.delete();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +201,7 @@ class ClientUser extends User {
|
||||
|
||||
/**
|
||||
* Set About me
|
||||
* @param {String} bio Bio to set
|
||||
* @param {string} bio Bio to set
|
||||
* @returns {Promise}
|
||||
*/
|
||||
setAboutMe(bio = null) {
|
||||
@ -250,11 +252,12 @@ class ClientUser extends User {
|
||||
if (!password && !this.client.password) {
|
||||
throw new Error('A password is required to disable an account.');
|
||||
}
|
||||
return await this.client.api.users['@me'].disable.post({
|
||||
const data = await this.client.api.users['@me'].disable.post({
|
||||
data: {
|
||||
password: this.client.password ? this.client.password : password,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -266,11 +269,12 @@ class ClientUser extends User {
|
||||
if (!password && !this.client.password) {
|
||||
throw new Error('A password is required to delete an account.');
|
||||
}
|
||||
return await this.client.api.users['@me'].delete.post({
|
||||
const data = await this.client.api.users['@me'].delete.post({
|
||||
data: {
|
||||
password: this.client.password ? this.client.password : password,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ const Integration = require('./Integration');
|
||||
const Webhook = require('./Webhook');
|
||||
const WelcomeScreen = require('./WelcomeScreen');
|
||||
const { Error } = require('../errors');
|
||||
const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
|
||||
// Disable: const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
|
||||
const GuildBanManager = require('../managers/GuildBanManager');
|
||||
const GuildChannelManager = require('../managers/GuildChannelManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
@ -637,12 +637,12 @@ class Guild extends AnonymousGuild {
|
||||
*
|
||||
* }
|
||||
*/
|
||||
async searchInteraction(options = {}) {
|
||||
searchInteraction(options = {}) {
|
||||
let { query, type, limit, offset, botID } = Object.assign(
|
||||
{ query: undefined, type: 1, limit: 1, offset: 0, botID: [] },
|
||||
options,
|
||||
);
|
||||
if (typeof type == 'string') {
|
||||
if (typeof type === 'string') {
|
||||
if (type == 'CHAT_INPUT') type = 1;
|
||||
else if (type == 'USER') type = 2;
|
||||
else if (type == 'MESSAGE') type = 3;
|
||||
@ -1242,10 +1242,10 @@ class Guild extends AnonymousGuild {
|
||||
* Change Guild Position (from * to Folder or Home)
|
||||
* @param {number} position Guild Position
|
||||
* * **WARNING**: Type = `FOLDER`, newPosition is the guild's index in the Folder.
|
||||
* @param {String|Number} type Move to folder or home
|
||||
* @param {string|number} type Move to folder or home
|
||||
* * `FOLDER`: 1
|
||||
* * `HOME`: 2
|
||||
* @param {String|Number|void|null} folderID If you want to move to folder
|
||||
* @param {string|number|void|null} folderID If you want to move to folder
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Move guild to folderID 123456, index 1
|
||||
@ -1465,10 +1465,10 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Set Community Feature
|
||||
* @param {Boolean} stats True / False to enable / disable Community Feature
|
||||
* @param {TextChannelResolvable} publicUpdatesChannel
|
||||
* @param {TextChannelResolvable} rulesChannel
|
||||
* @param {String} reason
|
||||
* @param {boolean} stats True / False to enable / disable Community Feature
|
||||
* @param {TextChannelResolvable} publicUpdatesChannel The community updates channel of the guild
|
||||
* @param {TextChannelResolvable} rulesChannel The new rules channel
|
||||
* @param {string} reason Reason for changing the community feature
|
||||
*/
|
||||
async setCommunity(stats = true, publicUpdatesChannel = '1', rulesChannel = '1', reason) {
|
||||
if (stats) {
|
||||
|
@ -316,7 +316,7 @@ class Invite extends Base {
|
||||
|
||||
/**
|
||||
* Join this Guild using this invite.
|
||||
* @param {Boolean} autoVerify Whether to automatically verify member
|
||||
* @param {boolean} autoVerify Whether to automatically verify member
|
||||
* @returns {Promise<void>}
|
||||
* @example
|
||||
* await client.fetchInvite('code').then(async invite => {
|
||||
@ -330,13 +330,13 @@ class Invite extends Base {
|
||||
.guilds(this.guild.id)
|
||||
['member-verification'].get({ query: { with_guild: false, invite_code: this.code } })
|
||||
.catch(() => {});
|
||||
if (!getForm) return void 0;
|
||||
if (!getForm) return undefined;
|
||||
const form = Object.assign(getForm.form_fields[0], { response: true });
|
||||
// Respond to the form
|
||||
// https://discord.com/api/v9/guilds/:id/requests/@me
|
||||
await this.client.api.guilds(this.guild.id).requests['@me'].put({ data: { form_fields: [form] } });
|
||||
}
|
||||
return void 0;
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const process = require('node:process');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
// Disable: const { findBestMatch } = require('string-similarity'); // Not check similarity
|
||||
const Base = require('./Base');
|
||||
const BaseMessageComponent = require('./BaseMessageComponent');
|
||||
const ClientApplication = require('./ClientApplication');
|
||||
@ -19,8 +20,7 @@ const MessageFlags = require('../util/MessageFlags');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const Util = require('../util/Util');
|
||||
const { findBestMatch } = require('string-similarity'); // not check similarity
|
||||
// const { ApplicationCommand } = require('discord.js-selfbot-v13'); - Not being used in this file, not necessary.
|
||||
// Const { ApplicationCommand } = require('discord.js-selfbot-v13'); - Not being used in this file, not necessary.
|
||||
|
||||
/**
|
||||
* @type {WeakSet<Message>}
|
||||
@ -994,7 +994,7 @@ class Message extends Base {
|
||||
// Added
|
||||
/**
|
||||
* Click specific button [Suggestion: Dux#2925]
|
||||
* @param {String<Button.customId>} buttonID Button ID
|
||||
* @param {string<Button.customId>} buttonID Button ID
|
||||
* @returns {Promise<pending>}
|
||||
*/
|
||||
async clickButton(buttonID) {
|
||||
@ -1006,10 +1006,11 @@ class Message extends Base {
|
||||
await Promise.all(
|
||||
this.components.map(async row => {
|
||||
await Promise.all(
|
||||
row.components.map(async interactionComponent => {
|
||||
row.components.map(interactionComponent => {
|
||||
if (interactionComponent.type == 'BUTTON' && interactionComponent.customId == buttonID) {
|
||||
button = interactionComponent;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
}),
|
||||
@ -1019,7 +1020,7 @@ class Message extends Base {
|
||||
}
|
||||
/**
|
||||
* Select specific menu or First Menu
|
||||
* @param {String<MessageSelectMenu.customID>|Array<MenuOptions>} menuID Select Menu specific id or auto select first Menu
|
||||
* @param {string<MessageSelectMenu.customID>|Array<MenuOptions>} menuID Select Menu specific id or auto select first Menu
|
||||
* @param {Array<MenuOptions>} options Menu Options
|
||||
*/
|
||||
async selectMenu(menuID, options = []) {
|
||||
@ -1028,7 +1029,7 @@ class Message extends Base {
|
||||
let menuCorrect;
|
||||
let menuCount = 0;
|
||||
await Promise.all(
|
||||
this.components.map(async row => {
|
||||
this.components.map(row => {
|
||||
const firstElement = row.components[0]; // Because 1 row has only 1 menu;
|
||||
if (firstElement.type == 'SELECT_MENU') {
|
||||
menuCount++;
|
||||
@ -1038,6 +1039,7 @@ class Message extends Base {
|
||||
menuFirst = firstElement;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (menuCount == 0) throw new TypeError('MENU_NOT_FOUND');
|
||||
@ -1052,7 +1054,7 @@ class Message extends Base {
|
||||
/**
|
||||
* Send context Menu v2
|
||||
* @param {DiscordBotID} botID Bot id
|
||||
* @param {String<ApplicationCommand.name>} commandName Command name in Context Menu
|
||||
* @param {string<ApplicationCommand.name>} commandName Command name in Context Menu
|
||||
* @returns {Promise<pending>}
|
||||
*/
|
||||
async contextMenu(botID, commandName) {
|
||||
@ -1068,10 +1070,11 @@ class Message extends Base {
|
||||
user.applications.cache.size == 0 ? await user.applications.fetch() : user.applications.cache;
|
||||
let contextCMD;
|
||||
await Promise.all(
|
||||
listApplication.map(async application => {
|
||||
listApplication.map(application => {
|
||||
if (commandName == application.name && application.type !== 'CHAT_INPUT') {
|
||||
contextCMD = application;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (!contextCMD) {
|
||||
|
@ -168,7 +168,7 @@ class MessageButton extends BaseMessageComponent {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
async click(message) {
|
||||
if (!message instanceof Message) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
|
||||
if (!(message instanceof Message)) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
|
||||
if (!this.customId || this.style == 5 || this.disabled) return false; // Button URL, Disabled
|
||||
await message.client.api.interactions.post({
|
||||
data: {
|
||||
|
@ -199,12 +199,12 @@ class MessagePayload {
|
||||
|
||||
if (webembeds.length > 0) {
|
||||
if (!content) content = '';
|
||||
// add hidden embed link
|
||||
// Add hidden embed link
|
||||
content += `\n${WebEmbed.hiddenEmbed} \n`;
|
||||
if (webembeds.length > 1) {
|
||||
console.warn('Multiple webembeds are not supported, this will be ignored.');
|
||||
}
|
||||
// const embed = webembeds[0];
|
||||
// Const embed = webembeds[0];
|
||||
for (const webE of webembeds) {
|
||||
const data = await webE.toMessage();
|
||||
content += `\n${data}`;
|
||||
|
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const BaseMessageComponent = require('./BaseMessageComponent');
|
||||
const { Message } = require('./Message');
|
||||
const { MessageComponentTypes } = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
const { Message } = require('./Message');
|
||||
|
||||
/**
|
||||
* Represents a select menu message component
|
||||
@ -210,35 +210,35 @@ class MessageSelectMenu extends BaseMessageComponent {
|
||||
}
|
||||
// Add
|
||||
/**
|
||||
* Select in menu
|
||||
* @param {Message} message Discord Message
|
||||
* @param {Array<String>} values Option values
|
||||
* @returns {Promise<boolean}
|
||||
* Mesage select menu
|
||||
* @param {Message} message The message this select menu is for
|
||||
* @param {Array<string>} values The values of the select menu
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async select(message, values = []) {
|
||||
// Github copilot is the best :))
|
||||
// POST data from https://github.com/phamleduy04
|
||||
if (!message instanceof Message) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
|
||||
if (!(message instanceof Message)) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
|
||||
if (!Array.isArray(values)) throw new TypeError('[INVALID_VALUES] Please pass an array of values');
|
||||
if (!this.customId || this.disabled || values.length == 0) return false; // Disabled or null customID or [] array
|
||||
// Check value is invalid [Max options is 20] => For loop
|
||||
if (values.length < this.minValues)
|
||||
throw new RangeError('[SELECT_MENU_MIN_VALUES] The minimum number of values is ' + this.minValues);
|
||||
if (values.length > this.maxValues)
|
||||
throw new RangeError('[SELECT_MENU_MAX_VALUES] The maximum number of values is ' + this.maxValues);
|
||||
if (values.length < this.minValues) {
|
||||
throw new RangeError(`[SELECT_MENU_MIN_VALUES] The minimum number of values is ${this.minValues}`);
|
||||
}
|
||||
if (values.length > this.maxValues) {
|
||||
throw new RangeError(`[SELECT_MENU_MAX_VALUES] The maximum number of values is ${this.maxValues}`);
|
||||
}
|
||||
const validValue = this.options.map(obj => obj.value);
|
||||
const check_ = await values.find(element => {
|
||||
if (typeof element !== 'string') return true;
|
||||
if (!validValue.includes(element)) return true;
|
||||
return false;
|
||||
});
|
||||
if (check_)
|
||||
if (check_) {
|
||||
throw new RangeError(
|
||||
'[SELECT_MENU_INVALID_VALUE] The value ' +
|
||||
check_ +
|
||||
' is invalid. Please use a valid value ' +
|
||||
validValue.join(', '),
|
||||
`[SELECT_MENU_INVALID_VALUE] The value ${check_} is invalid. Please use a valid value ${validValue.join(', ')}`,
|
||||
);
|
||||
}
|
||||
await message.client.api.interactions.post({
|
||||
data: {
|
||||
type: 3, // ?
|
||||
|
@ -76,16 +76,16 @@ class PartialGroupDMChannel extends Channel {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Client} client
|
||||
* @param {Object} data
|
||||
* @param {Discord.Client} client Discord Bot Client
|
||||
* @param {Object} data Channel Data
|
||||
* @private
|
||||
*/
|
||||
_setup(client, data) {
|
||||
if ('recipients' in data) {
|
||||
Promise.all(
|
||||
data.recipients.map(recipient => {
|
||||
this.recipients.set(recipient.id, client.users.cache.get(data.owner_id) || recipient);
|
||||
}),
|
||||
data.recipients.map(recipient =>
|
||||
this.recipients.set(recipient.id, client.users.cache.get(data.owner_id) || recipient),
|
||||
),
|
||||
);
|
||||
}
|
||||
if ('last_pin_timestamp' in data) {
|
||||
@ -100,7 +100,7 @@ class PartialGroupDMChannel extends Channel {
|
||||
/**
|
||||
*
|
||||
* @param {Object} data name, icon
|
||||
* @returns
|
||||
* @returns {any} any data .-.
|
||||
* @private
|
||||
*/
|
||||
async edit(data) {
|
||||
@ -129,7 +129,7 @@ class PartialGroupDMChannel extends Channel {
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
if (!user instanceof User) {
|
||||
if (!(user instanceof User)) {
|
||||
return Promise.reject(new TypeError('User is not an instance of Discord.User'));
|
||||
}
|
||||
if (this.recipients.get(user.id)) return Promise.reject(new Error('USER_ALREADY_IN_GROUP_DM_CHANNEL'));
|
||||
@ -143,7 +143,7 @@ class PartialGroupDMChannel extends Channel {
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
if (!user instanceof User) {
|
||||
if (!(user instanceof User)) {
|
||||
return Promise.reject(new TypeError('User is not an instance of Discord.User'));
|
||||
}
|
||||
if (!this.recipients.get(user.id)) return Promise.reject(new Error('USER_NOT_IN_GROUP_DM_CHANNEL'));
|
||||
@ -185,7 +185,7 @@ class PartialGroupDMChannel extends Channel {
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
if (!invite instanceof Invite) {
|
||||
if (!(invite instanceof Invite)) {
|
||||
return Promise.reject(new TypeError('Invite is not an instance of Discord.Invite'));
|
||||
}
|
||||
await this.client.api.channels(this.id).invites[invite.code].delete();
|
||||
|
@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { default: Collection } = require('@discordjs/collection');
|
||||
const Base = require('./Base');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const { Error } = require('../errors');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const UserFlags = require('../util/UserFlags');
|
||||
const { default: Collection } = require('@discordjs/collection');
|
||||
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
|
||||
const { Relationship } = require('../util/Constants');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const UserFlags = require('../util/UserFlags');
|
||||
|
||||
/**
|
||||
* Represents a user on Discord.
|
||||
@ -56,7 +56,7 @@ class User extends Base {
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.bot = Boolean(data.bot);
|
||||
if (this.bot == true) {
|
||||
if (this.bot === true) {
|
||||
this.applications = new ApplicationCommandManager(this.client, undefined, this);
|
||||
}
|
||||
} else if (!this.partial && typeof this.bot !== 'boolean') {
|
||||
@ -168,20 +168,16 @@ class User extends Base {
|
||||
*/
|
||||
async getProfile() {
|
||||
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
||||
try {
|
||||
const data = await this.client.api.users(this.id).profile.get();
|
||||
this._ProfilePatch(data);
|
||||
return this;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
const data = await this.client.api.users(this.id).profile.get();
|
||||
this._ProfilePatch(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Friends the user and send Request [If no request]
|
||||
* @returns {Promise<User>} the user object
|
||||
*/
|
||||
async setFriend() {
|
||||
setFriend() {
|
||||
return this.client.relationships.addFriend(this);
|
||||
}
|
||||
|
||||
@ -189,14 +185,14 @@ class User extends Base {
|
||||
* Send Friend Request to the user
|
||||
* @returns {Promise<User>} the user object
|
||||
*/
|
||||
async sendFriendRequest() {
|
||||
sendFriendRequest() {
|
||||
return this.client.relationships.sendFriendRequest(this.username, this.discriminator);
|
||||
}
|
||||
/**
|
||||
* Blocks the user
|
||||
* @returns {Promise<User>} the user object
|
||||
*/
|
||||
async setBlock() {
|
||||
setBlock() {
|
||||
return this.client.relationships.addBlocked(this);
|
||||
}
|
||||
|
||||
@ -204,7 +200,7 @@ class User extends Base {
|
||||
* Removes the user from your blocks list
|
||||
* @returns {Promise<User>} the user object
|
||||
*/
|
||||
async unBlock() {
|
||||
unBlock() {
|
||||
return this.client.relationships.deleteBlocked(this);
|
||||
}
|
||||
|
||||
@ -419,12 +415,12 @@ class User extends Base {
|
||||
|
||||
/**
|
||||
* Set note to user
|
||||
* @param {String<User.note>} note Note to set
|
||||
* @param {string<User.note>} note Note to set
|
||||
* @returns {Promise<User.note>}
|
||||
*/
|
||||
async setNote(note = null) {
|
||||
await this.client.api.users['@me'].notes(id).put({ data: { note } });
|
||||
return (this.note = note);
|
||||
await this.client.api.users['@me'].notes(this.id).put({ data: { note } });
|
||||
return this;
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
|
@ -23,7 +23,7 @@ class WebEmbed {
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @param {object} data
|
||||
* @param {Object} data The data for the embed
|
||||
*/
|
||||
_setup(data) {
|
||||
/**
|
||||
@ -297,7 +297,7 @@ class WebEmbed {
|
||||
arrayQuery.push(`url=${encodeURIComponent(this.url)}`);
|
||||
}
|
||||
if (this.color) {
|
||||
arrayQuery.push(`color=${encodeURIComponent('#' + this.color.toString(16))}`);
|
||||
arrayQuery.push(`color=${encodeURIComponent(`#${this.color.toString(16)}`)}`);
|
||||
}
|
||||
if (this.image?.url) {
|
||||
arrayQuery.push(`image=${encodeURIComponent(this.image.url)}`);
|
||||
@ -340,17 +340,17 @@ const getShorten = async url => {
|
||||
const APIurl = [
|
||||
// 'https://is.gd/create.php?format=simple&url=', :(
|
||||
'https://tinyurl.com/api-create.php?url=',
|
||||
'https://sagiri-fansub.tk/api/v1/short?url=', // my api, pls don't ddos :(
|
||||
'https://sagiri-fansub.tk/api/v1/short?url=', // My api, pls don't ddos :(
|
||||
'https://lazuee.ga/api/v1/shorten?url=',
|
||||
// 'https://cdpt.in/shorten?url=', Redirects 5s :(
|
||||
];
|
||||
try {
|
||||
const res = await axios.get(`${APIurl[Math.floor(Math.random() * APIurl.length)]}${encodeURIComponent(url)}`);
|
||||
if (typeof res.data == 'string') return res.data;
|
||||
else if (typeof res.data == 'object') return res.data.shorten;
|
||||
else throw null;
|
||||
if (typeof res.data === 'string') return res.data;
|
||||
else if (typeof res.data === 'object') return res.data.shorten;
|
||||
else throw new Error('Unknown error');
|
||||
} catch {
|
||||
return void 0;
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const { Message } = require('./Message');
|
||||
const MessagePayload = require('./MessagePayload');
|
||||
const { Error } = require('../errors');
|
||||
const { WebhookTypes } = require('../util/Constants');
|
||||
|
@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
/* Not used:
|
||||
const process = require('node:process');
|
||||
const Package = (exports.Package = require('../../package.json'));
|
||||
*/
|
||||
const { Error, RangeError, TypeError } = require('../errors');
|
||||
const listUserAgent = [
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
// Not used: const process = require('node:process');
|
||||
const Buffer = require('node:buffer').Buffer;
|
||||
const JSONBig = require('json-bigint');
|
||||
/**
|
||||
* Rate limit data
|
||||
|
@ -42,6 +42,6 @@
|
||||
"pretty": false,
|
||||
// Completeness
|
||||
"skipLibCheck": false,
|
||||
"skipDefaultLibCheck": true
|
||||
"skipDefaultLibCheck": true,
|
||||
}
|
||||
}
|
50
typings/index.d.ts
vendored
50
typings/index.d.ts
vendored
@ -88,6 +88,7 @@ import {
|
||||
GuildScheduledEventEntityTypes,
|
||||
GuildScheduledEventStatuses,
|
||||
GuildScheduledEventPrivacyLevels,
|
||||
HypeSquadOptions,
|
||||
} from './enums';
|
||||
import {
|
||||
RawActivityData,
|
||||
@ -258,8 +259,8 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
|
||||
private static transformCommand(command: ApplicationCommandData): RESTPostAPIApplicationCommandsJSONBody;
|
||||
private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody;
|
||||
// Add
|
||||
public static sendSlashCommand(message: Message, options?: Array<string>): Promise<Boolean>;
|
||||
public static sendContextMenu(message: Message): Promise<Boolean>;
|
||||
public static sendSlashCommand(message: Message, options?: string[]): Promise<boolean>;
|
||||
public static sendContextMenu(message: Message): Promise<boolean>;
|
||||
}
|
||||
|
||||
export type ApplicationResolvable = Application | Activity | Snowflake;
|
||||
@ -539,7 +540,7 @@ export abstract class Channel extends Base {
|
||||
public isThread(): this is ThreadChannel;
|
||||
public toString(): ChannelMention;
|
||||
//
|
||||
public sendSlash(botID: DiscordBotID, commandName: String<ApplicationCommand.name>, args?: Array<Options>): Promise;
|
||||
public sendSlash(botID: DiscordBotID, commandName: String<ApplicationCommand.name>, args?: Options[]): Promise;
|
||||
}
|
||||
|
||||
export type If<T extends boolean, A, B = null> = T extends true ? A : T extends false ? B : A | B;
|
||||
@ -571,7 +572,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public users: UserManager;
|
||||
public voice: ClientVoiceManager;
|
||||
public ws: WebSocketManager;
|
||||
public password: String | null;
|
||||
public password: string | null;
|
||||
public destroy(): void;
|
||||
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
||||
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
||||
@ -647,11 +648,10 @@ export class ClientUser extends User {
|
||||
public setPresence(data: PresenceData): ClientPresence;
|
||||
public setStatus(status: PresenceStatusData, shardId?: number | number[]): ClientPresence;
|
||||
public setUsername(username: string, password: string): Promise<this>;
|
||||
public setHypeSquad(type: HypeSquadOptions<Number | String>): Promise<void>;
|
||||
public setHypeSquad(type: HypeSquadOptions<number | string>): Promise<void>;
|
||||
public setAccentColor(color: ColorResolvable): Promise<this>;
|
||||
public setDiscriminator(discriminator: string, password: string): Promise<this>;
|
||||
public setAboutMe(bio: string): Promise<this>;
|
||||
public setBanner(): Promise<this>;
|
||||
public setEmail(email: string, password: string): Promise<this>;
|
||||
public setPassword(oldPassword: string, newPassword: string): Promise<this>;
|
||||
public disableAccount(password: string): Promise<this>;
|
||||
@ -665,12 +665,11 @@ export class ClientUser extends User {
|
||||
* `2`: Boost
|
||||
* @external
|
||||
* https://discord.com/developers/docs/resources/user#user-object-premium-types
|
||||
* @type {Number}
|
||||
*/
|
||||
public readonly nitroType: NitroType;
|
||||
public readonly phoneNumber: String;
|
||||
public readonly phoneNumber: string;
|
||||
public readonly nsfwAllowed: boolean;
|
||||
public readonly emailAddress: String;
|
||||
public readonly emailAddress: string;
|
||||
}
|
||||
type NitroType = 0 | 1 | 2;
|
||||
export class Options extends null {
|
||||
@ -1606,10 +1605,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
|
||||
public inGuild(): this is Message<true> & this;
|
||||
// Added
|
||||
public clickButton(buttonID: String<MessageButton.customId>): Promise<pending>;
|
||||
public selectMenu(
|
||||
menuID: String<MessageSelectMenu.customId> | Array<options>,
|
||||
options: Array<String>,
|
||||
): Promise<pending>;
|
||||
public selectMenu(menuID: String<MessageSelectMenu.customId> | options[], options: string[]): Promise<pending>;
|
||||
public contextMenu(botID: DiscordBotID, commandName: String<ApplicationCommand.name>): Promise;
|
||||
}
|
||||
|
||||
@ -1787,8 +1783,8 @@ export class WebEmbed {
|
||||
public title: string | null;
|
||||
public url: string | null;
|
||||
public video: MessageEmbedVideo | null;
|
||||
public hidden: Boolean;
|
||||
public shorten: Boolean;
|
||||
public hidden: boolean;
|
||||
public shorten: boolean;
|
||||
public imageType: 'thumbnail' | 'image';
|
||||
public setAuthor(options: EmbedAuthorData | null): this;
|
||||
public setColor(color: ColorResolvable): this;
|
||||
@ -1901,7 +1897,7 @@ export class MessageSelectMenu extends BaseMessageComponent {
|
||||
...options: MessageSelectOptionData[] | MessageSelectOptionData[][]
|
||||
): this;
|
||||
public toJSON(): APISelectMenuComponent;
|
||||
public select(message: Message, values: Array<String>): Promise<Boolean>;
|
||||
public select(message: Message, values: string[]): Promise<boolean>;
|
||||
}
|
||||
|
||||
export class NewsChannel extends BaseGuildTextChannel {
|
||||
@ -2507,7 +2503,7 @@ export class User extends PartialTextBasedChannel(Base) {
|
||||
public sendFriendRequest(): Promise<User>;
|
||||
public unFriend(): Promise<User>;
|
||||
public unBlock(): Promise<User>;
|
||||
public setNote(note): Promise<String>;
|
||||
public setNote(note?: any): Promise<string>;
|
||||
public getProfile(): Promise<User>;
|
||||
public toString(): UserMention;
|
||||
}
|
||||
@ -3080,7 +3076,7 @@ export class BaseGuildEmojiManager extends CachedManager<Snowflake, GuildEmoji,
|
||||
export class ChannelManager extends CachedManager<Snowflake, AnyChannel, ChannelResolvable> {
|
||||
private constructor(client: Client, iterable: Iterable<RawChannelData>);
|
||||
public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<AnyChannel | null>;
|
||||
public createGroupDM(recipients: Array<User>): Promise<PartialGroupDMChannel>;
|
||||
public createGroupDM(recipients: User[]): Promise<PartialGroupDMChannel>;
|
||||
}
|
||||
|
||||
export class ClientUserSettingManager {
|
||||
@ -3415,10 +3411,10 @@ export class UserManager extends CachedManager<Snowflake, User, UserResolvable>
|
||||
}
|
||||
|
||||
export class RelationshipsManager {
|
||||
private constructor(client: Client, users?: Array<RawRelationship>);
|
||||
private constructor(client: Client, users?: RawRelationship[]);
|
||||
public cache: Collection<Snowflake, relationshipsType>;
|
||||
public client: Client;
|
||||
private _setup(users: Array<RawRelationship>): null;
|
||||
private _setup(users: RawRelationship[]): null;
|
||||
public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<User>;
|
||||
public deleteFriend(user: UserResolvable): Promise<User>;
|
||||
public deleteBlocked(user: UserResolvable): Promise<User>;
|
||||
@ -3932,10 +3928,10 @@ export interface BaseFetchOptions {
|
||||
|
||||
export interface guildSearchInteraction {
|
||||
type?: ApplicationCommandTypes;
|
||||
query?: String | void;
|
||||
limit?: Number;
|
||||
offset?: Number;
|
||||
botID?: Array<User.id>;
|
||||
query?: string | null | undefined;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
botID?: User.id[];
|
||||
}
|
||||
|
||||
export interface BaseMessageComponentOptions {
|
||||
@ -5615,8 +5611,8 @@ export interface RawUserSettingsData {
|
||||
friend_discovery_flags?: number;
|
||||
friend_source_flags?: { all?: boolean; mutual_friends?: boolean; mututal_guilds?: boolean };
|
||||
gif_auto_play?: boolean;
|
||||
guild_folders?: Array<{ id?: Snowflake; guild_ids?: Array<Snowflake>; name?: string }>;
|
||||
guild_positions?: Array<T>;
|
||||
guild_folders?: { id?: Snowflake; guild_ids?: Snowflake[]; name?: string }[];
|
||||
guild_positions?: T[];
|
||||
inline_attachment_media?: boolean;
|
||||
inline_embed_media?: boolean;
|
||||
locale?: string;
|
||||
@ -5624,7 +5620,7 @@ export interface RawUserSettingsData {
|
||||
native_phone_integration_enabled?: boolean;
|
||||
render_embeds?: boolean;
|
||||
render_reactions?: boolean;
|
||||
restricted_guilds?: Array;
|
||||
restricted_guilds?: any[];
|
||||
show_current_game?: boolean;
|
||||
status?: PresenceStatusData;
|
||||
stream_notifications_enabled?: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user