mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
src: add news and store channels, and missing guild props (#3168)
* src: Implement store and news channels! * src: Remove code dupe * src: Add missing guild properties * docs: Add a small notice that the channel type may also change * src: Remove re-creation of the MessageStore * lint: Unused Import * src: Requested changes for StoreChannels * typings: Fix typings * src: Moar guild updates * src: Set maximumPresence to the data prop, the already existent one, or default to 5000 * typings: afkChannel is a VC I keep confusing them, ffs Co-Authored-By: vladfrangu <kingdgrizzle@gmail.com> * docs: Document that maximumMembers and maximumPresences may be inaccurate before fetching * src Appels requested changes
This commit is contained in:
@@ -116,6 +116,16 @@ class Channel extends Base {
|
||||
channel = new CategoryChannel(guild, data);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.NEWS: {
|
||||
const NewsChannel = Structures.get('NewsChannel');
|
||||
channel = new NewsChannel(guild, data);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.STORE: {
|
||||
const StoreChannel = Structures.get('StoreChannel');
|
||||
channel = new StoreChannel(guild, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (channel) guild.channels.set(channel.id, channel);
|
||||
}
|
||||
|
||||
@@ -186,6 +186,27 @@ class Guild extends Base {
|
||||
*/
|
||||
this.embedEnabled = data.embed_enabled;
|
||||
|
||||
/**
|
||||
* Whether widget images are enabled on this guild
|
||||
* @type {?boolean}
|
||||
* @name Guild#widgetEnabled
|
||||
*/
|
||||
if (typeof data.widget_enabled !== 'undefined') this.widgetEnabled = data.widget_enabled;
|
||||
|
||||
/**
|
||||
* The widget channel ID, if enabled
|
||||
* @type {?string}
|
||||
* @name Guild#widgetChannelID
|
||||
*/
|
||||
if (typeof data.widget_channel_id !== 'undefined') this.widgetChannelID = data.widget_channel_id;
|
||||
|
||||
/**
|
||||
* The embed channel ID, if enabled
|
||||
* @type {?string}
|
||||
* @name Guild#embedChannelID
|
||||
*/
|
||||
if (typeof data.embed_channel_id !== 'undefined') this.embedChannelID = data.embed_channel_id;
|
||||
|
||||
/**
|
||||
* The verification level of the guild
|
||||
* @type {number}
|
||||
@@ -211,12 +232,46 @@ class Guild extends Base {
|
||||
this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp;
|
||||
|
||||
/**
|
||||
* The value set for a guild's default message notifications
|
||||
* The value set for the guild's default message notifications
|
||||
* @type {DefaultMessageNotifications|number}
|
||||
*/
|
||||
this.defaultMessageNotifications = DefaultMessageNotifications[data.default_message_notifications] ||
|
||||
data.default_message_notifications;
|
||||
|
||||
/**
|
||||
* The maximum amount of members the guild can have
|
||||
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
|
||||
* @type {?number}
|
||||
* @name Guild#maximumMembers
|
||||
*/
|
||||
if (typeof data.max_members !== 'undefined') this.maximumMembers = data.max_members || 250000;
|
||||
|
||||
/**
|
||||
* The maximum amount of presences the guild can have
|
||||
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
|
||||
* @type {?number}
|
||||
* @name Guild#maximumPresences
|
||||
*/
|
||||
if (typeof data.max_presences !== 'undefined') this.maximumPresences = data.max_presences || 5000;
|
||||
|
||||
/**
|
||||
* The vanity URL code of the guild, if any
|
||||
* @type {?string}
|
||||
*/
|
||||
this.vanityURLCode = data.vanity_url_code;
|
||||
|
||||
/**
|
||||
* The description of the guild, if any
|
||||
* @type {?string}
|
||||
*/
|
||||
this.description = data.description;
|
||||
|
||||
/**
|
||||
* The hash of the guild banner
|
||||
* @type {?string}
|
||||
*/
|
||||
this.banner = data.banner;
|
||||
|
||||
this.id = data.id;
|
||||
this.available = !data.unavailable;
|
||||
this.features = data.features || this.features || [];
|
||||
@@ -274,6 +329,16 @@ class Guild extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL to this guild's banner.
|
||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||
* @returns {?string}
|
||||
*/
|
||||
bannerURL({ format, size } = {}) {
|
||||
if (!this.banner) return null;
|
||||
return this.client.rest.cdn.Banner(this.id, this.banner, format, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp the guild was created at
|
||||
* @type {number}
|
||||
@@ -368,6 +433,24 @@ class Guild extends Base {
|
||||
return this.client.channels.get(this.systemChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget channel for this guild
|
||||
* @type {?TextChannel}
|
||||
* @readonly
|
||||
*/
|
||||
get widgetChannel() {
|
||||
return this.client.channels.get(this.widgetChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed channel for this guild
|
||||
* @type {?TextChannel}
|
||||
* @readonly
|
||||
*/
|
||||
get embedChannel() {
|
||||
return this.client.channels.get(this.embedChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `@everyone` role of the guild
|
||||
* @type {?Role}
|
||||
@@ -409,6 +492,17 @@ class Guild extends Base {
|
||||
return this.members.resolve(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches this guild.
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
fetch() {
|
||||
return this.client.api.guilds(this.id).get().then(data => {
|
||||
this._patch(data);
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An object containing information about a guild member's ban.
|
||||
* @typedef {Object} BanInfo
|
||||
@@ -975,6 +1069,7 @@ class Guild extends Base {
|
||||
});
|
||||
json.iconURL = this.iconURL();
|
||||
json.splashURL = this.splashURL();
|
||||
json.bannerURL = this.bannerURL();
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
18
src/structures/NewsChannel.js
Normal file
18
src/structures/NewsChannel.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const TextChannel = require('./TextChannel');
|
||||
|
||||
/**
|
||||
* Represents a guild news channel on Discord.
|
||||
* @extends {TextChannel}
|
||||
*/
|
||||
class NewsChannel extends TextChannel {
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
|
||||
// News channels don't have a rate limit per user, remove it
|
||||
this.rateLimitPerUser = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NewsChannel;
|
||||
22
src/structures/StoreChannel.js
Normal file
22
src/structures/StoreChannel.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const GuildChannel = require('./GuildChannel');
|
||||
|
||||
/**
|
||||
* Represents a guild store channel on Discord.
|
||||
* @extends {GuildChannel}
|
||||
*/
|
||||
class StoreChannel extends GuildChannel {
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
|
||||
/**
|
||||
* If the guild considers this channel NSFW
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
this.nsfw = data.nsfw;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StoreChannel;
|
||||
@@ -139,7 +139,6 @@ class TextChannel extends GuildChannel {
|
||||
awaitMessages() {}
|
||||
bulkDelete() {}
|
||||
acknowledge() {}
|
||||
_cacheMessage() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(TextChannel, true);
|
||||
|
||||
Reference in New Issue
Block a user