copy eslint + tslint from Discord.js (v13)
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { Channel } = require('./Channel');
|
||||
const { Error } = require('../errors');
|
||||
const { Collection } = require('discord.js');
|
||||
const { Message } = require('./Message');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
const User = require('./User');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const Invite = require('./Invite');
|
||||
|
||||
const User = require('./User');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const { Error } = require('../errors');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
|
||||
/**
|
||||
* Represents a Partial Group DM Channel on Discord.
|
||||
@@ -77,19 +75,16 @@ class PartialGroupDMChannel extends Channel {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Client} client
|
||||
* @param {object} data
|
||||
*
|
||||
* @param {Discord.Client} client
|
||||
* @param {Object} 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);
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -103,16 +98,17 @@ class PartialGroupDMChannel extends Channel {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} data name, icon
|
||||
* @returns
|
||||
* @returns
|
||||
* @private
|
||||
*/
|
||||
async edit(data) {
|
||||
const _data = {};
|
||||
if ('name' in data) _data.name = data.name?.trim() ?? null;
|
||||
if (typeof data.icon !== 'undefined')
|
||||
if (typeof data.icon !== 'undefined') {
|
||||
_data.icon = await DataResolver.resolveImage(data.icon);
|
||||
}
|
||||
const newData = await this.client.api.channels(this.id).patch({
|
||||
data: _data,
|
||||
});
|
||||
@@ -126,19 +122,16 @@ class PartialGroupDMChannel extends Channel {
|
||||
* @returns {?string}
|
||||
*/
|
||||
iconURL({ format, size } = {}) {
|
||||
return (
|
||||
this.icon &&
|
||||
this.client.rest.cdn.GDMIcon(this.id, this.icon, format, size)
|
||||
);
|
||||
return this.icon && this.client.rest.cdn.GDMIcon(this.id, this.icon, format, size);
|
||||
}
|
||||
|
||||
async addMember(user) {
|
||||
if (this.ownerId !== this.client.user.id)
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
if (!user instanceof User)
|
||||
return Promise.reject(
|
||||
new TypeError('User is not an instance of Discord.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'));
|
||||
//
|
||||
await this.client.api.channels[this.id].recipients[user.id].put();
|
||||
@@ -147,12 +140,12 @@ class PartialGroupDMChannel extends Channel {
|
||||
}
|
||||
|
||||
async removeMember(user) {
|
||||
if (this.ownerId !== this.client.user.id)
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
if (!user instanceof User)
|
||||
return Promise.reject(
|
||||
new TypeError('User is not an instance of Discord.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'));
|
||||
await this.client.api.channels[this.id].recipients[user.id].delete();
|
||||
this.recipients.delete(user.id);
|
||||
@@ -169,18 +162,19 @@ class PartialGroupDMChannel extends Channel {
|
||||
|
||||
async getInvite() {
|
||||
const inviteCode = await this.client.api.channels(this.id).invites.post({
|
||||
data: {
|
||||
max_age: 86400,
|
||||
},
|
||||
});
|
||||
data: {
|
||||
max_age: 86400,
|
||||
},
|
||||
});
|
||||
const invite = new Invite(this.client, inviteCode);
|
||||
this.invites.set(invite.code, invite);
|
||||
return invite;
|
||||
}
|
||||
|
||||
async fetchInvite(force = false) {
|
||||
if (this.ownerId !== this.client.user.id)
|
||||
if (this.ownerId !== this.client.user.id) {
|
||||
return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
if (!force && this.invites.size) return this.invites;
|
||||
const invites = await this.client.api.channels(this.id).invites.get();
|
||||
await Promise.all(invites.map(invite => this.invites.set(invite.code, new Invite(this.client, invite))));
|
||||
@@ -188,10 +182,12 @@ class PartialGroupDMChannel extends Channel {
|
||||
}
|
||||
|
||||
async removeInvite(invite) {
|
||||
if (this.ownerId !== this.client.user.id)
|
||||
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();
|
||||
this.invites.delete(invite.code);
|
||||
return this;
|
||||
@@ -199,10 +195,10 @@ class PartialGroupDMChannel extends Channel {
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
get lastMessage() { }
|
||||
get lastPinAt() { }
|
||||
send() { }
|
||||
sendTyping() { }
|
||||
get lastMessage() {}
|
||||
get lastPinAt() {}
|
||||
send() {}
|
||||
sendTyping() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(PartialGroupDMChannel, false);
|
||||
|
||||
Reference in New Issue
Block a user