@zygout/eris 0.0.0-stage → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +80 -3
- package/esm.mjs +72 -0
- package/index.d.ts +4397 -0
- package/index.js +75 -0
- package/lib/Client.js +4683 -0
- package/lib/Constants.d.ts +988 -0
- package/lib/Constants.js +1161 -0
- package/lib/command/Command.js +552 -0
- package/lib/command/CommandClient.js +460 -0
- package/lib/errors/DiscordHTTPError.js +63 -0
- package/lib/errors/DiscordRESTError.js +77 -0
- package/lib/gateway/Shard.js +3029 -0
- package/lib/gateway/ShardManager.js +164 -0
- package/lib/rest/Endpoints.js +172 -0
- package/lib/rest/RequestHandler.js +459 -0
- package/lib/structures/ApplicationCommand.js +125 -0
- package/lib/structures/AutoModerationRule.js +143 -0
- package/lib/structures/AutocompleteInteraction.js +80 -0
- package/lib/structures/Base.js +81 -0
- package/lib/structures/CategoryChannel.js +77 -0
- package/lib/structures/Channel.js +98 -0
- package/lib/structures/CommandInteraction.js +473 -0
- package/lib/structures/ComponentInteraction.js +538 -0
- package/lib/structures/DMChannel.js +278 -0
- package/lib/structures/Entitlement.js +77 -0
- package/lib/structures/ExtendedUser.js +46 -0
- package/lib/structures/ForumChannel.js +24 -0
- package/lib/structures/GroupChannel.js +106 -0
- package/lib/structures/Guild.js +1677 -0
- package/lib/structures/GuildAuditLogEntry.js +190 -0
- package/lib/structures/GuildChannel.js +128 -0
- package/lib/structures/GuildIntegration.js +99 -0
- package/lib/structures/GuildPreview.js +97 -0
- package/lib/structures/GuildScheduledEvent.js +176 -0
- package/lib/structures/GuildTemplate.js +76 -0
- package/lib/structures/GuildTextableChannel.js +260 -0
- package/lib/structures/Interaction.js +133 -0
- package/lib/structures/Invite.js +143 -0
- package/lib/structures/Lobby.js +108 -0
- package/lib/structures/LobbyMember.js +59 -0
- package/lib/structures/MediaChannel.js +216 -0
- package/lib/structures/Member.js +371 -0
- package/lib/structures/Message.js +708 -0
- package/lib/structures/ModalSubmitInteraction.js +478 -0
- package/lib/structures/NewsChannel.js +34 -0
- package/lib/structures/NewsThreadChannel.js +12 -0
- package/lib/structures/Permission.js +80 -0
- package/lib/structures/PermissionOverwrite.js +32 -0
- package/lib/structures/PingInteraction.js +39 -0
- package/lib/structures/PrivateThreadChannel.js +25 -0
- package/lib/structures/PublicThreadChannel.js +26 -0
- package/lib/structures/Role.js +163 -0
- package/lib/structures/SKU.js +80 -0
- package/lib/structures/SoundboardSound.js +79 -0
- package/lib/structures/StageChannel.js +59 -0
- package/lib/structures/StageInstance.js +55 -0
- package/lib/structures/Subscription.js +69 -0
- package/lib/structures/TextChannel.js +202 -0
- package/lib/structures/ThreadChannel.js +143 -0
- package/lib/structures/ThreadMember.js +59 -0
- package/lib/structures/UnavailableGuild.js +26 -0
- package/lib/structures/UnknownInteraction.js +502 -0
- package/lib/structures/User.js +296 -0
- package/lib/structures/VoiceChannel.js +166 -0
- package/lib/structures/VoiceState.js +84 -0
- package/lib/util/BrowserWebSocket.js +76 -0
- package/lib/util/Bucket.js +89 -0
- package/lib/util/Collection.js +202 -0
- package/lib/util/MultipartData.js +70 -0
- package/lib/util/Opus.js +33 -0
- package/lib/util/SequentialBucket.js +83 -0
- package/lib/util/emitDeprecation.js +26 -0
- package/lib/voice/Piper.js +300 -0
- package/lib/voice/SharedStream.js +238 -0
- package/lib/voice/VoiceConnection.js +1440 -0
- package/lib/voice/VoiceConnectionManager.js +151 -0
- package/lib/voice/VoiceDataStream.js +22 -0
- package/lib/voice/streams/BaseTransformer.js +40 -0
- package/lib/voice/streams/DCAOpusTransformer.js +78 -0
- package/lib/voice/streams/FFmpegDuplex.js +192 -0
- package/lib/voice/streams/FFmpegOggTransformer.js +35 -0
- package/lib/voice/streams/FFmpegPCMTransformer.js +26 -0
- package/lib/voice/streams/OggOpusTransformer.js +108 -0
- package/lib/voice/streams/PCMOpusTransformer.js +61 -0
- package/lib/voice/streams/VolumeTransformer.js +50 -0
- package/lib/voice/streams/WebmOpusTransformer.js +258 -0
- package/package.json +82 -6
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Base = require("./Base");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Auto Moderation Rule
|
|
7
|
+
* @prop {Array<Object>} actions The actions that will be executed if the rule is triggered
|
|
8
|
+
* @prop {Object?} actions[].metadata Additional data used when an action is executed
|
|
9
|
+
* @prop {String?} actions[].metadata.channelID The channel where user content will be logged (action type 2 only)
|
|
10
|
+
* @prop {String?} actions[].metadata.customMessage Optional custom message up to 150 characters that will be shown to users when their message gets blocked (action type 1 only)
|
|
11
|
+
* @prop {Number?} actions[].metadata.durationSeconds Timeout duration in seconds, up to 4 weeks (action type 3 only)
|
|
12
|
+
* @prop {User} creator The user that created the Auto Moderation rule. If the user is uncached, this will be an object with an id key. No other properties are guaranteed
|
|
13
|
+
* @prop {Boolean} enabled Whether the rule is enabled or not
|
|
14
|
+
* @prop {Number} eventType Whether this rule applies for message sends (1) or member updates (2)
|
|
15
|
+
* @prop {Array<String>} exemptChannels A list of channel IDs that aren't affected by this rule
|
|
16
|
+
* @prop {Array<String>} exemptRoles A list of role IDs that aren't affected by this rule
|
|
17
|
+
* @prop {Guild} guild The guild which this rule applies to. If the guild is uncached, this will be an object with an id key. No other properties are guaranteed
|
|
18
|
+
* @prop {String} id The Auto Moderation Rule ID
|
|
19
|
+
* @prop {String} name The name of this rule
|
|
20
|
+
* @prop {Object} triggerMetadata Additional data used to determine whether a rule is triggered or not
|
|
21
|
+
* @prop {Array<String>?} triggerMetadata.allowList Substrings which shouldn't trigger this rule (trigger types 1, 4 and 6 only). Max of 100 for types 1 and 6, max of 1000 for type 4
|
|
22
|
+
* @prop {Array<String>?} triggerMetadata.keywordFilter Substrings which should trigger this rule (trigger types 1 and 6 only). Max of 1000
|
|
23
|
+
* @prop {Boolean?} triggerMetadata.mentionRaidProtectionEnabled Whether to automatically detect mention raids
|
|
24
|
+
* @prop {Number?} triggerMetadata.mentionTotalLimit The number of unique roles/user mentions allowed per message. Max of 50
|
|
25
|
+
* @prop {Array<Number>?} triggerMetadata.presets The predefined wordsets which should trigger this rule. 1 for profanity, 2 for sexual content, 3 for slurs
|
|
26
|
+
* @prop {Array<String>?} triggerMetadata.regexPatterns Rust flavored Regex patterns which should trigger this rule. Max of 10
|
|
27
|
+
* @prop {Number} triggerType The type of content which triggers this rule
|
|
28
|
+
*/
|
|
29
|
+
class AutoModerationRule extends Base {
|
|
30
|
+
constructor(data, client) {
|
|
31
|
+
super(data.id);
|
|
32
|
+
this._client = client;
|
|
33
|
+
this.guild = client.guilds.get(data.guild_id) || { id: data.guild_id };
|
|
34
|
+
this.creator = client.users.get(data.creator_id) || { id: data.creator_id };
|
|
35
|
+
this.triggerType = data.trigger_type;
|
|
36
|
+
|
|
37
|
+
this.update(data);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
update(data) {
|
|
41
|
+
if (data.name !== undefined) {
|
|
42
|
+
this.name = data.name;
|
|
43
|
+
}
|
|
44
|
+
if (data.event_type !== undefined) {
|
|
45
|
+
this.eventType = data.event_type;
|
|
46
|
+
}
|
|
47
|
+
if (data.trigger_metadata !== undefined) {
|
|
48
|
+
if (data.trigger_metadata.keyword_filter !== undefined) {
|
|
49
|
+
data.trigger_metadata.keywordFilter = data.trigger_metadata.keyword_filter;
|
|
50
|
+
delete data.trigger_metadata.keyword_filter;
|
|
51
|
+
}
|
|
52
|
+
if (data.trigger_metadata.regex_patterns !== undefined) {
|
|
53
|
+
data.trigger_metadata.regexPatterns = data.trigger_metadata.regex_patterns;
|
|
54
|
+
delete data.trigger_metadata.regex_patterns;
|
|
55
|
+
}
|
|
56
|
+
if (data.trigger_metadata.allow_list !== undefined) {
|
|
57
|
+
data.trigger_metadata.allowList = data.trigger_metadata.allow_list;
|
|
58
|
+
delete data.trigger_metadata.allow_list;
|
|
59
|
+
}
|
|
60
|
+
if (data.trigger_metadata.mention_total_limit !== undefined) {
|
|
61
|
+
data.trigger_metadata.mentionTotalLimit = data.trigger_metadata.mention_total_limit;
|
|
62
|
+
delete data.trigger_metadata.mention_total_limit;
|
|
63
|
+
}
|
|
64
|
+
if (data.trigger_metadata.mention_raid_protection_enabled !== undefined) {
|
|
65
|
+
data.trigger_metadata.mentionRaidProtectionEnabled = data.trigger_metadata.mention_raid_protection_enabled;
|
|
66
|
+
delete data.trigger_metadata.mention_raid_protection_enabled;
|
|
67
|
+
}
|
|
68
|
+
this.triggerMetadata = data.trigger_metadata;
|
|
69
|
+
}
|
|
70
|
+
if (data.actions !== undefined) {
|
|
71
|
+
this.actions = data.actions.map((action) => {
|
|
72
|
+
if (action.metadata) {
|
|
73
|
+
if (action.metadata.channel_id !== undefined) {
|
|
74
|
+
action.metadata.channelID = action.metadata.channel_id;
|
|
75
|
+
delete action.metadata.channel_id;
|
|
76
|
+
}
|
|
77
|
+
if (action.metadata.duration_seconds !== undefined) {
|
|
78
|
+
action.metadata.durationSeconds = action.metadata.duration_seconds;
|
|
79
|
+
delete action.metadata.duration_seconds;
|
|
80
|
+
}
|
|
81
|
+
if (action.metadata.custom_message !== undefined) {
|
|
82
|
+
action.metadata.customMessage = action.metadata.custom_message;
|
|
83
|
+
delete action.metadata.custom_message;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return action;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (data.enabled !== undefined) {
|
|
90
|
+
this.enabled = data.enabled;
|
|
91
|
+
}
|
|
92
|
+
if (data.exempt_roles !== undefined) {
|
|
93
|
+
this.exemptRoles = data.exempt_roles;
|
|
94
|
+
}
|
|
95
|
+
if (data.exempt_channels !== undefined) {
|
|
96
|
+
this.exemptChannels = data.exempt_channels;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Delete the auto moderation rule
|
|
102
|
+
* @arg {String} [reason] The reason to be displayed in audit logs
|
|
103
|
+
* @returns {Promise}
|
|
104
|
+
*/
|
|
105
|
+
delete(reason) {
|
|
106
|
+
return this._client.deleteAutoModerationRule.call(this._client, this.guild.id, this.id, reason);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Edit an existing auto moderation rule
|
|
111
|
+
* @arg {Object} options The properties to edit
|
|
112
|
+
* @arg {Array<Object>} [options.actions] The [actions](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object) done when the rule is violated
|
|
113
|
+
* @arg {Boolean} [options.enabled=false] If the rule is enabled, false by default
|
|
114
|
+
* @arg {Number} [options.eventType] The [event type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types) for the rule
|
|
115
|
+
* @arg {Array<String>} [options.exemptChannels] Any channels where this rule does not apply
|
|
116
|
+
* @arg {Array<String>} [options.exemptRoles] Any roles to which this rule does not apply
|
|
117
|
+
* @arg {String} [options.name] The name of the rule
|
|
118
|
+
* @arg {Object} [options.triggerMetadata] The [trigger metadata](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) for the rule
|
|
119
|
+
* @arg {Number} [options.triggerType] The [trigger type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types) of the rule
|
|
120
|
+
* @arg {String} [options.reason] The reason to be displayed in audit logs
|
|
121
|
+
* @returns {Promise<AutoModerationRule>}
|
|
122
|
+
*/
|
|
123
|
+
edit(options) {
|
|
124
|
+
return this._client.editAutoModerationRule.call(this._client, this.guild.id, this.id, options);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
toJSON(props = []) {
|
|
128
|
+
return super.toJSON([
|
|
129
|
+
"actions",
|
|
130
|
+
"creator",
|
|
131
|
+
"enabled",
|
|
132
|
+
"eventType",
|
|
133
|
+
"exemptChannels",
|
|
134
|
+
"exemptRoles",
|
|
135
|
+
"name",
|
|
136
|
+
"triggerMetadata",
|
|
137
|
+
"triggerType",
|
|
138
|
+
...props,
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = AutoModerationRule;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Interaction = require("./Interaction");
|
|
4
|
+
const { InteractionResponseTypes } = require("../Constants");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents an application command autocomplete interaction. See Interaction for more properties.
|
|
8
|
+
* @extends Interaction
|
|
9
|
+
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
|
|
10
|
+
* @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
|
|
11
|
+
* @prop {Object} data The data attached to the interaction
|
|
12
|
+
* @prop {String} data.id The ID of the Application Command
|
|
13
|
+
* @prop {String} data.name The command name
|
|
14
|
+
* @prop {Array<Object>?} data.options The run Application Command options
|
|
15
|
+
* @prop {Boolean?} data.options[].focused Whether or not the option is focused
|
|
16
|
+
* @prop {String} data.options[].name The name of the Application Command option
|
|
17
|
+
* @prop {Array<Object>?} data.options[].options The run Application Command options (Mutually exclusive with value)
|
|
18
|
+
* @prop {Number} data.options[].type Command option type, 1-10
|
|
19
|
+
* @prop {(String | Number | Boolean)?} data.options[].value The value of the run Application Command (Mutually exclusive with options)
|
|
20
|
+
* @prop {String?} data.target_id The ID the of user or message targetted by a context menu command
|
|
21
|
+
* @prop {Number} data.type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
|
|
22
|
+
* @prop {String?} guildID The ID of the guild in which the interaction was created
|
|
23
|
+
* @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
|
|
24
|
+
* @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
|
|
25
|
+
*/
|
|
26
|
+
class AutocompleteInteraction extends Interaction {
|
|
27
|
+
constructor(data, client) {
|
|
28
|
+
super(data, client);
|
|
29
|
+
|
|
30
|
+
this.channel = this._client.getChannel(data.channel_id) || {
|
|
31
|
+
id: data.channel_id,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.data = data.data;
|
|
35
|
+
|
|
36
|
+
if (data.guild_id !== undefined) {
|
|
37
|
+
this.guildID = data.guild_id;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (data.member !== undefined) {
|
|
41
|
+
this.member = this._resolveMember(data.member, data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (data.user !== undefined) {
|
|
45
|
+
this.user = this._client.users.update(data.user, client);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Acknowledges the autocomplete interaction with a result of choices
|
|
51
|
+
* Note: You can **not** use more than 1 initial interaction response per interaction
|
|
52
|
+
* @arg {Array<Object>} choices The autocomplete choices to return to the user
|
|
53
|
+
* @arg {String | Number} choices[].name The choice display name
|
|
54
|
+
* @arg {String} choices[].value The choice value to return to the bot
|
|
55
|
+
* @returns {Promise}
|
|
56
|
+
*/
|
|
57
|
+
async acknowledge(choices) {
|
|
58
|
+
return this.result(choices);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Acknowledges the autocomplete interaction with a result of choices
|
|
63
|
+
* Note: You can **not** use more than 1 initial interaction response per interaction.
|
|
64
|
+
* @arg {Array<Object>} choices The autocomplete choices to return to the user
|
|
65
|
+
* @arg {String | Number} choices[].name The choice display name
|
|
66
|
+
* @arg {String} choices[].value The choice value to return to the bot
|
|
67
|
+
* @returns {Promise}
|
|
68
|
+
*/
|
|
69
|
+
async result(choices) {
|
|
70
|
+
if (this.acknowledged === true) {
|
|
71
|
+
throw new Error("You have already acknowledged this interaction.");
|
|
72
|
+
}
|
|
73
|
+
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
|
|
74
|
+
type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT,
|
|
75
|
+
data: { choices },
|
|
76
|
+
}).then(() => this.update());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = AutocompleteInteraction;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const util = require("util");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides utilities for working with many Discord structures
|
|
7
|
+
* @prop {String} id A Discord snowflake identifying the object
|
|
8
|
+
* @prop {Number} createdAt Timestamp of structure creation
|
|
9
|
+
*/
|
|
10
|
+
class Base {
|
|
11
|
+
constructor(id) {
|
|
12
|
+
if (id) {
|
|
13
|
+
this.id = id;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get createdAt() {
|
|
18
|
+
return Base.getCreatedAt(this.id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Calculates the timestamp in milliseconds associated with a Discord ID/snowflake
|
|
23
|
+
* @arg {String} id The ID of a structure
|
|
24
|
+
* @returns {Number}
|
|
25
|
+
*/
|
|
26
|
+
static getCreatedAt(id) {
|
|
27
|
+
return Base.getDiscordEpoch(id) + 1420070400000;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the number of milliseconds since epoch represented by an ID/snowflake
|
|
32
|
+
* @arg {String} id The ID of a structure
|
|
33
|
+
* @returns {Number}
|
|
34
|
+
*/
|
|
35
|
+
static getDiscordEpoch(id) {
|
|
36
|
+
return Math.floor(id / 4194304);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[util.inspect.custom]() {
|
|
40
|
+
// http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript
|
|
41
|
+
const copy = new { [this.constructor.name]: class {} }[this.constructor.name]();
|
|
42
|
+
for (const key in this) {
|
|
43
|
+
if (this.hasOwnProperty(key) && !key.startsWith("_") && this[key] !== undefined) {
|
|
44
|
+
copy[key] = this[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return copy;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toString() {
|
|
51
|
+
return `[${this.constructor.name} ${this.id}]`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
toJSON(props = []) {
|
|
55
|
+
const json = {};
|
|
56
|
+
if (this.id) {
|
|
57
|
+
json.id = this.id;
|
|
58
|
+
json.createdAt = this.createdAt;
|
|
59
|
+
}
|
|
60
|
+
for (const prop of props) {
|
|
61
|
+
const value = this[prop];
|
|
62
|
+
const type = typeof value;
|
|
63
|
+
if (value === undefined) {
|
|
64
|
+
continue;
|
|
65
|
+
} else if ((type !== "object" && type !== "function" && type !== "bigint") || value === null) {
|
|
66
|
+
json[prop] = value;
|
|
67
|
+
} else if (value.toJSON !== undefined) {
|
|
68
|
+
json[prop] = value.toJSON();
|
|
69
|
+
} else if (value.values !== undefined) {
|
|
70
|
+
json[prop] = [...value.values()];
|
|
71
|
+
} else if (type === "bigint") {
|
|
72
|
+
json[prop] = value.toString();
|
|
73
|
+
} else if (type === "object") {
|
|
74
|
+
json[prop] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return json;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = Base;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Collection = require("../util/Collection");
|
|
4
|
+
const GuildChannel = require("./GuildChannel");
|
|
5
|
+
const PermissionOverwrite = require("./PermissionOverwrite");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents a guild category channel. See GuildChannel for more properties and methods
|
|
9
|
+
* @extends GuildChannel
|
|
10
|
+
* @prop {Collection<GuildChannel>} channels A collection of guild channels that are part of this category
|
|
11
|
+
* @prop {Collection<PermissionOverwrite>} permissionOverwrites Collection of permission overwrites in the channel
|
|
12
|
+
* @prop {Number} position The position of the channel
|
|
13
|
+
*/
|
|
14
|
+
class CategoryChannel extends GuildChannel {
|
|
15
|
+
constructor(data, client) {
|
|
16
|
+
super(data, client);
|
|
17
|
+
this.update(data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
update(data) {
|
|
21
|
+
super.update(data);
|
|
22
|
+
if (data.position !== undefined) {
|
|
23
|
+
this.position = data.position;
|
|
24
|
+
}
|
|
25
|
+
if (data.permission_overwrites !== undefined) {
|
|
26
|
+
this.permissionOverwrites = new Collection(PermissionOverwrite);
|
|
27
|
+
data.permission_overwrites.forEach((overwrite) => {
|
|
28
|
+
this.permissionOverwrites.add(overwrite);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get channels() {
|
|
34
|
+
const channels = new Collection(GuildChannel);
|
|
35
|
+
if (this.guild && this.guild.channels) {
|
|
36
|
+
for (const channel of this.guild.channels.values()) {
|
|
37
|
+
if (channel.parentID === this.id) {
|
|
38
|
+
channels.add(channel);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return channels;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Delete a channel permission overwrite
|
|
47
|
+
* @arg {String} overwriteID The ID of the overwritten user or role
|
|
48
|
+
* @arg {String} [reason] The reason to be displayed in audit logs
|
|
49
|
+
* @returns {Promise}
|
|
50
|
+
*/
|
|
51
|
+
deletePermission(overwriteID, reason) {
|
|
52
|
+
return this._client.deleteChannelPermission.call(this._client, this.id, overwriteID, reason);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Edit a channel permission overwrite
|
|
57
|
+
* @arg {String} overwriteID The ID of the overwritten user or role
|
|
58
|
+
* @arg {BigInt | Number | String} allow The permissions number for allowed permissions
|
|
59
|
+
* @arg {BigInt | Number | String} deny The permissions number for denied permissions
|
|
60
|
+
* @arg {Number} type The object type of the overwrite, either 1 for "member" or 0 for "role"
|
|
61
|
+
* @arg {String} [reason] The reason to be displayed in audit logs
|
|
62
|
+
* @returns {Promise<PermissionOverwrite>}
|
|
63
|
+
*/
|
|
64
|
+
editPermission(overwriteID, allow, deny, type, reason) {
|
|
65
|
+
return this._client.editChannelPermission.call(this._client, this.id, overwriteID, allow, deny, type, reason);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
toJSON(props = []) {
|
|
69
|
+
return super.toJSON([
|
|
70
|
+
"permissionOverwrites",
|
|
71
|
+
"position",
|
|
72
|
+
...props,
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = CategoryChannel;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Base = require("./Base");
|
|
4
|
+
const { ChannelTypes } = require("../Constants");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a channel. You also probably want to look at CategoryChannel, GroupChannel, NewsChannel, DMChannel, TextChannel, and VoiceChannel.
|
|
8
|
+
* @prop {Number} createdAt Timestamp of the channel's creation
|
|
9
|
+
* @prop {String} id The ID of the channel
|
|
10
|
+
* @prop {String} mention A string that mentions the channel
|
|
11
|
+
* @prop {Number} type The type of the channel
|
|
12
|
+
*/
|
|
13
|
+
class Channel extends Base {
|
|
14
|
+
constructor(data, client) {
|
|
15
|
+
super(data.id);
|
|
16
|
+
this.type = data.type;
|
|
17
|
+
this._client = client;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get mention() {
|
|
21
|
+
return `<#${this.id}>`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static from(data, client) {
|
|
25
|
+
switch (data.type) {
|
|
26
|
+
case ChannelTypes.GUILD_TEXT: {
|
|
27
|
+
return new TextChannel(data, client);
|
|
28
|
+
}
|
|
29
|
+
case ChannelTypes.DM: {
|
|
30
|
+
return new DMChannel(data, client);
|
|
31
|
+
}
|
|
32
|
+
case ChannelTypes.GUILD_VOICE: {
|
|
33
|
+
return new VoiceChannel(data, client);
|
|
34
|
+
}
|
|
35
|
+
case ChannelTypes.GROUP_DM: {
|
|
36
|
+
return new GroupChannel(data, client);
|
|
37
|
+
}
|
|
38
|
+
case ChannelTypes.GUILD_CATEGORY: {
|
|
39
|
+
return new CategoryChannel(data, client);
|
|
40
|
+
}
|
|
41
|
+
case ChannelTypes.GUILD_NEWS: {
|
|
42
|
+
return new NewsChannel(data, client);
|
|
43
|
+
}
|
|
44
|
+
case ChannelTypes.GUILD_NEWS_THREAD: {
|
|
45
|
+
return new NewsThreadChannel(data, client);
|
|
46
|
+
}
|
|
47
|
+
case ChannelTypes.GUILD_PUBLIC_THREAD: {
|
|
48
|
+
return new PublicThreadChannel(data, client);
|
|
49
|
+
}
|
|
50
|
+
case ChannelTypes.GUILD_PRIVATE_THREAD: {
|
|
51
|
+
return new PrivateThreadChannel(data, client);
|
|
52
|
+
}
|
|
53
|
+
case ChannelTypes.GUILD_STAGE_VOICE: {
|
|
54
|
+
return new StageChannel(data, client);
|
|
55
|
+
}
|
|
56
|
+
case ChannelTypes.GUILD_FORUM: {
|
|
57
|
+
return new ForumChannel(data, client);
|
|
58
|
+
}
|
|
59
|
+
case ChannelTypes.GUILD_MEDIA: {
|
|
60
|
+
return new MediaChannel(data, client);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (data.guild_id) {
|
|
64
|
+
if (data.last_message_id !== undefined) {
|
|
65
|
+
client.emit("warn", new Error(`Unknown guild text channel type: ${data.type}\n${JSON.stringify(data)}`));
|
|
66
|
+
return new TextChannel(data, client);
|
|
67
|
+
}
|
|
68
|
+
client.emit("warn", new Error(`Unknown guild channel type: ${data.type}\n${JSON.stringify(data)}`));
|
|
69
|
+
return new GuildChannel(data, client);
|
|
70
|
+
}
|
|
71
|
+
client.emit("warn", new Error(`Unknown channel type: ${data.type}\n${JSON.stringify(data)}`));
|
|
72
|
+
return new Channel(data, client);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
toJSON(props = []) {
|
|
76
|
+
return super.toJSON([
|
|
77
|
+
"type",
|
|
78
|
+
...props,
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = Channel;
|
|
84
|
+
|
|
85
|
+
// Circular import
|
|
86
|
+
const CategoryChannel = require("./CategoryChannel");
|
|
87
|
+
const DMChannel = require("./DMChannel");
|
|
88
|
+
const GuildChannel = require("./GuildChannel");
|
|
89
|
+
const ForumChannel = require("./ForumChannel");
|
|
90
|
+
const GroupChannel = require("./GroupChannel");
|
|
91
|
+
const MediaChannel = require("./MediaChannel");
|
|
92
|
+
const NewsChannel = require("./NewsChannel");
|
|
93
|
+
const NewsThreadChannel = require("./NewsThreadChannel");
|
|
94
|
+
const PrivateThreadChannel = require("./PrivateThreadChannel");
|
|
95
|
+
const PublicThreadChannel = require("./PublicThreadChannel");
|
|
96
|
+
const StageChannel = require("./StageChannel");
|
|
97
|
+
const TextChannel = require("./TextChannel");
|
|
98
|
+
const VoiceChannel = require("./VoiceChannel");
|