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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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