@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.
Files changed (88) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +80 -3
  3. package/esm.mjs +72 -0
  4. package/index.d.ts +4397 -0
  5. package/index.js +75 -0
  6. package/lib/Client.js +4683 -0
  7. package/lib/Constants.d.ts +988 -0
  8. package/lib/Constants.js +1161 -0
  9. package/lib/command/Command.js +552 -0
  10. package/lib/command/CommandClient.js +460 -0
  11. package/lib/errors/DiscordHTTPError.js +63 -0
  12. package/lib/errors/DiscordRESTError.js +77 -0
  13. package/lib/gateway/Shard.js +3029 -0
  14. package/lib/gateway/ShardManager.js +164 -0
  15. package/lib/rest/Endpoints.js +172 -0
  16. package/lib/rest/RequestHandler.js +459 -0
  17. package/lib/structures/ApplicationCommand.js +125 -0
  18. package/lib/structures/AutoModerationRule.js +143 -0
  19. package/lib/structures/AutocompleteInteraction.js +80 -0
  20. package/lib/structures/Base.js +81 -0
  21. package/lib/structures/CategoryChannel.js +77 -0
  22. package/lib/structures/Channel.js +98 -0
  23. package/lib/structures/CommandInteraction.js +473 -0
  24. package/lib/structures/ComponentInteraction.js +538 -0
  25. package/lib/structures/DMChannel.js +278 -0
  26. package/lib/structures/Entitlement.js +77 -0
  27. package/lib/structures/ExtendedUser.js +46 -0
  28. package/lib/structures/ForumChannel.js +24 -0
  29. package/lib/structures/GroupChannel.js +106 -0
  30. package/lib/structures/Guild.js +1677 -0
  31. package/lib/structures/GuildAuditLogEntry.js +190 -0
  32. package/lib/structures/GuildChannel.js +128 -0
  33. package/lib/structures/GuildIntegration.js +99 -0
  34. package/lib/structures/GuildPreview.js +97 -0
  35. package/lib/structures/GuildScheduledEvent.js +176 -0
  36. package/lib/structures/GuildTemplate.js +76 -0
  37. package/lib/structures/GuildTextableChannel.js +260 -0
  38. package/lib/structures/Interaction.js +133 -0
  39. package/lib/structures/Invite.js +143 -0
  40. package/lib/structures/Lobby.js +108 -0
  41. package/lib/structures/LobbyMember.js +59 -0
  42. package/lib/structures/MediaChannel.js +216 -0
  43. package/lib/structures/Member.js +371 -0
  44. package/lib/structures/Message.js +708 -0
  45. package/lib/structures/ModalSubmitInteraction.js +478 -0
  46. package/lib/structures/NewsChannel.js +34 -0
  47. package/lib/structures/NewsThreadChannel.js +12 -0
  48. package/lib/structures/Permission.js +80 -0
  49. package/lib/structures/PermissionOverwrite.js +32 -0
  50. package/lib/structures/PingInteraction.js +39 -0
  51. package/lib/structures/PrivateThreadChannel.js +25 -0
  52. package/lib/structures/PublicThreadChannel.js +26 -0
  53. package/lib/structures/Role.js +163 -0
  54. package/lib/structures/SKU.js +80 -0
  55. package/lib/structures/SoundboardSound.js +79 -0
  56. package/lib/structures/StageChannel.js +59 -0
  57. package/lib/structures/StageInstance.js +55 -0
  58. package/lib/structures/Subscription.js +69 -0
  59. package/lib/structures/TextChannel.js +202 -0
  60. package/lib/structures/ThreadChannel.js +143 -0
  61. package/lib/structures/ThreadMember.js +59 -0
  62. package/lib/structures/UnavailableGuild.js +26 -0
  63. package/lib/structures/UnknownInteraction.js +502 -0
  64. package/lib/structures/User.js +296 -0
  65. package/lib/structures/VoiceChannel.js +166 -0
  66. package/lib/structures/VoiceState.js +84 -0
  67. package/lib/util/BrowserWebSocket.js +76 -0
  68. package/lib/util/Bucket.js +89 -0
  69. package/lib/util/Collection.js +202 -0
  70. package/lib/util/MultipartData.js +70 -0
  71. package/lib/util/Opus.js +33 -0
  72. package/lib/util/SequentialBucket.js +83 -0
  73. package/lib/util/emitDeprecation.js +26 -0
  74. package/lib/voice/Piper.js +300 -0
  75. package/lib/voice/SharedStream.js +238 -0
  76. package/lib/voice/VoiceConnection.js +1440 -0
  77. package/lib/voice/VoiceConnectionManager.js +151 -0
  78. package/lib/voice/VoiceDataStream.js +22 -0
  79. package/lib/voice/streams/BaseTransformer.js +40 -0
  80. package/lib/voice/streams/DCAOpusTransformer.js +78 -0
  81. package/lib/voice/streams/FFmpegDuplex.js +192 -0
  82. package/lib/voice/streams/FFmpegOggTransformer.js +35 -0
  83. package/lib/voice/streams/FFmpegPCMTransformer.js +26 -0
  84. package/lib/voice/streams/OggOpusTransformer.js +108 -0
  85. package/lib/voice/streams/PCMOpusTransformer.js +61 -0
  86. package/lib/voice/streams/VolumeTransformer.js +50 -0
  87. package/lib/voice/streams/WebmOpusTransformer.js +258 -0
  88. package/package.json +82 -6
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Endpoints = require("../rest/Endpoints");
5
+
6
+ /**
7
+ * Represents a guild scheduled event
8
+ * @prop {(VoiceChannel | StageChannel | Object)?} channel The channel where the event will be held. This will be null if the event is external (`entityType` is `3`). Can be partial with only `id` if the channel or guild is not cached
9
+ * @prop {User?} creator The user that created the scheduled event. For events created before October 25 2021, this will be null. Please see the relevant Discord documentation for more details
10
+ * @prop {String?} description The description of the event
11
+ * @prop {String?} entityID The entity ID associated to the event
12
+ * @prop {Object?} entityMetadata Metadata for the event. This will be null if the event is not external (`entityType` is not `3`)
13
+ * @prop {String?} entityMetadata.location Location of the event
14
+ * @prop {Number} entityType The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
15
+ * @prop {Guild | Object} guild The guild which the event belongs to. Can be partial with only `id` if not cached
16
+ * @prop {String} id The ID of the guild event
17
+ * @prop {String?} image The hash of the event's image, or null if no image
18
+ * @prop {String?} imageURL The URL of the event's image, or null if no image
19
+ * @prop {String} name The name of the event
20
+ * @prop {Number} privacyLevel Event privacy level
21
+ * @prop {Object?} recurrenceRule The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Note: properties have been camelCased, and ISO8601 timestamps are represented by epoch number.
22
+ * @prop {Number} scheduledStartTime The time the event will start
23
+ * @prop {Number?} scheduledEndTime The time the event will end, or null if the event does not have a scheduled time to end
24
+ * @prop {Number} status The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
25
+ * @prop {Number?} userCount The number of users subscribed to the event
26
+ */
27
+ class GuildScheduledEvent extends Base {
28
+ constructor(data, client) {
29
+ super(data.id);
30
+
31
+ this._client = client;
32
+ if (data.creator !== undefined) {
33
+ this.creator = client.users.update(data.creator, this.client);
34
+ } else {
35
+ this.creator = null;
36
+ }
37
+ this.guild = client.guilds.get(data.guild_id) || {
38
+ id: data.guild_id,
39
+ };
40
+ this.scheduledEndTime = null;
41
+ this.update(data);
42
+ }
43
+
44
+ update(data) {
45
+ if (data.channel_id !== undefined) {
46
+ if (data.channel_id !== null) {
47
+ if (this._client.guilds.get(data.guild_id)) {
48
+ this.channel = this._client.guilds.get(data.guild_id).channels.get(data.channel_id) || { id: data.channel_id };
49
+ } else {
50
+ this.channel = { id: data.channel_id };
51
+ }
52
+ } else {
53
+ this.channel = null;
54
+ }
55
+ }
56
+ if (data.name !== undefined) {
57
+ this.name = data.name;
58
+ }
59
+ if (data.description !== undefined) {
60
+ this.description = data.description;
61
+ }
62
+ if (data.scheduled_start_time !== undefined) {
63
+ this.scheduledStartTime = Date.parse(data.scheduled_start_time);
64
+ }
65
+ if (data.scheduled_end_time !== undefined) {
66
+ this.scheduledEndTime = Date.parse(data.scheduled_end_time);
67
+ }
68
+ if (data.privacy_level !== undefined) {
69
+ this.privacyLevel = data.privacy_level;
70
+ }
71
+ if (data.status !== undefined) {
72
+ this.status = data.status;
73
+ }
74
+ if (data.entity_type !== undefined) {
75
+ this.entityType = data.entity_type;
76
+ }
77
+ if (data.entity_id !== undefined) {
78
+ this.entityID = data.entity_id;
79
+ }
80
+ if (data.entity_metadata !== undefined) {
81
+ this.entityMetadata = data.entity_metadata;
82
+ }
83
+ if (data.user_count !== undefined) {
84
+ this.userCount = data.user_count;
85
+ }
86
+ if (data.image !== undefined) {
87
+ this.image = data.image;
88
+ }
89
+ if (data.recurrence_rule !== undefined) {
90
+ if (data.recurrence_rule === null) {
91
+ this.recurrenceRule = null;
92
+ } else {
93
+ this.recurrenceRule = {
94
+ byMonth: data.recurrence_rule.by_month,
95
+ byMonthDay: data.recurrence_rule.by_month_day,
96
+ byNWeekday: data.recurrence_rule.by_n_weekday,
97
+ byWeekday: data.recurrence_rule.by_weekday,
98
+ byYearDay: data.recurrence_rule.by_year_day,
99
+ count: data.recurrence_rule.count,
100
+ end: data.recurrence_rule.end && Date.parse(data.recurrence_rule.end),
101
+ frequency: data.recurrence_rule.frequency,
102
+ interval: data.recurrence_rule.interval,
103
+ start: Date.parse(data.recurrence_rule.start),
104
+ };
105
+ }
106
+ }
107
+ }
108
+
109
+ get imageURL() {
110
+ return this.image ? this._client._formatImage(Endpoints.GUILD_SCHEDULED_EVENT_COVER(this.id, this.image)) : null;
111
+ }
112
+
113
+ /**
114
+ * Delete this scheduled event
115
+ * @returns {Promise}
116
+ */
117
+ delete() {
118
+ return this._client.deleteGuildScheduledEvent.call(this._client, this.guildID, this.id);
119
+ }
120
+
121
+ /**
122
+ * Edit this scheduled event
123
+ * @arg {Object} event The new guild scheduled event object
124
+ * @arg {String} [event.channelID] The channel ID of the event. If updating `entityType` to `3` (external), this **must** be set to `null`
125
+ * @arg {String} [event.description] The description of the event
126
+ * @arg {Object} [event.entityMetadata] The entity metadata for the scheduled event. This is required if updating `entityType` to `3` (external)
127
+ * @arg {String} [event.entityMetadata.location] Location of the event. This is required if updating `entityType` to `3` (external)
128
+ * @arg {Number} [event.entityType] The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
129
+ * @arg {String} [event.image] Base 64 encoded image for the event
130
+ * @arg {String} [event.name] The name of the event
131
+ * @arg {String} [event.privacyLevel] The privacy level of the event
132
+ * @arg {Object?} [event.recurrenceRule] The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Properties can be camelCase (preferred) or snake_case
133
+ * @arg {Date} [event.scheduledEndTime] The time when the scheduled event is scheduled to end. This is required if updating `entityType` to `3` (external)
134
+ * @arg {Date} [event.scheduledStartTime] The time the event will start
135
+ * @arg {Number} [event.status] The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
136
+ * @arg {String} [reason] The reason to be displayed in audit logs
137
+ * @returns {Promise<GuildScheduledEvent>}
138
+ */
139
+ edit(event, reason) {
140
+ return this._client.editGuildScheduledEvent.call(this._client, this.guildID, this.id, event, reason);
141
+ }
142
+
143
+ /**
144
+ * Get a list of users subscribed to the guild scheduled event
145
+ * @arg {Object} [options] Options for the request
146
+ * @arg {String} [options.after] Get users after this user ID. If `options.before` is provided, this will be ignored. Fetching users in between `before` and `after` is not supported
147
+ * @arg {String} [options.before] Get users before this user ID
148
+ * @arg {Number} [options.limit=100] The number of users to get (max 100). Pagination will only work if one of `options.after` or `options.after` is also provided
149
+ * @arg {Boolean} [options.withMember] Include guild member data
150
+ * @returns {Promise<Array<{guildScheduledEventID: String, member?: Member, user: User}>>}
151
+ */
152
+ getUsers(options) {
153
+ return this._client.getGuildScheduledEventUsers.call(this._client, this.guild.id, this.id, options);
154
+ }
155
+
156
+ toJSON(props = []) {
157
+ return super.toJSON([
158
+ "channel",
159
+ "creator",
160
+ "description",
161
+ "entityID",
162
+ "entityMetadata",
163
+ "entityType",
164
+ "guild",
165
+ "name",
166
+ "privacyLevel",
167
+ "scheduledEndTime",
168
+ "scheduledStartTime",
169
+ "status",
170
+ "userCount",
171
+ ...props,
172
+ ]);
173
+ }
174
+ }
175
+
176
+ module.exports = GuildScheduledEvent;
@@ -0,0 +1,76 @@
1
+ const Base = require("./Base");
2
+ const Guild = require("./Guild");
3
+
4
+ /**
5
+ * Represents a guild template
6
+ * @prop {String} code The template code
7
+ * @prop {Number} createdAt Timestamp of template creation
8
+ * @prop {User} creator User that created the template
9
+ * @prop {String?} description The template description
10
+ * @prop {Boolean?} isDirty Whether the template has unsynced changes
11
+ * @prop {String} name The template name
12
+ * @prop {Guild} serializedSourceGuild The guild snapshot this template contains
13
+ * @prop {Guild | Object} sourceGuild The guild this template is based on. If the guild is not cached, this will be an object with `id` key. No other property is guaranteed
14
+ * @prop {Number} updatedAt Timestamp of template update
15
+ * @prop {Number} usageCount Number of times this template has been used
16
+ */
17
+ class GuildTemplate {
18
+ constructor(data, client) {
19
+ this._client = client;
20
+ this.code = data.code;
21
+ this.createdAt = Date.parse(data.created_at);
22
+ this.creator = client.users.update(data.creator, client);
23
+ this.description = data.description;
24
+ this.isDirty = data.is_dirty;
25
+ this.name = data.name;
26
+ this.serializedSourceGuild = new Guild(data.serialized_source_guild, client);
27
+ this.sourceGuild = client.guilds.get(data.source_guild_id) || { id: data.source_guild_id };
28
+ this.updatedAt = Date.parse(data.updated_at);
29
+ this.usageCount = data.usage_count;
30
+ }
31
+
32
+ /**
33
+ * Delete this template
34
+ * @returns {Promise<GuildTemplate>}
35
+ */
36
+ delete() {
37
+ return this._client.deleteGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
38
+ }
39
+
40
+ /**
41
+ * Edit this template
42
+ * @arg {Object} options The properties to edit
43
+ * @arg {String?} [options.description] The description for the template. Set to `null` to remove the description
44
+ * @arg {String} [options.name] The name of the template
45
+ * @returns {Promise<GuildTemplate>}
46
+ */
47
+ edit(options) {
48
+ return this._client.editGuildTemplate.call(this._client, this.sourceGuild.id, this.code, options);
49
+ }
50
+
51
+ /**
52
+ * Force this template to sync to the guild's current state
53
+ * @returns {Promise<GuildTemplate>}
54
+ */
55
+ sync() {
56
+ return this._client.syncGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
57
+ }
58
+
59
+ toJSON(props = []) {
60
+ return Base.prototype.toJSON.call(this, [
61
+ "code",
62
+ "createdAt",
63
+ "creator",
64
+ "description",
65
+ "isDirty",
66
+ "name",
67
+ "serializedSourceGuild",
68
+ "sourceGuild",
69
+ "updatedAt",
70
+ "usageCount",
71
+ ...props,
72
+ ]);
73
+ }
74
+ }
75
+
76
+ module.exports = GuildTemplate;
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+
3
+ const Collection = require("../util/Collection");
4
+ const GuildChannel = require("./GuildChannel");
5
+ const Message = require("./Message");
6
+
7
+ /**
8
+ * Represents a textable guild channel. You also probably want to look at NewsChannel, StageChannel, TextChannel, ThreadChannel, and VoiceChannel. See GuildChannel for more properties
9
+ * @prop {String?} lastMessageID The ID of the last message in the channel. This can be null if there has never been a message in the channel
10
+ * @prop {Collection<Message>} messages Collection of Messages in this channel
11
+ * @prop {Number} rateLimitPerUser The time in seconds a user has to wait before sending another message (0-21600) (does not affect bots or users with manageMessages/manageChannel permissions)
12
+ */
13
+ class GuildTextableChannel extends GuildChannel {
14
+ constructor(data, client, messageLimit) {
15
+ super(data, client);
16
+ this.messages = new Collection(Message, messageLimit == null ? client.options.messageLimit : messageLimit);
17
+ this.lastMessageID = data.last_message_id || null;
18
+ this.update(data);
19
+ }
20
+
21
+ update(data) {
22
+ super.update(data);
23
+ if (data.rate_limit_per_user !== undefined) {
24
+ this.rateLimitPerUser = data.rate_limit_per_user;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Add a reaction to a message
30
+ * @arg {String} messageID The ID of the message
31
+ * @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
32
+ * @returns {Promise}
33
+ */
34
+ addMessageReaction(messageID, reaction) {
35
+ return this._client.addMessageReaction.call(this._client, this.id, messageID, reaction);
36
+ }
37
+
38
+ /**
39
+ * Create a message in the channel
40
+ * @arg {String | Object} content A string or object. If an object is passed:
41
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
42
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
43
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
44
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
45
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
46
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects with the filename and description
47
+ * @arg {String} [content.attachments[].description] The description of the file
48
+ * @arg {String} [content.attachments[].filename] The name of the file
49
+ * @arg {Number} content.attachments[].id The index of the file
50
+ * @arg {Array<Object>} [content.components] An array of [component objects](https://discord.dev/interactions/message-components#component-object)
51
+ * @arg {String} [content.content] A content string
52
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
53
+ * @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
54
+ * @arg {Boolean} [content.enforceNonce] If true and `content.nonce` is present, if multiple messages are sent with the same nonce within a few minutes of each other, that message will be returned and no new message created
55
+ * @arg {Number} [content.flags] A number representing the [flags](https://discord.dev/resources/channel#message-object-message-flags) to apply to the message (only SUPPRESS_EMBEDS and SUPPRESS_NOTIFICATIONS)
56
+ * @arg {Object} [content.messageReference] The message reference, used when replying to or forwarding messages
57
+ * @arg {String} [content.messageReference.channelID] The channel ID of the referenced message. Required when forwarding messages
58
+ * @arg {Boolean} [content.messageReference.failIfNotExists=true] Whether to throw an error if the message reference doesn't exist. If false, and the referenced message doesn't exist, the message is created without a referenced message
59
+ * @arg {String} [content.messageReference.guildID] The guild ID of the referenced message
60
+ * @arg {String} content.messageReference.messageID The message ID of the referenced message. This cannot reference a system message
61
+ * @arg {String} [content.messageReference.type=0] The type of reference. Either `0` (REPLY) or `1` (FORWARDED). Will become required in the future
62
+ * @arg {String} [content.messageReferenceID] [DEPRECATED] The ID of the message should be replied to. Use `messageReference` instead
63
+ * @arg {Object} [content.poll] A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure
64
+ * @arg {String | Number} [content.nonce] A nonce value which will also appear in the messageCreate event
65
+ * @arg {Array<String>} [content.stickerIDs] An array of IDs corresponding to stickers to send
66
+ * @arg {Boolean} [content.tts] Set the message TTS flag
67
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
68
+ * @arg {Buffer} file.file A buffer containing file data
69
+ * @arg {String} file.name What to name the file
70
+ * @returns {Promise<Message>}
71
+ */
72
+ createMessage(content, file) {
73
+ return this._client.createMessage.call(this._client, this.id, content, file);
74
+ }
75
+
76
+ /**
77
+ * Delete a message
78
+ * @arg {String} messageID The ID of the message
79
+ * @arg {String} [reason] The reason to be displayed in audit logs
80
+ * @returns {Promise}
81
+ */
82
+ deleteMessage(messageID, reason) {
83
+ return this._client.deleteMessage.call(this._client, this.id, messageID, reason);
84
+ }
85
+
86
+ /**
87
+ * Bulk delete messages (bot accounts only)
88
+ * @arg {Array<String>} messageIDs Array of message IDs to delete
89
+ * @arg {String} [reason] The reason to be displayed in audit logs
90
+ * @returns {Promise}
91
+ */
92
+ deleteMessages(messageIDs, reason) {
93
+ return this._client.deleteMessages.call(this._client, this.id, messageIDs, reason);
94
+ }
95
+
96
+ /**
97
+ * Edit a message
98
+ * @arg {String} messageID The ID of the message
99
+ * @arg {String | Array | Object} content A string, array of strings, or object. If an object is passed:
100
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
101
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
102
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
103
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
104
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects that will be appended to the message, including new files. Only the provided files will be appended
105
+ * @arg {String} [content.attachments[].description] The description of the file
106
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
107
+ * @arg {Number | String} content.attachments[].id The ID of the file. If you are attaching a new file, this would be the index of the file
108
+ * @arg {Array<Object>} [content.components] An array of [component objects](https://discord.dev/interactions/message-components#component-object)
109
+ * @arg {String} [content.content] A content string
110
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
111
+ * @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
112
+ * @arg {Object | Array<Object>} [content.file] A file object (or an Array of them)
113
+ * @arg {Buffer} content.file[].file A buffer containing file data
114
+ * @arg {String} content.file[].name What to name the file
115
+ * @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
116
+ * @returns {Promise<Message>}
117
+ */
118
+ editMessage(messageID, content) {
119
+ return this._client.editMessage.call(this._client, this.id, messageID, content);
120
+ }
121
+
122
+ /**
123
+ * Immediately end a poll. Note: You cannot end polls from other users.
124
+ * @arg {String} messageID The ID of the message that the poll is in
125
+ * @returns {Promise<Message>}
126
+ */
127
+ endPoll(messageID) {
128
+ return this._client.endPoll.call(this._client, this.id, messageID);
129
+ }
130
+
131
+ /**
132
+ * Get a previous message in the channel
133
+ * @arg {String} messageID The ID of the message
134
+ * @returns {Promise<Message>}
135
+ */
136
+ getMessage(messageID) {
137
+ return this._client.getMessage.call(this._client, this.id, messageID);
138
+ }
139
+
140
+ /**
141
+ * Get a list of users who reacted with a specific reaction
142
+ * @arg {String} messageID The ID of the message
143
+ * @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
144
+ * @arg {Object} [options] Options for the request. If this is a number, it is treated as `options.limit` ([DEPRECATED] behavior)
145
+ * @arg {String} [options.after] Get users after this user ID
146
+ * @arg {Number} [options.limit=100] The maximum number of users to get
147
+ * @arg {Number} [options.type=0] The type of reaction (`0` for normal, `1` for burst)
148
+ * @arg {String} [before] [DEPRECATED] Get users before this user ID. Discord no longer supports this parameter
149
+ * @arg {String} [after] [DEPRECATED] Get users after this user ID
150
+ * @returns {Promise<Array<User>>}
151
+ */
152
+ getMessageReaction(messageID, reaction, options, before, after) {
153
+ return this._client.getMessageReaction.call(this._client, this.id, messageID, reaction, options, before, after);
154
+ }
155
+
156
+ /**
157
+ * Get previous messages in the channel
158
+ * @arg {Object} [options] Options for the request. If this is a number ([DEPRECATED] behavior), it is treated as `options.limit`
159
+ * @arg {String} [options.after] Get messages after this message ID
160
+ * @arg {String} [options.around] Get messages around this message ID (does not work with limit > 100)
161
+ * @arg {String} [options.before] Get messages before this message ID
162
+ * @arg {Number} [options.limit=50] The max number of messages to get
163
+ * @arg {String} [before] [DEPRECATED] Get messages before this message ID
164
+ * @arg {String} [after] [DEPRECATED] Get messages after this message ID
165
+ * @arg {String} [around] [DEPRECATED] Get messages around this message ID (does not work with limit > 100)
166
+ * @returns {Promise<Array<Message>>}
167
+ */
168
+ getMessages(options, before, after, around) {
169
+ return this._client.getMessages.call(this._client, this.id, options, before, after, around);
170
+ }
171
+
172
+ /**
173
+ * Get a list of users that voted for a specific poll answer
174
+ * @arg {String} messageID The ID of the message that the poll is in
175
+ * @arg {Number} answerID The ID of the answer to get voters for
176
+ * @arg {Object} [options] Options for the request
177
+ * @arg {String} [options.after] Get users after this user ID
178
+ * @arg {Number} [options.limit=25] The max number of users to get
179
+ * @returns {Promise<Array<User>>} An array of users who voted for this answer
180
+ */
181
+ getPollAnswerVoters(messageID, answerID, options) {
182
+ return this._client.getPollAnswerVoters.call(this._client, this.id, messageID, answerID, options);
183
+ }
184
+
185
+ /**
186
+ * Purge previous messages in the channel with an optional filter
187
+ * @arg {Object} options Options for the request. If this is a number ([DEPRECATED] behavior), it is treated as `options.limit`
188
+ * @arg {String} [options.after] Get messages after this message ID
189
+ * @arg {String} [options.before] Get messages before this message ID
190
+ * @arg {Function} [options.filter] Optional filter function that returns a boolean when passed a Message object
191
+ * @arg {Number} options.limit The max number of messages to search through, -1 for no limit
192
+ * @arg {String} [options.reason] The reason to be displayed in audit logs
193
+ * @arg {Function} [filter] [DEPRECATED] Optional filter function that returns a boolean when passed a Message object
194
+ * @arg {String} [before] [DEPRECATED] Get messages before this message ID
195
+ * @arg {String} [after] [DEPRECATED] Get messages after this message ID
196
+ * @arg {String} [reason] [DEPRECATED] The reason to be displayed in audit logs
197
+ * @returns {Promise<Number>} Resolves with the number of messages deleted
198
+ */
199
+ purge(limit, filter, before, after, reason) {
200
+ return this._client.purgeChannel.call(this._client, this.id, limit, filter, before, after, reason);
201
+ }
202
+
203
+ /**
204
+ * Remove a reaction from a message
205
+ * @arg {String} messageID The ID of the message
206
+ * @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
207
+ * @arg {String} [userID="@me"] The ID of the user to remove the reaction for
208
+ * @returns {Promise}
209
+ */
210
+ removeMessageReaction(messageID, reaction, userID) {
211
+ return this._client.removeMessageReaction.call(this._client, this.id, messageID, reaction, userID);
212
+ }
213
+
214
+ /**
215
+ * Remove all reactions from a message for a single emoji
216
+ * @arg {String} messageID The ID of the message
217
+ * @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
218
+ * @returns {Promise}
219
+ */
220
+ removeMessageReactionEmoji(messageID, reaction) {
221
+ return this._client.removeMessageReactionEmoji.call(this._client, this.id, messageID, reaction);
222
+ }
223
+
224
+ /**
225
+ * Remove all reactions from a message
226
+ * @arg {String} messageID The ID of the message
227
+ * @returns {Promise}
228
+ */
229
+ removeMessageReactions(messageID) {
230
+ return this._client.removeMessageReactions.call(this._client, this.id, messageID);
231
+ }
232
+
233
+ /**
234
+ * Send typing status in the channel
235
+ * @returns {Promise}
236
+ */
237
+ sendTyping() {
238
+ return this._client.sendChannelTyping.call(this._client, this.id);
239
+ }
240
+
241
+ /**
242
+ * Un-send a message. You're welcome Programmix
243
+ * @arg {String} messageID The ID of the message
244
+ * @returns {Promise}
245
+ */
246
+ unsendMessage(messageID) {
247
+ return this._client.deleteMessage.call(this.client, this.id, messageID);
248
+ }
249
+
250
+ toJSON(props = []) {
251
+ return super.toJSON([
252
+ "lastMessageID",
253
+ "lastPinTimestamp",
254
+ "rateLimitPerUser",
255
+ ...props,
256
+ ]);
257
+ }
258
+ }
259
+
260
+ module.exports = GuildTextableChannel;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Entitlement = require("./Entitlement");
5
+ const Permission = require("./Permission");
6
+ const { ApplicationIntegrationTypes, InteractionTypes } = require("../Constants");
7
+
8
+ /**
9
+ * Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, AutocompleteInteraction, ModalSubmitInteraction, and UnknownInteraction.
10
+ * @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged
11
+ * @prop {Permission?} appPermissions The permissions the app has within the channel the interaction was sent from
12
+ * @prop {String} applicationID The ID of the interaction's application
13
+ * @prop {Number?} attachmentSizeLimit The maximum size of attachments (in bytes) the app can send in response to the interaction
14
+ * @prop {Object} authorizingIntegrationOwners The IDs of the installation contexts that authorized the app for this interaction
15
+ * @prop {String?} authorizingIntegrationOwners.guildInstall The ID of the guild the app is installed in (`"0"` if the interaction was triggered from the app's bot DM), if the app is installed in a guild
16
+ * @prop {String?} authorizingIntegrationOwners.userInstall The ID of the user who installed the app, if the app is installed by a user
17
+ * @prop {Number?} context The context the interaction was triggered from. `0` is a guild, `1` is the app's bot DM, `2` is a group DM or a DM other than the app's bot DM. See `Constants.InteractionContextTypes`
18
+ * @prop {Number} createdAt Timestamp of the interaction's creation
19
+ * @prop {Array<Entitlement>} entitlements The entitlements of the user and/or guild that triggered the interaction, for monetized apps
20
+ * @prop {String?} guildLocale The guild's preferred locale, if the interaction was triggered from a guild
21
+ * @prop {String} id The ID of the interaction
22
+ * @prop {String?} locale The selected language of the user who triggered the interaction (not available on ping interactions)
23
+ * @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
24
+ * @prop {Number} type 1 is a Ping, 2 is an Application Command, 3 is a Message Component, 4 is an Application Command Autocomplete, 5 is a Modal Submit
25
+ * @prop {Number} version The interaction version
26
+ */
27
+ class Interaction extends Base {
28
+ constructor(data, client) {
29
+ super(data.id);
30
+ this._client = client;
31
+
32
+ this.applicationID = data.application_id;
33
+ this.token = data.token;
34
+ this.type = data.type;
35
+ this.version = data.version;
36
+ this.acknowledged = false;
37
+
38
+ if (data.app_permissions !== undefined) {
39
+ this.appPermissions = new Permission(data.app_permissions);
40
+ }
41
+ if (data.attachment_size_limit !== undefined) {
42
+ this.attachmentSizeLimit = data.attachment_size_limit;
43
+ }
44
+ const owners = data.authorizing_integration_owners || {};
45
+ this.authorizingIntegrationOwners = {
46
+ guildInstall: owners[ApplicationIntegrationTypes.GUILD_INSTALL],
47
+ userInstall: owners[ApplicationIntegrationTypes.USER_INSTALL],
48
+ };
49
+ this.context = data.context !== undefined ? data.context : null;
50
+ this.entitlements = data.entitlements ? data.entitlements.map((entitlement) => new Entitlement(entitlement, client)) : [];
51
+ if (data.guild_locale !== undefined) {
52
+ this.guildLocale = data.guild_locale;
53
+ }
54
+ if (data.locale !== undefined) {
55
+ this.locale = data.locale;
56
+ }
57
+ }
58
+
59
+ update() {
60
+ this.acknowledged = true;
61
+ }
62
+
63
+ /**
64
+ * Get the guild the interaction was triggered from. If the guild is not cached (e.g. user-installed apps), a partial guild is created from the interaction data
65
+ * @arg {Object} data The raw interaction data
66
+ * @returns {Guild}
67
+ * @private
68
+ */
69
+ _resolveGuild(data) {
70
+ if (this.channel && this.channel.guild instanceof Guild) {
71
+ return this.channel.guild;
72
+ }
73
+ const guild = this._client.guilds.get(data.guild_id);
74
+ if (guild) {
75
+ return guild;
76
+ }
77
+ if (!this._partialGuild) {
78
+ this._partialGuild = new Guild(Object.assign({}, data.guild, {
79
+ id: data.guild_id,
80
+ }), this._client);
81
+ }
82
+ return this._partialGuild;
83
+ }
84
+
85
+ /**
86
+ * Create or update a member from raw interaction member data
87
+ * @arg {Object} member The raw member data
88
+ * @arg {Object} data The raw interaction data
89
+ * @returns {Member}
90
+ * @private
91
+ */
92
+ _resolveMember(member, data) {
93
+ if (member.user) {
94
+ member.id = member.user.id;
95
+ }
96
+ const guild = this._resolveGuild(data);
97
+ return guild.members.update(member, guild);
98
+ }
99
+
100
+ static from(data, client) {
101
+ switch (data.type) {
102
+ case InteractionTypes.PING: {
103
+ return new PingInteraction(data, client);
104
+ }
105
+ case InteractionTypes.APPLICATION_COMMAND: {
106
+ return new CommandInteraction(data, client);
107
+ }
108
+ case InteractionTypes.MESSAGE_COMPONENT: {
109
+ return new ComponentInteraction(data, client);
110
+ }
111
+ case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE: {
112
+ return new AutocompleteInteraction(data, client);
113
+ }
114
+ case InteractionTypes.MODAL_SUBMIT: {
115
+ return new ModalSubmitInteraction(data, client);
116
+ }
117
+ }
118
+
119
+ client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
120
+ return new UnknownInteraction(data, client);
121
+ }
122
+ }
123
+
124
+ module.exports = Interaction;
125
+
126
+ // Circular import
127
+ const Guild = require("./Guild");
128
+ const PingInteraction = require("./PingInteraction");
129
+ const CommandInteraction = require("./CommandInteraction");
130
+ const ComponentInteraction = require("./ComponentInteraction");
131
+ const AutocompleteInteraction = require("./AutocompleteInteraction");
132
+ const ModalSubmitInteraction = require("./ModalSubmitInteraction.js");
133
+ const UnknownInteraction = require("./UnknownInteraction");