refactor(Channel): change channel types to UPPER_CASE (#6035)

This commit is contained in:
Rodry
2021-07-08 21:32:19 +01:00
committed by GitHub
parent b170fb5ce8
commit 6301728d35
26 changed files with 190 additions and 154 deletions

View File

@@ -12,7 +12,7 @@ class ChannelUpdateAction extends Action {
if (channel) {
const old = channel._update(data);
if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
if (ChannelTypes[channel.type] !== data.type) {
const newChannel = Channel.create(this.client, data, channel.guild);
for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
newChannel._typing = new Map(channel._typing);

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
class GuildDeleteAction extends Action {
constructor(client) {
@@ -15,7 +15,7 @@ class GuildDeleteAction extends Action {
let guild = client.guilds.cache.get(data.id);
if (guild) {
for (const channel of guild.channels.cache.values()) {
if (channel.type === 'text') channel.stopTyping(true);
if (channel.type in TextBasedChannelTypes) channel.stopTyping(true);
}
if (data.unavailable) {

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { PartialTypes } = require('../../util/Constants');
/*
@@ -23,7 +23,7 @@ class MessageReactionAdd extends Action {
// Verify channel
const channel = this.getChannel(data);
if (!channel || channel.type === 'voice') return false;
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
/*
{ user_id: 'id',
@@ -20,7 +20,7 @@ class MessageReactionRemove extends Action {
// Verify channel
const channel = this.getChannel(data);
if (!channel || channel.type === 'voice') return false;
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,13 +1,13 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
class MessageReactionRemoveAll extends Action {
handle(data) {
// Verify channel
const channel = this.getChannel(data);
if (!channel || channel.type === 'voice') return false;
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,12 +1,12 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
class MessageReactionRemoveEmoji extends Action {
handle(data) {
const channel = this.getChannel(data);
if (!channel || channel.type === 'voice') return false;
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
const message = this.getMessage(data, channel);
if (!message) return false;

View File

@@ -1,8 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const textBasedChannelTypes = ['dm', 'text', 'news', 'news_thread', 'public_thread', 'private_thread'];
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
class TypingStart extends Action {
handle(data) {
@@ -10,7 +9,7 @@ class TypingStart extends Action {
if (!channel) {
return;
}
if (!textBasedChannelTypes.includes(channel.type)) {
if (!(channel.type in TextBasedChannelTypes)) {
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
return;
}