disgroove 1.3.1 → 1.3.3-dev.1

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 (267) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/Client.d.ts +234 -0
  3. package/dist/lib/Client.js +256 -0
  4. package/dist/lib/Client.js.map +1 -0
  5. package/dist/lib/constants.d.ts +1084 -0
  6. package/dist/lib/constants.js +1163 -0
  7. package/dist/lib/constants.js.map +1 -0
  8. package/dist/lib/gateway/Shard.d.ts +25 -0
  9. package/dist/lib/gateway/Shard.js +522 -0
  10. package/dist/lib/gateway/Shard.js.map +1 -0
  11. package/dist/lib/gateway/ShardsManager.d.ts +5 -0
  12. package/dist/lib/gateway/ShardsManager.js +13 -0
  13. package/dist/lib/gateway/ShardsManager.js.map +1 -0
  14. package/dist/lib/gateway/index.d.ts +2 -0
  15. package/dist/lib/gateway/index.js +19 -0
  16. package/dist/lib/gateway/index.js.map +1 -0
  17. package/dist/lib/index.d.ts +7 -0
  18. package/dist/lib/index.js +24 -0
  19. package/dist/lib/index.js.map +1 -0
  20. package/dist/lib/rest/CDN.d.ts +21 -0
  21. package/dist/lib/rest/CDN.js +46 -0
  22. package/dist/lib/rest/CDN.js.map +1 -0
  23. package/dist/lib/rest/Endpoints.d.ts +94 -0
  24. package/dist/lib/rest/Endpoints.js +211 -0
  25. package/dist/lib/rest/Endpoints.js.map +1 -0
  26. package/dist/lib/rest/REST.d.ts +22 -0
  27. package/dist/lib/rest/REST.js +35 -0
  28. package/dist/lib/rest/REST.js.map +1 -0
  29. package/dist/lib/rest/RequestsManager.d.ts +17 -0
  30. package/dist/lib/rest/RequestsManager.js +124 -0
  31. package/dist/lib/rest/RequestsManager.js.map +1 -0
  32. package/dist/lib/rest/index.d.ts +4 -0
  33. package/dist/lib/rest/index.js +34 -0
  34. package/dist/lib/rest/index.js.map +1 -0
  35. package/dist/lib/structures/Application.d.ts +174 -0
  36. package/dist/lib/structures/Application.js +328 -0
  37. package/dist/lib/structures/Application.js.map +1 -0
  38. package/dist/lib/structures/ApplicationCommand.d.ts +45 -0
  39. package/dist/lib/structures/ApplicationCommand.js +127 -0
  40. package/dist/lib/structures/ApplicationCommand.js.map +1 -0
  41. package/dist/lib/structures/AuditLog.d.ts +20 -0
  42. package/dist/lib/structures/AuditLog.js +76 -0
  43. package/dist/lib/structures/AuditLog.js.map +1 -0
  44. package/dist/lib/structures/AutoModerationRule.d.ts +34 -0
  45. package/dist/lib/structures/AutoModerationRule.js +96 -0
  46. package/dist/lib/structures/AutoModerationRule.js.map +1 -0
  47. package/dist/lib/structures/Base.d.ts +17 -0
  48. package/dist/lib/structures/Base.js +31 -0
  49. package/dist/lib/structures/Base.js.map +1 -0
  50. package/dist/lib/structures/Channel.d.ts +253 -0
  51. package/dist/lib/structures/Channel.js +591 -0
  52. package/dist/lib/structures/Channel.js.map +1 -0
  53. package/dist/lib/structures/ClientApplication.d.ts +150 -0
  54. package/dist/lib/structures/ClientApplication.js +241 -0
  55. package/dist/lib/structures/ClientApplication.js.map +1 -0
  56. package/dist/lib/structures/Emoji.d.ts +28 -0
  57. package/dist/lib/structures/Emoji.js +79 -0
  58. package/dist/lib/structures/Emoji.js.map +1 -0
  59. package/dist/lib/structures/Entitlement.d.ts +24 -0
  60. package/dist/lib/structures/Entitlement.js +68 -0
  61. package/dist/lib/structures/Entitlement.js.map +1 -0
  62. package/dist/lib/structures/Guild.d.ts +462 -0
  63. package/dist/lib/structures/Guild.js +1095 -0
  64. package/dist/lib/structures/Guild.js.map +1 -0
  65. package/dist/lib/structures/GuildMember.d.ts +50 -0
  66. package/dist/lib/structures/GuildMember.js +149 -0
  67. package/dist/lib/structures/GuildMember.js.map +1 -0
  68. package/dist/lib/structures/GuildScheduledEvent.d.ts +49 -0
  69. package/dist/lib/structures/GuildScheduledEvent.js +118 -0
  70. package/dist/lib/structures/GuildScheduledEvent.js.map +1 -0
  71. package/dist/lib/structures/GuildTemplate.d.ts +32 -0
  72. package/dist/lib/structures/GuildTemplate.js +76 -0
  73. package/dist/lib/structures/GuildTemplate.js.map +1 -0
  74. package/dist/lib/structures/Integration.d.ts +30 -0
  75. package/dist/lib/structures/Integration.js +102 -0
  76. package/dist/lib/structures/Integration.js.map +1 -0
  77. package/dist/lib/structures/Interaction.d.ts +76 -0
  78. package/dist/lib/structures/Interaction.js +345 -0
  79. package/dist/lib/structures/Interaction.js.map +1 -0
  80. package/dist/lib/structures/Invite.d.ts +28 -0
  81. package/dist/lib/structures/Invite.js +86 -0
  82. package/dist/lib/structures/Invite.js.map +1 -0
  83. package/dist/lib/structures/Message.d.ts +84 -0
  84. package/dist/lib/structures/Message.js +300 -0
  85. package/dist/lib/structures/Message.js.map +1 -0
  86. package/dist/lib/structures/Role.d.ts +37 -0
  87. package/dist/lib/structures/Role.js +90 -0
  88. package/dist/lib/structures/Role.js.map +1 -0
  89. package/dist/lib/structures/SKU.d.ts +23 -0
  90. package/dist/lib/structures/SKU.js +63 -0
  91. package/dist/lib/structures/SKU.js.map +1 -0
  92. package/dist/lib/structures/StageInstance.d.ts +24 -0
  93. package/dist/lib/structures/StageInstance.js +57 -0
  94. package/dist/lib/structures/StageInstance.js.map +1 -0
  95. package/dist/lib/structures/Sticker.d.ts +31 -0
  96. package/dist/lib/structures/Sticker.js +86 -0
  97. package/dist/lib/structures/Sticker.js.map +1 -0
  98. package/dist/lib/structures/Team.d.ts +14 -0
  99. package/dist/lib/structures/Team.js +39 -0
  100. package/dist/lib/structures/Team.js.map +1 -0
  101. package/dist/lib/structures/TestEntitlement.d.ts +23 -0
  102. package/dist/lib/structures/TestEntitlement.js +61 -0
  103. package/dist/lib/structures/TestEntitlement.js.map +1 -0
  104. package/dist/lib/structures/UnavailableGuild.d.ts +11 -0
  105. package/dist/lib/structures/UnavailableGuild.js +25 -0
  106. package/dist/lib/structures/UnavailableGuild.js.map +1 -0
  107. package/dist/lib/structures/User.d.ts +63 -0
  108. package/dist/lib/structures/User.js +177 -0
  109. package/dist/lib/structures/User.js.map +1 -0
  110. package/dist/lib/structures/VoiceState.d.ts +26 -0
  111. package/dist/lib/structures/VoiceState.js +70 -0
  112. package/dist/lib/structures/VoiceState.js.map +1 -0
  113. package/dist/lib/structures/Webhook.d.ts +84 -0
  114. package/dist/lib/structures/Webhook.js +239 -0
  115. package/dist/lib/structures/Webhook.js.map +1 -0
  116. package/dist/lib/structures/index.d.ts +27 -0
  117. package/dist/lib/structures/index.js +44 -0
  118. package/dist/lib/structures/index.js.map +1 -0
  119. package/dist/lib/types/application-command.d.ts +102 -0
  120. package/dist/lib/types/application-command.js +3 -0
  121. package/dist/lib/types/application-command.js.map +1 -0
  122. package/dist/lib/types/application-role-connection-metadata.d.ts +18 -0
  123. package/dist/lib/types/application-role-connection-metadata.js +3 -0
  124. package/dist/lib/types/application-role-connection-metadata.js.map +1 -0
  125. package/dist/lib/types/application.d.ts +66 -0
  126. package/dist/lib/types/application.js +3 -0
  127. package/dist/lib/types/application.js.map +1 -0
  128. package/dist/lib/types/audit-log.d.ts +82 -0
  129. package/dist/lib/types/audit-log.js +3 -0
  130. package/dist/lib/types/audit-log.js.map +1 -0
  131. package/dist/lib/types/auto-moderation.d.ts +65 -0
  132. package/dist/lib/types/auto-moderation.js +3 -0
  133. package/dist/lib/types/auto-moderation.js.map +1 -0
  134. package/dist/lib/types/channel.d.ts +456 -0
  135. package/dist/lib/types/channel.js +3 -0
  136. package/dist/lib/types/channel.js.map +1 -0
  137. package/dist/lib/types/emoji.d.ts +22 -0
  138. package/dist/lib/types/emoji.js +3 -0
  139. package/dist/lib/types/emoji.js.map +1 -0
  140. package/dist/lib/types/entitlements.d.ts +32 -0
  141. package/dist/lib/types/entitlements.js +3 -0
  142. package/dist/lib/types/entitlements.js.map +1 -0
  143. package/dist/lib/types/gateway-events.d.ts +805 -0
  144. package/dist/lib/types/gateway-events.js +3 -0
  145. package/dist/lib/types/gateway-events.js.map +1 -0
  146. package/dist/lib/types/guild-scheduled-event.d.ts +57 -0
  147. package/dist/lib/types/guild-scheduled-event.js +3 -0
  148. package/dist/lib/types/guild-scheduled-event.js.map +1 -0
  149. package/dist/lib/types/guild-template.d.ts +28 -0
  150. package/dist/lib/types/guild-template.js +3 -0
  151. package/dist/lib/types/guild-template.js.map +1 -0
  152. package/dist/lib/types/guild.d.ts +333 -0
  153. package/dist/lib/types/guild.js +3 -0
  154. package/dist/lib/types/guild.js.map +1 -0
  155. package/dist/lib/types/index.d.ts +23 -0
  156. package/dist/lib/types/index.js +40 -0
  157. package/dist/lib/types/index.js.map +1 -0
  158. package/dist/lib/types/interaction.d.ts +170 -0
  159. package/dist/lib/types/interaction.js +3 -0
  160. package/dist/lib/types/interaction.js.map +1 -0
  161. package/dist/lib/types/invite.d.ts +59 -0
  162. package/dist/lib/types/invite.js +3 -0
  163. package/dist/lib/types/invite.js.map +1 -0
  164. package/dist/lib/types/message-components.d.ts +100 -0
  165. package/dist/lib/types/message-components.js +3 -0
  166. package/dist/lib/types/message-components.js.map +1 -0
  167. package/dist/lib/types/role.d.ts +47 -0
  168. package/dist/lib/types/role.js +3 -0
  169. package/dist/lib/types/role.js.map +1 -0
  170. package/dist/lib/types/sku.d.ts +30 -0
  171. package/dist/lib/types/sku.js +3 -0
  172. package/dist/lib/types/sku.js.map +1 -0
  173. package/dist/lib/types/stage-instance.d.ts +20 -0
  174. package/dist/lib/types/stage-instance.js +3 -0
  175. package/dist/lib/types/stage-instance.js.map +1 -0
  176. package/dist/lib/types/sticker.d.ts +61 -0
  177. package/dist/lib/types/sticker.js +3 -0
  178. package/dist/lib/types/sticker.js.map +1 -0
  179. package/dist/lib/types/team.d.ts +30 -0
  180. package/dist/lib/types/team.js +3 -0
  181. package/dist/lib/types/team.js.map +1 -0
  182. package/dist/lib/types/user.d.ts +77 -0
  183. package/dist/lib/types/user.js +3 -0
  184. package/dist/lib/types/user.js.map +1 -0
  185. package/dist/lib/types/voice.d.ts +47 -0
  186. package/dist/lib/types/voice.js +3 -0
  187. package/dist/lib/types/voice.js.map +1 -0
  188. package/dist/lib/types/webhook.d.ts +31 -0
  189. package/dist/lib/types/webhook.js +3 -0
  190. package/dist/lib/types/webhook.js.map +1 -0
  191. package/dist/lib/utils/Util.d.ts +15 -0
  192. package/dist/lib/utils/Util.js +543 -0
  193. package/dist/lib/utils/Util.js.map +1 -0
  194. package/dist/lib/utils/errors.d.ts +12 -0
  195. package/dist/lib/utils/errors.js +25 -0
  196. package/dist/lib/utils/errors.js.map +1 -0
  197. package/dist/lib/utils/index.d.ts +2 -0
  198. package/dist/lib/utils/index.js +19 -0
  199. package/dist/lib/utils/index.js.map +1 -0
  200. package/dist/package.json +1 -1
  201. package/lib/Client.ts +616 -0
  202. package/lib/constants.ts +1173 -0
  203. package/lib/gateway/Shard.ts +704 -0
  204. package/lib/gateway/ShardsManager.ts +11 -0
  205. package/lib/gateway/index.ts +2 -0
  206. package/lib/index.ts +7 -0
  207. package/lib/rest/CDN.ts +56 -0
  208. package/lib/rest/Endpoints.ts +241 -0
  209. package/lib/rest/REST.ts +45 -0
  210. package/lib/rest/RequestsManager.ts +134 -0
  211. package/lib/rest/index.ts +4 -0
  212. package/lib/structures/Application.ts +599 -0
  213. package/lib/structures/ApplicationCommand.ts +187 -0
  214. package/lib/structures/AuditLog.ts +112 -0
  215. package/lib/structures/AutoModerationRule.ts +127 -0
  216. package/lib/structures/Base.ts +39 -0
  217. package/lib/structures/Channel.ts +921 -0
  218. package/lib/structures/ClientApplication.ts +515 -0
  219. package/lib/structures/Emoji.ts +95 -0
  220. package/lib/structures/Entitlement.ts +65 -0
  221. package/lib/structures/Guild.ts +1842 -0
  222. package/lib/structures/GuildMember.ts +193 -0
  223. package/lib/structures/GuildScheduledEvent.ts +164 -0
  224. package/lib/structures/GuildTemplate.ts +103 -0
  225. package/lib/structures/Integration.ts +136 -0
  226. package/lib/structures/Interaction.ts +506 -0
  227. package/lib/structures/Invite.ts +108 -0
  228. package/lib/structures/Message.ts +421 -0
  229. package/lib/structures/Role.ts +116 -0
  230. package/lib/structures/SKU.ts +63 -0
  231. package/lib/structures/StageInstance.ts +74 -0
  232. package/lib/structures/Sticker.ts +100 -0
  233. package/lib/structures/Team.ts +41 -0
  234. package/lib/structures/TestEntitlement.ts +78 -0
  235. package/lib/structures/UnavailableGuild.ts +27 -0
  236. package/lib/structures/User.ts +233 -0
  237. package/lib/structures/VoiceState.ts +72 -0
  238. package/lib/structures/Webhook.ts +341 -0
  239. package/lib/structures/index.ts +27 -0
  240. package/lib/types/application-command.ts +118 -0
  241. package/lib/types/application-role-connection-metadata.ts +23 -0
  242. package/lib/types/application.ts +77 -0
  243. package/lib/types/audit-log.ts +105 -0
  244. package/lib/types/auto-moderation.ts +78 -0
  245. package/lib/types/channel.ts +534 -0
  246. package/lib/types/emoji.ts +24 -0
  247. package/lib/types/entitlements.ts +34 -0
  248. package/lib/types/gateway-events.ts +970 -0
  249. package/lib/types/guild-scheduled-event.ts +67 -0
  250. package/lib/types/guild-template.ts +30 -0
  251. package/lib/types/guild.ts +388 -0
  252. package/lib/types/index.ts +23 -0
  253. package/lib/types/interaction.ts +224 -0
  254. package/lib/types/invite.ts +78 -0
  255. package/lib/types/message-components.ts +127 -0
  256. package/lib/types/role.ts +51 -0
  257. package/lib/types/sku.ts +32 -0
  258. package/lib/types/stage-instance.ts +22 -0
  259. package/lib/types/sticker.ts +67 -0
  260. package/lib/types/team.ts +34 -0
  261. package/lib/types/user.ts +93 -0
  262. package/lib/types/voice.ts +51 -0
  263. package/lib/types/webhook.ts +40 -0
  264. package/lib/utils/Util.ts +600 -0
  265. package/lib/utils/errors.ts +23 -0
  266. package/lib/utils/index.ts +2 -0
  267. package/package.json +1 -1
