Backport news/store channels

This commit is contained in:
Schuyler Cebulskie
2019-05-11 14:58:46 -04:00
parent ee42bdfd76
commit 5e4654ee07
6 changed files with 98 additions and 2 deletions

View File

@@ -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,

View File

@@ -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'),

View File

@@ -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;

View 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;

View 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;

View File

@@ -282,6 +282,8 @@ exports.ChannelTypes = {
VOICE: 2,
GROUP_DM: 3,
CATEGORY: 4,
NEWS: 5,
STORE: 6,
};
exports.OPCodes = {