/
StageInstance.js
143 lines (125 loc) · 3.23 KB
/
StageInstance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'use strict';
const Base = require('./Base');
const { PrivacyLevels } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
/**
* Represents a stage instance.
* @extends {Base}
*/
class StageInstance extends Base {
constructor(client, data) {
super(client);
/**
* The stage instance's id
* @type {Snowflake}
*/
this.id = data.id;
/**
* Whether the stage instance has been deleted
* @type {boolean}
*/
this.deleted = false;
this._patch(data);
}
_patch(data) {
/**
* The id of the guild associated with the stage channel
* @type {Snowflake}
*/
this.guildId = data.guild_id;
/**
* The id of the channel associated with the stage channel
* @type {Snowflake}
*/
this.channelId = data.channel_id;
/**
* The topic of the stage instance
* @type {string}
*/
this.topic = data.topic;
/**
* The privacy level of the stage instance
* @type {PrivacyLevel}
*/
this.privacyLevel = PrivacyLevels[data.privacy_level];
/**
* Whether or not stage discovery is disabled
* @type {?boolean}
*/
this.discoverableDisabled = data.discoverable_disabled ?? null;
}
/**
* The stage channel associated with this stage instance
* @type {?StageChannel}
* @readonly
*/
get channel() {
return this.client.channels.resolve(this.channelId);
}
/**
* The guild this stage instance belongs to
* @type {?Guild}
* @readonly
*/
get guild() {
return this.client.guilds.resolve(this.guildId);
}
/**
* Edits this stage instance.
* @param {StageInstanceEditOptions} options The options to edit the stage instance
* @returns {Promise<StageInstance>}
* @example
* // Edit a stage instance
* stageInstance.edit({ topic: 'new topic' })
* .then(stageInstance => console.log(stageInstance))
* .catch(console.error)
*/
edit(options) {
return this.guild.stageInstances.edit(this.channelId, options);
}
/**
* Deletes this stage instance.
* @returns {Promise<StageInstance>}
* @example
* // Delete a stage instance
* stageInstance.delete()
* .then(stageInstance => console.log(stageInstance))
* .catch(console.error);
*/
async delete() {
await this.guild.stageInstances.delete(this.channelId);
const clone = this._clone();
clone.deleted = true;
return clone;
}
/**
* Sets the topic of this stage instance.
* @param {string} topic The topic for the stage instance
* @returns {Promise<StageInstance>}
* @example
* // Set topic of a stage instance
* stageInstance.setTopic('new topic')
* .then(stageInstance => console.log(`Set the topic to: ${stageInstance.topic}`))
* .catch(console.error);
*/
setTopic(topic) {
return this.guild.stageInstances.edit(this.channelId, { topic });
}
/**
* The timestamp this stage instances was created at
* @type {number}
* @readonly
*/
get createdTimestamp() {
return SnowflakeUtil.deconstruct(this.id).timestamp;
}
/**
* The time this stage instance was created at
* @type {Date}
* @readonly
*/
get createdAt() {
return new Date(this.createdTimestamp);
}
}
module.exports = StageInstance;