-
Notifications
You must be signed in to change notification settings - Fork 417
/
Channel.js
69 lines (62 loc) · 1.97 KB
/
Channel.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
"use strict";
const Base = require("./Base");
/**
* Represents a channel. You also probably want to look at CategoryChannel, GroupChannel, NewsChannel, PrivateChannel, TextChannel, 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
* @prop {Number} createdAt Timestamp of the channel's creation
*/
class Channel extends Base {
constructor(data) {
super(data.id);
this.type = data.type;
}
get mention() {
return `<#${this.id}>`;
}
static from(data, client) {
switch(data.type) {
case 0: {
return new TextChannel(data, client);
}
case 1: {
return new PrivateChannel(data, client);
}
case 2: {
return new VoiceChannel(data, client);
}
case 3: {
return new GroupChannel(data, client);
}
case 4: {
return new CategoryChannel(data, client);
}
case 5: {
return new NewsChannel(data, client);
}
case 6: {
return new StoreChannel(data, client);
}
}
return new Channel(data);
}
toJSON() {
const base = super.toJSON(true);
for(const prop of ["type"]) {
if(this[prop] !== undefined) {
base[prop] = this[prop] && this[prop].toJSON ? this[prop].toJSON() : this[prop];
}
}
return base;
}
}
module.exports = Channel;
// Circular import
const CategoryChannel = require("./CategoryChannel");
const GroupChannel = require("./GroupChannel");
const NewsChannel = require("./NewsChannel");
const PrivateChannel = require("./PrivateChannel");
const StoreChannel = require("./StoreChannel");
const TextChannel = require("./TextChannel");
const VoiceChannel = require("./VoiceChannel");