mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Backport news/store channels
This commit is contained in:
@@ -1,15 +1,56 @@
|
||||
const Action = require('./Action');
|
||||
const Channel = require('../../structures/Channel');
|
||||
const TextChannel = require('../../structures/TextChannel');
|
||||
const VoiceChannel = require('../../structures/VoiceChannel');
|
||||
const CategoryChannel = require('../../structures/CategoryChannel');
|
||||
const NewsChannel = require('../../structures/NewsChannel');
|
||||
const StoreChannel = require('../../structures/StoreChannel');
|
||||
const Constants = require('../../util/Constants');
|
||||
const ChannelTypes = Constants.ChannelTypes;
|
||||
const Util = require('../../util/Util');
|
||||
|
||||
class ChannelUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const channel = client.channels.get(data.id);
|
||||
let channel = client.channels.get(data.id);
|
||||
if (channel) {
|
||||
const oldChannel = Util.cloneObject(channel);
|
||||
channel.setup(data);
|
||||
|
||||
// If the channel is changing types, we need to follow a different process
|
||||
if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
|
||||
// Determine which channel class we're changing to
|
||||
let channelClass;
|
||||
switch (data.type) {
|
||||
case ChannelTypes.TEXT:
|
||||
channelClass = TextChannel;
|
||||
break;
|
||||
case ChannelTypes.VOICE:
|
||||
channelClass = VoiceChannel;
|
||||
break;
|
||||
case ChannelTypes.CATEGORY:
|
||||
channelClass = CategoryChannel;
|
||||
break;
|
||||
case ChannelTypes.NEWS:
|
||||
channelClass = NewsChannel;
|
||||
break;
|
||||
case ChannelTypes.STORE:
|
||||
channelClass = StoreChannel;
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the new channel instance and copy over cached data
|
||||
const newChannel = new channelClass(channel.guild, data);
|
||||
if (channel.messages && newChannel.messages) {
|
||||
for (const [id, message] of channel.messages) newChannel.messages.set(id, message);
|
||||
}
|
||||
|
||||
channel = newChannel;
|
||||
this.client.channels.set(channel.id, channel);
|
||||
} else {
|
||||
channel.setup(data);
|
||||
}
|
||||
|
||||
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
|
||||
return {
|
||||
old: oldChannel,
|
||||
|
||||
@@ -47,6 +47,7 @@ module.exports = {
|
||||
MessageEmbed: require('./structures/MessageEmbed'),
|
||||
MessageMentions: require('./structures/MessageMentions'),
|
||||
MessageReaction: require('./structures/MessageReaction'),
|
||||
NewsChannel: require('./structures/NewsChannel'),
|
||||
OAuth2Application: require('./structures/OAuth2Application'),
|
||||
ClientOAuth2Application: require('./structures/OAuth2Application'),
|
||||
PartialGuild: require('./structures/PartialGuild'),
|
||||
@@ -57,6 +58,7 @@ module.exports = {
|
||||
ReactionCollector: require('./structures/ReactionCollector'),
|
||||
RichEmbed: require('./structures/RichEmbed'),
|
||||
Role: require('./structures/Role'),
|
||||
StoreChannel: require('./structures/StoreChannel'),
|
||||
TextChannel: require('./structures/TextChannel'),
|
||||
User: require('./structures/User'),
|
||||
VoiceChannel: require('./structures/VoiceChannel'),
|
||||
|
||||
@@ -20,6 +20,8 @@ class Channel {
|
||||
* * `text` - a guild text channel
|
||||
* * `voice` - a guild voice channel
|
||||
* * `category` - a guild category channel
|
||||
* * `news` - a guild news channel
|
||||
* * `store` - a guild store channel
|
||||
* @type {string}
|
||||
*/
|
||||
this.type = null;
|
||||
|
||||
24
src/structures/NewsChannel.js
Normal file
24
src/structures/NewsChannel.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const TextChannel = require('./TextChannel');
|
||||
|
||||
/**
|
||||
* Represents a guild news channel on Discord.
|
||||
* @extends {TextChannel}
|
||||
*/
|
||||
class NewsChannel extends TextChannel {
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.type = 'news';
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
|
||||
/**
|
||||
* The ratelimit per user for this channel (always 0)
|
||||
* @type {number}
|
||||
*/
|
||||
this.rateLimitPerUser = 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NewsChannel;
|
||||
25
src/structures/StoreChannel.js
Normal file
25
src/structures/StoreChannel.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const GuildChannel = require('./GuildChannel');
|
||||
|
||||
/**
|
||||
* Represents a guild store channel on Discord.
|
||||
* @extends {GuildChannel}
|
||||
*/
|
||||
class StoreChannel extends GuildChannel {
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.type = 'store';
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
|
||||
/**
|
||||
* If the guild considers this channel NSFW
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
this.nsfw = data.nsfw;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StoreChannel;
|
||||
@@ -282,6 +282,8 @@ exports.ChannelTypes = {
|
||||
VOICE: 2,
|
||||
GROUP_DM: 3,
|
||||
CATEGORY: 4,
|
||||
NEWS: 5,
|
||||
STORE: 6,
|
||||
};
|
||||
|
||||
exports.OPCodes = {
|
||||
|
||||
Reference in New Issue
Block a user