Eslint fix all

This commit is contained in:
March 7th
2022-04-16 19:01:05 +07:00
parent c3764e77c4
commit 2a559f7d36
38 changed files with 209 additions and 207 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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');
/**

View File

@@ -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.

View File

@@ -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;
}
/**

View File

@@ -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) {

View File

@@ -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;
}
}

View File

@@ -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) {

View File

@@ -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: {

View File

@@ -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}`;

View File

@@ -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, // ?

View File

@@ -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();

View File

@@ -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

View File

@@ -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;
}
};

View File

@@ -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');