mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
Backport news/store channels
This commit is contained in:
@@ -1,15 +1,56 @@
|
|||||||
const Action = require('./Action');
|
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 Constants = require('../../util/Constants');
|
||||||
|
const ChannelTypes = Constants.ChannelTypes;
|
||||||
const Util = require('../../util/Util');
|
const Util = require('../../util/Util');
|
||||||
|
|
||||||
class ChannelUpdateAction extends Action {
|
class ChannelUpdateAction extends Action {
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
|
|
||||||
const channel = client.channels.get(data.id);
|
let channel = client.channels.get(data.id);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
const oldChannel = Util.cloneObject(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);
|
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
|
||||||
return {
|
return {
|
||||||
old: oldChannel,
|
old: oldChannel,
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ module.exports = {
|
|||||||
MessageEmbed: require('./structures/MessageEmbed'),
|
MessageEmbed: require('./structures/MessageEmbed'),
|
||||||
MessageMentions: require('./structures/MessageMentions'),
|
MessageMentions: require('./structures/MessageMentions'),
|
||||||
MessageReaction: require('./structures/MessageReaction'),
|
MessageReaction: require('./structures/MessageReaction'),
|
||||||
|
NewsChannel: require('./structures/NewsChannel'),
|
||||||
OAuth2Application: require('./structures/OAuth2Application'),
|
OAuth2Application: require('./structures/OAuth2Application'),
|
||||||
ClientOAuth2Application: require('./structures/OAuth2Application'),
|
ClientOAuth2Application: require('./structures/OAuth2Application'),
|
||||||
PartialGuild: require('./structures/PartialGuild'),
|
PartialGuild: require('./structures/PartialGuild'),
|
||||||
@@ -57,6 +58,7 @@ module.exports = {
|
|||||||
ReactionCollector: require('./structures/ReactionCollector'),
|
ReactionCollector: require('./structures/ReactionCollector'),
|
||||||
RichEmbed: require('./structures/RichEmbed'),
|
RichEmbed: require('./structures/RichEmbed'),
|
||||||
Role: require('./structures/Role'),
|
Role: require('./structures/Role'),
|
||||||
|
StoreChannel: require('./structures/StoreChannel'),
|
||||||
TextChannel: require('./structures/TextChannel'),
|
TextChannel: require('./structures/TextChannel'),
|
||||||
User: require('./structures/User'),
|
User: require('./structures/User'),
|
||||||
VoiceChannel: require('./structures/VoiceChannel'),
|
VoiceChannel: require('./structures/VoiceChannel'),
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class Channel {
|
|||||||
* * `text` - a guild text channel
|
* * `text` - a guild text channel
|
||||||
* * `voice` - a guild voice channel
|
* * `voice` - a guild voice channel
|
||||||
* * `category` - a guild category channel
|
* * `category` - a guild category channel
|
||||||
|
* * `news` - a guild news channel
|
||||||
|
* * `store` - a guild store channel
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.type = null;
|
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,
|
VOICE: 2,
|
||||||
GROUP_DM: 3,
|
GROUP_DM: 3,
|
||||||
CATEGORY: 4,
|
CATEGORY: 4,
|
||||||
|
NEWS: 5,
|
||||||
|
STORE: 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.OPCodes = {
|
exports.OPCodes = {
|
||||||
|
|||||||
Reference in New Issue
Block a user