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

@@ -415,31 +415,73 @@ exports.SystemMessageTypes = exports.MessageTypes.filter(
*/
exports.ActivityTypes = createEnum(['PLAYING', 'STREAMING', 'LISTENING', 'WATCHING', 'CUSTOM', 'COMPETING']);
/**
* All available channel types:
* * `GUILD_TEXT` - a guild text channel
* * `DM` - a DM channel
* * `GUILD_VOICE` - a guild voice channel
* * `GROUP_DM` - a group DM channel
* * `GUILD_CATEGORY` - a guild category channel
* * `GUILD_NEWS` - a guild news channel
* * `GUILD_STORE` - a guild store channel
* * `GUILD_NEWS_THREAD` - a guild news channel's public thread channel
* * `GUILD_PUBLIC_THREAD` - a guild text channel's public thread channel
* * `GUILD_PRIVATE_THREAD` - a guild text channel's private thread channel
* * `GUILD_STAGE_VOICE` - a guild stage voice channel
* * `UNKNOWN` - a generic channel of unknown type, could be Channel or GuildChannel
* @typedef {string} ChannelType
*/
exports.ChannelTypes = createEnum([
'TEXT',
'GUILD_TEXT',
'DM',
'VOICE',
'GROUP',
'CATEGORY',
'NEWS',
// 6
'STORE',
'GUILD_VOICE',
'GROUP_DM',
'GUILD_CATEGORY',
'GUILD_NEWS',
'GUILD_STORE',
...Array(3).fill(null),
// 10
'NEWS_THREAD',
'PUBLIC_THREAD',
'PRIVATE_THREAD',
'STAGE',
'GUILD_NEWS_THREAD',
'GUILD_PUBLIC_THREAD',
'GUILD_PRIVATE_THREAD',
'GUILD_STAGE_VOICE',
]);
/**
* The types of channels that are threads. The available types are:
* * news_thread
* * public_thread
* * private_thread
* @typedef {string} ThreadChannelType
* The types of channels that are text-based. The available types are:
* * DM
* * GUILD_TEXT
* * GUILD_NEWS
* * GUILD_NEWS_THREAD
* * GUILD_PUBLIC_THREAD
* * GUILD_PRIVATE_THREAD
* @typedef {string} TextBasedChannelTypes
*/
exports.ThreadChannelTypes = ['news_thread', 'public_thread', 'private_thread'];
exports.TextBasedChannelTypes = [
'DM',
'GUILD_TEXT',
'GUILD_NEWS',
'GUILD_NEWS_THREAD',
'GUILD_PUBLIC_THREAD',
'GUILD_PRIVATE_THREAD',
];
/**
* The types of channels that are threads. The available types are:
* * GUILD_NEWS_THREAD
* * GUILD_PUBLIC_THREAD
* * GUILD_PRIVATE_THREAD
* @typedef {string} ThreadChannelTypes
*/
exports.ThreadChannelTypes = ['GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'];
/**
* The types of channels that are voice-based. The available types are:
* * GUILD_VOICE
* * GUILD_STAGE_VOICE
* @typedef {string} VoiceBasedChannelTypes
*/
exports.VoiceBasedChannelTypes = ['GUILD_VOICE', 'GUILD_STAGE_VOICE'];
exports.ClientApplicationAssetTypes = {
SMALL: 1,

View File

@@ -582,7 +582,7 @@ class Util extends null {
str = str
.replace(/<@!?[0-9]+>/g, input => {
const id = input.replace(/<|!|>|@/g, '');
if (channel.type === 'dm') {
if (channel.type === 'DM') {
const user = channel.client.users.cache.get(id);
return user ? Util.removeMentions(`@${user.username}`) : input;
}
@@ -600,7 +600,7 @@ class Util extends null {
return mentionedChannel ? `#${mentionedChannel.name}` : input;
})
.replace(/<@&[0-9]+>/g, input => {
if (channel.type === 'dm') return input;
if (channel.type === 'DM') return input;
const role = channel.guild.roles.cache.get(input.replace(/<|@|>|&/g, ''));
return role ? `@${role.name}` : input;
});