refactor: remove unnecessary checks (#6777)

This commit is contained in:
Bas950
2021-10-08 12:35:24 +02:00
committed by GitHub
parent d399a28323
commit e24209a8b1
7 changed files with 17 additions and 22 deletions

View File

@@ -7,16 +7,15 @@ const { Events, TextBasedChannelTypes } = require('../../util/Constants');
class TypingStart extends Action { class TypingStart extends Action {
handle(data) { handle(data) {
const channel = this.getChannel(data); const channel = this.getChannel(data);
if (!channel) { if (!channel) return;
return;
}
if (!TextBasedChannelTypes.includes(channel.type)) { if (!TextBasedChannelTypes.includes(channel.type)) {
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`); this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
return; return;
} }
const user = this.getUserFromMember(data); const user = this.getUserFromMember(data);
if (channel && user) { if (user) {
/** /**
* Emitted whenever a user starts typing in a channel. * Emitted whenever a user starts typing in a channel.
* @event Client#typingStart * @event Client#typingStart

View File

@@ -4,11 +4,11 @@ const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => { module.exports = (client, { d: data }) => {
const channel = client.channels.cache.get(data.channel_id); const channel = client.channels.cache.get(data.channel_id);
const time = new Date(data.last_pin_timestamp); const time = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
if (channel && !Number.isNaN(time.getTime())) { if (channel) {
// Discord sends null for last_pin_timestamp if the last pinned message was removed // Discord sends null for last_pin_timestamp if the last pinned message was removed
channel.lastPinTimestamp = time.getTime() ?? null; channel.lastPinTimestamp = time;
/** /**
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event, * Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,

View File

@@ -57,8 +57,9 @@ class GuildStickerManager extends CachedManager {
* .catch(console.error); * .catch(console.error);
*/ */
async create(file, name, tags, { description, reason } = {}) { async create(file, name, tags, { description, reason } = {}) {
file = { ...(await MessagePayload.resolveFile(file)), key: 'file' }; const resolvedFile = await MessagePayload.resolveFile(file);
if (!file) throw new TypeError('REQ_RESOURCE_TYPE'); if (!resolvedFile) throw new TypeError('REQ_RESOURCE_TYPE');
file = { ...resolvedFile, key: 'file' };
const data = { name, tags, description: description ?? '' }; const data = { name, tags, description: description ?? '' };

View File

@@ -21,7 +21,7 @@ class Channel extends Base {
constructor(client, data, immediatePatch = true) { constructor(client, data, immediatePatch = true) {
super(client); super(client);
const type = ChannelTypes[data.type]; const type = ChannelTypes[data?.type];
/** /**
* The type of the channel * The type of the channel
* @type {ChannelType} * @type {ChannelType}

View File

@@ -45,7 +45,7 @@ class Message extends Base {
*/ */
this.deleted = false; this.deleted = false;
if (data) this._patch(data); this._patch(data);
} }
_patch(data) { _patch(data) {

10
typings/index.d.ts vendored
View File

@@ -20,7 +20,6 @@ import {
userMention, userMention,
} from '@discordjs/builders'; } from '@discordjs/builders';
import { Collection } from '@discordjs/collection'; import { Collection } from '@discordjs/collection';
import { ChildProcess } from 'child_process';
import { import {
APIActionRowComponent, APIActionRowComponent,
APIApplicationCommand, APIApplicationCommand,
@@ -47,10 +46,11 @@ import {
RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIApplicationCommandsJSONBody,
Snowflake, Snowflake,
} from 'discord-api-types/v9'; } from 'discord-api-types/v9';
import { EventEmitter } from 'events'; import { ChildProcess } from 'node:child_process';
import { AgentOptions } from 'https'; import { EventEmitter } from 'node:events';
import { Stream } from 'stream'; import { AgentOptions } from 'node:https';
import { MessagePort, Worker } from 'worker_threads'; import { Stream } from 'node:stream';
import { MessagePort, Worker } from 'node:worker_threads';
import * as WebSocket from 'ws'; import * as WebSocket from 'ws';
import { import {
ActivityTypes, ActivityTypes,

View File

@@ -1,7 +1,6 @@
import { APIGuildMember, APIInteractionGuildMember, APIMessage } from 'discord-api-types/v9'; import { APIGuildMember, APIInteractionGuildMember, APIMessage } from 'discord-api-types/v9';
import { import {
ApplicationCommand, ApplicationCommand,
ApplicationCommandChannelOption,
ApplicationCommandChannelOptionData, ApplicationCommandChannelOptionData,
ApplicationCommandChoicesData, ApplicationCommandChoicesData,
ApplicationCommandData, ApplicationCommandData,
@@ -12,8 +11,6 @@ import {
ApplicationCommandSubCommandData, ApplicationCommandSubCommandData,
ApplicationCommandSubGroupData, ApplicationCommandSubGroupData,
ButtonInteraction, ButtonInteraction,
CacheFactory,
Caches,
CategoryChannel, CategoryChannel,
Client, Client,
ClientApplication, ClientApplication,
@@ -45,11 +42,9 @@ import {
MessageCollector, MessageCollector,
MessageComponentInteraction, MessageComponentInteraction,
MessageEmbed, MessageEmbed,
MessageManager,
MessageReaction, MessageReaction,
NewsChannel, NewsChannel,
Options, Options,
PartialDMChannel,
PartialTextBasedChannelFields, PartialTextBasedChannelFields,
PartialUser, PartialUser,
Permissions, Permissions,
@@ -71,7 +66,7 @@ import {
User, User,
VoiceChannel, VoiceChannel,
} from '.'; } from '.';
import { ApplicationCommandOptionTypes, ApplicationCommandTypes } from './enums'; import { ApplicationCommandOptionTypes } from './enums';
const client: Client = new Client({ const client: Client = new Client({
intents: Intents.FLAGS.GUILDS, intents: Intents.FLAGS.GUILDS,