@@ -0,0 +1,193 @@
1
+ import { User } from ".";
2
+ import type { Client } from "../Client";
3
+ import { Endpoints } from "../rest";
4
+ import type {
5
+ JSONGuildMember,
6
+ JSONGuildMemberAddEventExtraFields,
7
+ RawGuildMember,
8
+ RawGuildMemberAddEventExtraFields,
9
+ } from "../types";
10
+ import type { GuildMemberFlags } from "../constants";
11
+
12
+ /** https://discord.com/developers/docs/resources/guild */
13
+ export class GuildMember {
14
+ private client: Client;
15
+ private raw: RawGuildMember & Partial<RawGuildMemberAddEventExtraFields>;
16
+ user?: User;
17
+ nick?: string | null;
18
+ avatar?: string | null;
19
+ roles: Array<string>;
20
+ joinedAt: string;
21
+ premiumSince?: number | null;
22
+ deaf: boolean;
23
+ mute: boolean;
24
+ flags: GuildMemberFlags;
25
+ pending?: boolean;
26
+ permissions?: string;
27
+ communicationDisabledUntil?: number | null;
28
+ guildId?: string;
29
+
30
+ constructor(
31
+ data: RawGuildMember & Partial<RawGuildMemberAddEventExtraFields>,
32
+ client: Client
33
+ ) {
34
+ this.client = client;
35
+ this.raw = data;
36
+ this.roles = data.roles;
37
+ this.joinedAt = data.joined_at;
38
+ this.deaf = data.deaf;
39
+ this.mute = data.mute;
40
+ this.flags = data.flags;
41
+
42
+ this.patch(data);
43
+ }
44
+
45
+ private patch(
46
+ data: RawGuildMember & Partial<RawGuildMemberAddEventExtraFields>
47
+ ): void {
48
+ if (data.user !== undefined) this.user = new User(data.user, this.client);
49
+ if (data.nick !== undefined) this.nick = data.nick;
50
+ if (data.avatar !== undefined) this.avatar = data.avatar;
51
+ if (data.premium_since !== undefined)
52
+ this.premiumSince = data.premium_since;
53
+ if (data.pending !== undefined) this.pending = data.pending;
54
+ if (data.permissions !== undefined) this.permissions = data.permissions;
55
+ if (data.communication_disabled_until !== undefined)
56
+ this.communicationDisabledUntil = data.communication_disabled_until;
57
+ if (data.guild_id !== undefined) this.guildId = data.guild_id;
58
+ }
59
+
60
+ /** https://discord.com/developers/docs/resources/guild#add-guild-member-role */
61
+ addRole(roleId: string, reason?: string): void {
62
+ if (!this.user?.id)
63
+ throw new Error("[disgroove] Guild member ID not found");
64
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
65
+
66
+ this.client.rest.put(
67
+ Endpoints.guildMemberRole(this.guildId, this.user.id, roleId),
68
+ {
69
+ reason,
70
+ }
71
+ );
72
+ }
73
+
74
+ /** https://discord.com/developers/docs/resources/guild#create-guild-ban */
75
+ createBan(
76
+ options?: {
77
+ deleteMessageDays?: number;
78
+ deleteMessageSeconds?: number;
79
+ },
80
+ reason?: string
81
+ ): void {
82
+ if (!this.user?.id)
83
+ throw new Error("[disgroove] Guild member ID not found");
84
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
85
+
86
+ this.client.rest.put(Endpoints.guildBan(this.guildId, this.user.id), {
87
+ json: {
88
+ delete_message_days: options?.deleteMessageDays,
89
+ delete_message_seconds: options?.deleteMessageSeconds,
90
+ },
91
+ reason,
92
+ });
93
+ }
94
+
95
+ /** https://discord.com/developers/docs/resources/guild#modify-guild-member */
96
+ async edit(
97
+ options: {
98
+ nick?: string | null;
99
+ roles?: Array<string> | null;
100
+ mute?: boolean | null;
101
+ deaf?: boolean | null;
102
+ channelId?: string | null;
103
+ communicationDisabledUntil?: number | null;
104
+ flags?: GuildMemberFlags;
105
+ },
106
+ reason?: string
107
+ ): Promise<GuildMember> {
108
+ if (!this.user?.id)
109
+ throw new Error("[disgroove] Guild member ID not found");
110
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
111
+
112
+ return new GuildMember(
113
+ await this.client.rest.patch(
114
+ Endpoints.guildMember(this.guildId, this.user.id),
115
+ {
116
+ json: {
117
+ nick: options.nick,
118
+ roles: options.roles,
119
+ mute: options.mute,
120
+ deaf: options.deaf,
121
+ channel_id: options.channelId,
122
+ communication_disabled_until: options.communicationDisabledUntil,
123
+ flags: options.flags,
124
+ },
125
+ reason,
126
+ }
127
+ ),
128
+ this.client
129
+ );
130
+ }
131
+
132
+ /** https://discord.com/developers/docs/resources/guild#remove-guild-member */
133
+ remove(reason?: string): void {
134
+ if (!this.user?.id)
135
+ throw new Error("[disgroove] Guild member ID not found");
136
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
137
+
138
+ this.client.rest.delete(Endpoints.guildMember(this.guildId, this.user.id), {
139
+ reason,
140
+ });
141
+ }
142
+
143
+ /** https://discord.com/developers/docs/resources/guild#remove-guild-ban */
144
+ removeBan(reason?: string): void {
145
+ if (!this.user?.id)
146
+ throw new Error("[disgroove] Guild member ID not found");
147
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
148
+
149
+ this.client.rest.delete(Endpoints.guildBan(this.guildId, this.user.id), {
150
+ reason,
151
+ });
152
+ }
153
+
154
+ /** https://discord.com/developers/docs/resources/guild#remove-guild-member-role */
155
+ removeRole(roleId: string, reason?: string): void {
156
+ if (!this.user?.id)
157
+ throw new Error("[disgroove] Guild member ID not found");
158
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
159
+
160
+ this.client.rest.delete(
161
+ Endpoints.guildMemberRole(this.guildId, this.user.id, roleId),
162
+ {
163
+ reason,
164
+ }
165
+ );
166
+ }
167
+
168
+ toString(): string {
169
+ return `[${this.constructor.name}]`;
170
+ }
171
+
172
+ toRaw(): RawGuildMember & Partial<RawGuildMemberAddEventExtraFields> {
173
+ return this.raw;
174
+ }
175
+
176
+ toJSON(): JSONGuildMember & Partial<JSONGuildMemberAddEventExtraFields> {
177
+ return {
178
+ user: this.user?.toJSON(),
179
+ nick: this.nick,
180
+ avatar: this.avatar,
181
+ roles: this.roles,
182
+ joinedAt: this.joinedAt,
183
+ premiumSince: this.premiumSince,
184
+ deaf: this.deaf,
185
+ mute: this.mute,
186
+ flags: this.flags,
187
+ pending: this.pending,
188
+ permissions: this.permissions,
189
+ communicationDisabledUntil: this.communicationDisabledUntil,
190
+ guildId: this.guildId,
191
+ };
192
+ }
193
+ }
@@ -0,0 +1,164 @@
1
+ import { Base, GuildMember, User } from ".";
2
+ import type { Client } from "../Client";
3
+ import { Endpoints } from "../rest";
4
+ import type {
5
+ JSONGuildScheduledEvent,
6
+ JSONGuildScheduledEventEntityMetadata,
7
+ JSONGuildScheduledEventUser,
8
+ RawGuildScheduledEvent,
9
+ RawGuildScheduledEventUser,
10
+ } from "../types";
11
+ import type {
12
+ GuildScheduledEventEntityTypes,
13
+ GuildScheduledEventPrivacyLevel,
14
+ GuildScheduledEventStatus,
15
+ } from "../constants";
16
+
17
+ /** https://discord.com/developers/docs/resources/guild-scheduled-event */
18
+ export class GuildScheduledEvent extends Base {
19
+ protected override raw: RawGuildScheduledEvent;
20
+ guildId: string;
21
+ channelId: string | null;
22
+ creatorId?: string | null;
23
+ name: string;
24
+ description?: string | null;
25
+ scheduledStartTime: string;
26
+ scheduledEndTime: string | null;
27
+ privacyLevel: GuildScheduledEventPrivacyLevel;
28
+ status: GuildScheduledEventStatus;
29
+ entityType: GuildScheduledEventEntityTypes;
30
+ entityId?: string;
31
+ entityMetadata: JSONGuildScheduledEventEntityMetadata | null;
32
+ creator?: User;
33
+ userCount?: number;
34
+ image?: string;
35
+
36
+ constructor(data: RawGuildScheduledEvent, client: Client) {
37
+ super(data.id, client);
38
+
39
+ this.raw = data;
40
+ this.guildId = data.guild_id;
41
+ this.channelId = data.channel_id;
42
+ this.name = data.name;
43
+ this.scheduledStartTime = data.scheduled_start_time;
44
+ this.scheduledEndTime = data.scheduled_end_time;
45
+ this.privacyLevel = data.privacy_level;
46
+ this.status = data.status;
47
+ this.entityType = data.entity_type;
48
+ this.entityMetadata = data.entity_metadata;
49
+
50
+ this.patch(data);
51
+ }
52
+
53
+ protected override patch(data: RawGuildScheduledEvent): void {
54
+ if (data.creator_id !== undefined) this.creatorId = data.creator_id;
55
+ if (data.description !== undefined) this.description = data.description;
56
+ if (data.entity_id !== undefined) this.entityId = data.entity_id;
57
+ if (data.creator !== undefined)
58
+ this.creator = new User(data.creator, this.client);
59
+ if (data.user_count !== undefined) this.userCount = data.user_count;
60
+ if (data.image !== undefined) this.image = data.image;
61
+ }
62
+
63
+ /** https://discord.com/developers/docs/resources/guild-scheduled-event#delete-guild-scheduled-event */
64
+ delete(): void {
65
+ this.client.rest.delete(
66
+ Endpoints.guildScheduledEvent(this.guildId, this.id)
67
+ );
68
+ }
69
+
70
+ /** https://discord.com/developers/docs/resources/guild-scheduled-event#modify-guild-scheduled-event */
71
+ async edit(
72
+ options: {
73
+ channelId?: string | null;
74
+ entityMetadata?: JSONGuildScheduledEventEntityMetadata | null;
75
+ name?: string;
76
+ privacyLevel?: GuildScheduledEventPrivacyLevel;
77
+ scheduledStartTime?: string;
78
+ scheduledEndTime?: string;
79
+ description?: string | null;
80
+ entityType?: GuildScheduledEventEntityTypes;
81
+ status?: GuildScheduledEventStatus;
82
+ image?: string;
83
+ },
84
+ reason?: string
85
+ ): Promise<GuildScheduledEvent> {
86
+ return new GuildScheduledEvent(
87
+ await this.client.rest.patch<RawGuildScheduledEvent>(
88
+ Endpoints.guildScheduledEvent(this.guildId, this.id),
89
+ {
90
+ json: {
91
+ channel_id: options.channelId,
92
+ entity_metadata: options.entityMetadata,
93
+ name: options.name,
94
+ privacy_level: options.privacyLevel,
95
+ scheduled_start_time: options.scheduledStartTime,
96
+ scheduled_end_time: options.scheduledEndTime,
97
+ description: options.description,
98
+ entityType: options.entityType,
99
+ status: options.status,
100
+ image: options.image,
101
+ },
102
+ reason,
103
+ }
104
+ ),
105
+ this.client
106
+ );
107
+ }
108
+
109
+ /** https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event-users */
110
+ async getUsers(options?: {
111
+ limit?: number;
112
+ withMember?: boolean;
113
+ before?: string;
114
+ after?: string;
115
+ }): Promise<Array<JSONGuildScheduledEventUser>> {
116
+ return this.client.rest
117
+ .get<Array<RawGuildScheduledEventUser>>(
118
+ Endpoints.guildScheduledEvent(this.guildId, this.id),
119
+ {
120
+ query: {
121
+ limit: options?.limit,
122
+ with_member: options?.withMember,
123
+ before: options?.before,
124
+ after: options?.after,
125
+ },
126
+ }
127
+ )
128
+ .then((response) =>
129
+ response.map((data) => ({
130
+ guildScheduledEventId: data.guild_scheduled_event_id,
131
+ user: new User(data.user, this.client).toJSON(),
132
+ member:
133
+ data.member !== undefined
134
+ ? new GuildMember(data.member, this.client).toJSON()
135
+ : undefined,
136
+ }))
137
+ );
138
+ }
139
+
140
+ override toRaw(): RawGuildScheduledEvent {
141
+ return this.raw;
142
+ }
143
+
144
+ override toJSON(): JSONGuildScheduledEvent {
145
+ return {
146
+ ...super.toJSON(),
147
+ guildId: this.guildId,
148
+ channelId: this.channelId,
149
+ creatorId: this.creatorId,
150
+ name: this.name,
151
+ description: this.description,
152
+ scheduledStartTime: this.scheduledStartTime,
153
+ scheduledEndTime: this.scheduledEndTime,
154
+ privacyLevel: this.privacyLevel,
155
+ status: this.status,
156
+ entityType: this.entityType,
157
+ entityId: this.entityId,
158
+ entityMetadata: this.entityMetadata,
159
+ creator: this.creator?.toJSON(),
160
+ userCount: this.userCount,
161
+ image: this.image,
162
+ };
163
+ }
164
+ }
@@ -0,0 +1,103 @@
1
+ import { Guild, User } from ".";
2
+ import type { Client } from "../Client";
3
+ import { Endpoints } from "../rest";
4
+ import type { JSONGuildTemplate, RawGuildTemplate } from "../types";
5
+
6
+ /** https://discord.com/developers/docs/resources/guild-template */
7
+ export class GuildTemplate {
8
+ private client: Client;
9
+ private raw: RawGuildTemplate;
10
+ code: string;
11
+ name: string;
12
+ description: string | null;
13
+ usageCount: number;
14
+ creatorId: string;
15
+ creator: User;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ sourceGuildId: string;
19
+ serializedSourceGuild: Guild;
20
+ isDirty: boolean | null;
21
+
22
+ constructor(data: RawGuildTemplate, client: Client) {
23
+ this.client = client;
24
+ this.raw = data;
25
+ this.code = data.code;
26
+ this.name = data.name;
27
+ this.description = data.description;
28
+ this.usageCount = data.usage_count;
29
+ this.creatorId = data.creator_id;
30
+ this.createdAt = data.created_at;
31
+ this.creator = new User(data.creator, client);
32
+ this.updatedAt = data.updated_at;
33
+ this.sourceGuildId = data.source_guild_id;
34
+ this.serializedSourceGuild = new Guild(
35
+ data.serialized_source_guild,
36
+ client
37
+ );
38
+ this.isDirty = data.is_dirty;
39
+ }
40
+
41
+ /** https://discord.com/developers/docs/resources/guild-template#delete-guild-template */
42
+ async delete(): Promise<JSONGuildTemplate> {
43
+ return new GuildTemplate(
44
+ await this.client.rest.delete<RawGuildTemplate>(
45
+ Endpoints.guildTemplate(this.sourceGuildId, this.code)
46
+ ),
47
+ this.client
48
+ ).toJSON();
49
+ }
50
+
51
+ /** https://discord.com/developers/docs/resources/guild-template#modify-guild-template */
52
+ async edit(options: {
53
+ name?: string;
54
+ description?: string | null;
55
+ }): Promise<GuildTemplate> {
56
+ return new GuildTemplate(
57
+ await this.client.rest.patch<RawGuildTemplate>(
58
+ Endpoints.guildTemplate(this.sourceGuildId, this.code),
59
+ {
60
+ json: {
61
+ name: options.name,
62
+ description: options.description,
63
+ },
64
+ }
65
+ ),
66
+ this.client
67
+ );
68
+ }
69
+
70
+ /** https://discord.com/developers/docs/resources/guild-template#sync-guild-template */
71
+ async sync(): Promise<GuildTemplate> {
72
+ return new GuildTemplate(
73
+ await this.client.rest.put<RawGuildTemplate>(
74
+ Endpoints.guildTemplate(this.sourceGuildId, this.code)
75
+ ),
76
+ this.client
77
+ );
78
+ }
79
+
80
+ toString(): string {
81
+ return `[${this.constructor.name}]`;
82
+ }
83
+
84
+ toRaw(): RawGuildTemplate {
85
+ return this.raw;
86
+ }
87
+
88
+ toJSON(): JSONGuildTemplate {
89
+ return {
90
+ code: this.code,
91
+ name: this.name,
92
+ description: this.description,
93
+ usageCount: this.usageCount,
94
+ creatorId: this.creatorId,
95
+ creator: this.creator.toJSON(),
96
+ createdAt: this.createdAt,
97
+ updatedAt: this.updatedAt,
98
+ sourceGuildId: this.sourceGuildId,
99
+ serializedSourceGuild: this.serializedSourceGuild.toJSON(),
100
+ isDirty: this.isDirty,
101
+ };
102
+ }
103
+ }
@@ -0,0 +1,136 @@
1
+ import { Base, User } from ".";
2
+ import type { Client } from "../Client";
3
+ import { Endpoints } from "../rest";
4
+ import type {
5
+ JSONIntegration,
6
+ JSONIntegrationAccount,
7
+ JSONIntegrationApplication,
8
+ JSONIntegrationCreateEventExtraFields,
9
+ JSONIntegrationUpdateEventExtraFields,
10
+ RawIntegration,
11
+ RawIntegrationCreateEventExtraFields,
12
+ RawIntegrationUpdateEventExtraFields,
13
+ } from "../types";
14
+ import type { IntegrationExpireBehaviors, OAuth2Scopes } from "../constants";
15
+
16
+ /** https://discord.com/developers/docs/resources/guild */
17
+ export class Integration extends Base {
18
+ protected override raw: RawIntegration &
19
+ Partial<
20
+ | RawIntegrationCreateEventExtraFields
21
+ | RawIntegrationUpdateEventExtraFields
22
+ >;
23
+ name: string;
24
+ type: string;
25
+ enabled: boolean;
26
+ syncing?: boolean;
27
+ roleId?: string;
28
+ enableEmoticons?: boolean;
29
+ expireBehavior?: IntegrationExpireBehaviors;
30
+ expireGracePeriod?: number;
31
+ user?: User;
32
+ account: JSONIntegrationAccount;
33
+ syncedAt?: string;
34
+ subscriberCount?: number;
35
+ revoked?: boolean;
36
+ application?: JSONIntegrationApplication;
37
+ scopes?: Array<OAuth2Scopes>;
38
+ guildId?: string;
39
+
40
+ constructor(
41
+ data: RawIntegration &
42
+ Partial<
43
+ | RawIntegrationCreateEventExtraFields
44
+ | RawIntegrationUpdateEventExtraFields
45
+ >,
46
+ client: Client
47
+ ) {
48
+ super(data.id, client);
49
+
50
+ this.raw = data;
51
+ this.name = data.name;
52
+ this.type = data.type;
53
+ this.enabled = data.enabled;
54
+ this.account = data.account;
55
+
56
+ this.patch(data);
57
+ }
58
+
59
+ protected override patch(
60
+ data: RawIntegration &
61
+ Partial<
62
+ | RawIntegrationCreateEventExtraFields
63
+ | RawIntegrationUpdateEventExtraFields
64
+ >
65
+ ): void {
66
+ if (data.syncing !== undefined) this.syncing = data.syncing;
67
+ if (data.role_id !== undefined) this.roleId = data.role_id;
68
+ if (data.enable_emoticons !== undefined)
69
+ this.enableEmoticons = data.enable_emoticons;
70
+ if (data.expire_behavior !== undefined)
71
+ this.expireBehavior = data.expire_behavior;
72
+ if (data.expire_grace_period !== undefined)
73
+ this.expireGracePeriod = data.expire_grace_period;
74
+ if (data.user !== undefined) this.user = new User(data.user, this.client);
75
+ if (data.synced_at !== undefined) this.syncedAt = data.synced_at;
76
+ if (data.subscriber_count !== undefined)
77
+ this.subscriberCount = data.subscriber_count;
78
+ if (data.revoked !== undefined) this.revoked = data.revoked;
79
+ if (data.application !== undefined)
80
+ this.application = {
81
+ id: data.application.id,
82
+ name: data.application.name,
83
+ icon: data.application.icon,
84
+ description: data.application.description,
85
+ bot:
86
+ data.application.bot !== undefined
87
+ ? new User(data.application.bot, this.client).toJSON()
88
+ : undefined,
89
+ };
90
+ if (data.scopes !== undefined) this.scopes = data.scopes;
91
+ if (data.guild_id !== undefined) this.guildId = data.guild_id;
92
+ }
93
+
94
+ /** https://discord.com/developers/docs/resources/guild#delete-guild-integration */
95
+ delete(reason?: string): void {
96
+ if (!this.guildId) throw new Error("[disgroove] Guild ID not found");
97
+
98
+ this.client.rest.delete(Endpoints.guildIntegration(this.guildId, this.id), {
99
+ reason,
100
+ });
101
+ }
102
+
103
+ override toRaw(): RawIntegration &
104
+ Partial<
105
+ | RawIntegrationCreateEventExtraFields
106
+ | RawIntegrationUpdateEventExtraFields
107
+ > {
108
+ return this.raw;
109
+ }
110
+
111
+ override toJSON(): JSONIntegration &
112
+ Partial<
113
+ | JSONIntegrationCreateEventExtraFields
114
+ | JSONIntegrationUpdateEventExtraFields
115
+ > {
116
+ return {
117
+ ...super.toJSON(),
118
+ name: this.name,
119
+ type: this.type,
120
+ enabled: this.enabled,
121
+ syncing: this.syncing,
122
+ roleId: this.roleId,
123
+ enableEmoticons: this.enableEmoticons,
124
+ expireBehavior: this.expireBehavior,
125
+ expireGracePeriod: this.expireGracePeriod,
126
+ user: this.user?.toJSON(),
127
+ account: this.account,
128
+ syncedAt: this.syncedAt,
129
+ subscriberCount: this.subscriberCount,
130
+ revoked: this.revoked,
131
+ application: this.application,
132
+ scopes: this.scopes,
133
+ guildId: this.guildId,
134
+ };
135
+ }
136
+ }