summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/Channel.js
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-30 15:46:16 -0700
committer8cy <[email protected]>2020-04-30 15:46:16 -0700
commit3a4deac89054021b56ad5bd8005b2044cc085c98 (patch)
tree3dd6af8503e497e46180b6b5231674f36bdce9f2 /node_modules/discord.js/src/structures/Channel.js
downloaduppity-3a4deac89054021b56ad5bd8005b2044cc085c98.tar.xz
uppity-3a4deac89054021b56ad5bd8005b2044cc085c98.zip
Up, up, uppity.
Diffstat (limited to 'node_modules/discord.js/src/structures/Channel.js')
-rw-r--r--node_modules/discord.js/src/structures/Channel.js151
1 files changed, 151 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/Channel.js b/node_modules/discord.js/src/structures/Channel.js
new file mode 100644
index 0000000..1dc7ee0
--- /dev/null
+++ b/node_modules/discord.js/src/structures/Channel.js
@@ -0,0 +1,151 @@
+'use strict';
+
+const Base = require('./Base');
+const { ChannelTypes } = require('../util/Constants');
+const Snowflake = require('../util/Snowflake');
+
+/**
+ * Represents any channel on Discord.
+ * @extends {Base}
+ */
+class Channel extends Base {
+ constructor(client, data) {
+ super(client);
+
+ const type = Object.keys(ChannelTypes)[data.type];
+ /**
+ * The type of the channel, either:
+ * * `dm` - a DM 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
+ * * `unknown` - a generic channel of unknown type, could be Channel or GuildChannel
+ * @type {string}
+ */
+ this.type = type ? type.toLowerCase() : 'unknown';
+
+ /**
+ * Whether the channel has been deleted
+ * @type {boolean}
+ */
+ this.deleted = false;
+
+ if (data) this._patch(data);
+ }
+
+ _patch(data) {
+ /**
+ * The unique ID of the channel
+ * @type {Snowflake}
+ */
+ this.id = data.id;
+ }
+
+ /**
+ * The timestamp the channel was created at
+ * @type {number}
+ * @readonly
+ */
+ get createdTimestamp() {
+ return Snowflake.deconstruct(this.id).timestamp;
+ }
+
+ /**
+ * The time the channel was created at
+ * @type {Date}
+ * @readonly
+ */
+ get createdAt() {
+ return new Date(this.createdTimestamp);
+ }
+
+ /**
+ * When concatenated with a string, this automatically returns the channel's mention instead of the Channel object.
+ * @returns {string}
+ * @example
+ * // Logs: Hello from <#123456789012345678>!
+ * console.log(`Hello from ${channel}!`);
+ */
+ toString() {
+ return `<#${this.id}>`;
+ }
+
+ /**
+ * Deletes this channel.
+ * @returns {Promise<Channel>}
+ * @example
+ * // Delete the channel
+ * channel.delete()
+ * .then(console.log)
+ * .catch(console.error);
+ */
+ delete() {
+ return this.client.api
+ .channels(this.id)
+ .delete()
+ .then(() => this);
+ }
+
+ /**
+ * Fetches this channel.
+ * @returns {Promise<Channel>}
+ */
+ fetch() {
+ return this.client.channels.fetch(this.id, true);
+ }
+
+ static create(client, data, guild) {
+ const Structures = require('../util/Structures');
+ let channel;
+ if (!data.guild_id && !guild) {
+ if ((data.recipients && data.type !== ChannelTypes.GROUP) || data.type === ChannelTypes.DM) {
+ const DMChannel = Structures.get('DMChannel');
+ channel = new DMChannel(client, data);
+ } else if (data.type === ChannelTypes.GROUP) {
+ const PartialGroupDMChannel = require('./PartialGroupDMChannel');
+ channel = new PartialGroupDMChannel(client, data);
+ }
+ } else {
+ guild = guild || client.guilds.cache.get(data.guild_id);
+ if (guild) {
+ switch (data.type) {
+ case ChannelTypes.TEXT: {
+ const TextChannel = Structures.get('TextChannel');
+ channel = new TextChannel(guild, data);
+ break;
+ }
+ case ChannelTypes.VOICE: {
+ const VoiceChannel = Structures.get('VoiceChannel');
+ channel = new VoiceChannel(guild, data);
+ break;
+ }
+ case ChannelTypes.CATEGORY: {
+ const CategoryChannel = Structures.get('CategoryChannel');
+ 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.cache.set(channel.id, channel);
+ }
+ }
+ return channel;
+ }
+
+ toJSON(...props) {
+ return super.toJSON({ createdTimestamp: true }, ...props);
+ }
+}
+
+module.exports = Channel;