Skip to content

Commit

Permalink
NewsChannel (type 5) Support (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayzure authored and abalabahaha committed Apr 19, 2019
1 parent 2e444a4 commit 247092d
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -24,6 +24,7 @@ Eris.GuildIntegration = require("./lib/structures/GuildIntegration");
Eris.Invite = require("./lib/structures/Invite");
Eris.Member = require("./lib/structures/Member");
Eris.Message = require("./lib/structures/Message");
Eris.NewsChannel = require("./lib/structures/NewsChannel");
Eris.Permission = require("./lib/structures/Permission");
Eris.PermissionOverwrite = require("./lib/structures/PermissionOverwrite");
Eris.PrivateChannel = require("./lib/structures/PrivateChannel");
Expand Down
17 changes: 9 additions & 8 deletions lib/Client.js
Expand Up @@ -18,6 +18,7 @@ const RequestHandler = require("./rest/RequestHandler");
const Role = require("./structures/Role");
const ShardManager = require("./gateway/ShardManager");
const TextChannel = require("./structures/TextChannel");
const NewsChannel = require("./structures/NewsChannel");
const UnavailableGuild = require("./structures/UnavailableGuild");
const User = require("./structures/User");
const VoiceChannel = require("./structures/VoiceChannel");
Expand Down Expand Up @@ -342,7 +343,7 @@ class Client extends EventEmitter {
/**
* Get a Channel object from a channel ID
* @arg {String} channelID The ID of the channel
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel}
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel}
*/
getChannel(channelID) {
if(!channelID) {
Expand Down Expand Up @@ -393,7 +394,7 @@ class Client extends EventEmitter {
} else if(channel.type === 4) {
return new CategoryChannel(channel, guild);
} else if(channel.type === 5) {
return new TextChannel(channel, guild);
return new NewsChannel(channel, guild);
} else if(channel.type === 0 || channel.last_message_id !== undefined) {
return new TextChannel(channel, guild);
} else {
Expand All @@ -416,7 +417,7 @@ class Client extends EventEmitter {
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (guild text channels only)
* @arg {String?} [options.parentID] The ID of the parent channel category for this channel (guild text/voice channels only)
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | VoiceChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | VoiceChannel | NewsChannel>}
*/
editChannel(channelID, options, reason) {
return this.requestHandler.request("PATCH", Endpoints.CHANNEL(channelID), true, {
Expand All @@ -441,7 +442,7 @@ class Client extends EventEmitter {
} else if(data.type === 4) {
return new CategoryChannel(data, guild);
} else if(data.type === 5) {
return new TextChannel(data, guild);
return new NewsChannel(data, guild);
} else if(data.type === 0 || (data.guild_id && data.last_message_id !== undefined)) {
return new TextChannel(data, guild);
} else {
Expand Down Expand Up @@ -1815,7 +1816,7 @@ class Client extends EventEmitter {
/**
* Get a channel's data via the REST API. REST mode is required to use this endpoint.
* @arg {String} channelID The ID of the channel
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel>}
*/
getRESTChannel(channelID) {
if(!this.options.restMode) {
Expand All @@ -1831,7 +1832,7 @@ class Client extends EventEmitter {
} else if(channel.type === 4) {
return new CategoryChannel(channel, null);
} else if(channel.type === 5) {
return new TextChannel(channel, null, this.options.messageLimit);
return new NewsChannel(channel, null, this.options.messageLimit);
} else if(channel.type === 0 || (channel.guild_id && channel.last_message_id !== undefined)) {
return new TextChannel(channel, null, this.options.messageLimit);
} else {
Expand Down Expand Up @@ -1873,7 +1874,7 @@ class Client extends EventEmitter {
/**
* Get a guild's channels via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @returns {Promise<(CategoryChannel[] | TextChannel[] | VoiceChannel[])>}
* @returns {Promise<(CategoryChannel[] | TextChannel[] | VoiceChannel[] | NewsChannel[])>}
*/
getRESTGuildChannels(guildID) {
if(!this.options.restMode) {
Expand All @@ -1885,7 +1886,7 @@ class Client extends EventEmitter {
} else if(channel.type === 4) {
return new CategoryChannel(channel, null);
} else if(channel.type === 5) {
return new TextChannel(channel, null, this.options.messageLimit);
return new NewsChannel(channel, null, this.options.messageLimit);
} else if(channel.type === 0 || channel.last_message_id !== undefined) {
return new TextChannel(channel, null, this.options.messageLimit);
} else {
Expand Down
5 changes: 3 additions & 2 deletions lib/gateway/Shard.js
Expand Up @@ -8,6 +8,7 @@ const ExtendedUser = require("../structures/ExtendedUser");
const GuildChannel = require("../structures/GuildChannel");
const OPCodes = Constants.GatewayOPCodes;
const TextChannel = require("../structures/TextChannel");
const NewsChannel = require("../structures/NewsChannel");
const User = require("../structures/User");
const VoiceChannel = require("../structures/VoiceChannel");
let WebSocket = typeof window !== "undefined" ? window.WebSocket : require("ws");
Expand Down Expand Up @@ -881,7 +882,7 @@ class Shard extends EventEmitter {
} else if(packet.d.type === 4) {
channel = guild.channels.add(new CategoryChannel(packet.d, guild), guild);
} else if(packet.d.type === 5) {
channel = guild.channels.add(new TextChannel(packet.d, guild), guild);
channel = guild.channels.add(new NewsChannel(packet.d, guild), guild);
} else if(packet.d.type === 0 || (packet.d.guild_id && packet.d.last_message_id !== undefined)) {
channel = guild.channels.add(new TextChannel(packet.d, guild), guild);
} else {
Expand Down Expand Up @@ -951,7 +952,7 @@ class Shard extends EventEmitter {
channel = guild.channels.add(new CategoryChannel(packet.d, guild), guild);
} else if(packet.d.type === 5) {
guild.channels.remove(channel);
channel = guild.channels.add(new TextChannel(packet.d, guild), guild);
channel = guild.channels.add(new NewsChannel(packet.d, guild), guild);
} else if(packet.d.type === 0 || packet.d.last_message_id !== undefined) {
guild.channels.remove(channel);
channel = guild.channels.add(new TextChannel(packet.d, guild), guild);
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/Channel.js
Expand Up @@ -3,7 +3,7 @@
const Base = require("./Base");

/**
* Represents a channel. You also probably want to look at CategoryChannel, GroupChannel, PrivateChannel, TextChannel, and VoiceChannel.
* Represents a channel. You also probably want to look at CategoryChannel, GroupChannel, PrivateChannel, TextChannel, NewsChannel, and VoiceChannel.
* @prop {String} id The ID of the channel
* @prop {String} mention A string that mentions the channel
* @prop {Number} type The type of the channel
Expand Down
3 changes: 2 additions & 1 deletion lib/structures/Guild.js
Expand Up @@ -9,6 +9,7 @@ const GuildChannel = require("./GuildChannel");
const Member = require("./Member");
const Role = require("./Role");
const TextChannel = require("./TextChannel");
const NewsChannel = require("./NewsChannel");
const VoiceChannel = require("./VoiceChannel");

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ class Guild extends Base {
} else if(channel.type === 4) {
channel = this.channels.add(new CategoryChannel(channel, this), this);
} else if(channel.type === 5) {
channel = this.channels.add(new TextChannel(channel, this), this);
channel = this.channels.add(new NewsChannel(channel, this), this);
} else if(channel.type === 0 || channel.last_message_id !== undefined) {
channel = this.channels.add(new TextChannel(channel, this), this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/GuildAuditLogEntry.js
Expand Up @@ -11,7 +11,7 @@ const Invite = require("./Invite");
* @prop {String?} reason The reason for the action
* @prop {User} user The user that performed the action
* @prop {String} targetID The ID of the action target
* @prop {(CategoryChannel | Guild | Member | Invite | Role | Object | TextChannel | VoiceChannel)?} target The object of the action target
* @prop {(CategoryChannel | Guild | Member | Invite | Role | Object | TextChannel | VoiceChannel | NewsChannel)?} target The object of the action target
* If the item is not cached, this property will be null
* If the action targets a guild, this could be a Guild object
* If the action targets a guild channel, this could be a CategoryChannel, TextChannel, or VoiceChannel object
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/GuildChannel.js
Expand Up @@ -7,7 +7,7 @@ const Permissions = require("../Constants").Permissions;
const PermissionOverwrite = require("./PermissionOverwrite");

/**
* Represents a guild channel. You also probably want to look at CategoryChannel, TextChannel, and VoiceChannel.
* Represents a guild channel. You also probably want to look at CategoryChannel, TextChannel, NewsChannel, and VoiceChannel.
* @extends Channel
* @prop {String} id The ID of the channel
* @prop {String} mention A string that mentions the channel
Expand Down Expand Up @@ -88,7 +88,7 @@ class GuildChannel extends Channel {
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (guild text channels only)
* @arg {Number?} [options.parentID] The ID of the parent channel category for this channel (guild text/voice channels only)
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<CategoryChannel | TextChannel | VoiceChannel>}
* @returns {Promise<CategoryChannel | TextChannel | VoiceChannel | NewsChannel>}
*/
edit(options, reason) {
return this.guild.shard.client.editChannel.call(this.guild.shard.client, this.id, options, reason);
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/Message.js
Expand Up @@ -8,7 +8,7 @@ const User = require("./User");
/**
* Represents a message
* @prop {String} id The ID of the message
* @prop {PrivateChannel | TextChannel} channel The channel the message is in
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the message is in
* @prop {Number} timestamp Timestamp of message creation
* @prop {Number} type The type of the message
* @prop {User} author The message author
Expand Down
35 changes: 35 additions & 0 deletions lib/structures/NewsChannel.js
@@ -0,0 +1,35 @@
"use strict";

const TextChannel = require("./TextChannel");

/**
* Represents a guild news channel
* @extends TextChannel
* @prop {String} id The ID of the channel
* @prop {String} mention A string that mentions the channel
* @prop {Number} type The type of the channel
* @prop {Guild} guild The guild that owns the channel
* @prop {String?} parentID The ID of the category this channel belongs to
* @prop {String} name The name of the channel
* @prop {Number} position The position of the channel
* @prop {Boolean} nsfw Whether the channel is an NSFW channel or not
* @prop {Collection<PermissionOverwrite>} permissionOverwrites Collection of PermissionOverwrites in this channel
* @prop {Collection<Message>} messages Collection of Messages in this channel
* @prop {String} lastMessageID The ID of the last message in this channel
* @prop {Number} lastPinTimestamp The timestamp of the last pinned message
* @prop {String?} topic The topic of the channel
* @prop {Number} rateLimitPerUser The ratelimit of the channel, in seconds. 0 means no ratelimit is enabled. Always 0 in NewsChannel
*/
class NewsChannel extends TextChannel {
constructor(data, guild, messageLimit) {
super(data, guild, messageLimit);
this.rateLimitPerUser = 0;
this.update(data);
}

update(data) {
super.update(data);
}
}

module.exports = NewsChannel;
1 change: 1 addition & 0 deletions lib/structures/TextChannel.js
Expand Up @@ -20,6 +20,7 @@ const Message = require("./Message");
* @prop {String} lastMessageID The ID of the last message in this channel
* @prop {Number} lastPinTimestamp The timestamp of the last pinned message
* @prop {String?} topic The topic of the channel
* @prop {Number} rateLimitPerUser The ratelimit of the channel, in seconds. 0 means no ratelimit is enabled
*/
class TextChannel extends GuildChannel {
constructor(data, guild, messageLimit) {
Expand Down

0 comments on commit 247092d

Please sign in to comment.