bakit 3.0.0 → 3.1.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/dist/index.cjs +1050 -587
- package/dist/index.d.cts +390 -249
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +417 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +908 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/index.d.ts +0 -276
- package/dist/index.js +0 -522
package/dist/index.js
DELETED
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
import { ShardingManager } from '@bakit/gateway';
|
|
2
|
-
export { Cluster, Shard, ShardState, ShardStrategy, ShardingManager } from '@bakit/gateway';
|
|
3
|
-
import { REST } from '@bakit/rest';
|
|
4
|
-
export { DEFAULT_REST_OPTIONS, DiscordHTTPError, REST, RESTAdapter, RESTMethod, createREST, createRESTAdapter } from '@bakit/rest';
|
|
5
|
-
export { Service, ServiceDriver, ServiceProcess, ServiceState, TransportClient, TransportServer, createService, createTransportClient, createTransportServer } from '@bakit/service';
|
|
6
|
-
import { getSnowflakeDate } from '@bakit/utils';
|
|
7
|
-
export { capitalize, instanceToObject, isCommonJS, isESM, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
|
|
8
|
-
import EventEmitter from 'events';
|
|
9
|
-
import { Collection } from '@discordjs/collection';
|
|
10
|
-
import { Routes, GatewayDispatchEvents, ChannelType } from 'discord-api-types/v10';
|
|
11
|
-
import * as v10 from 'discord-api-types/v10';
|
|
12
|
-
export { v10 as DiscordAPIV10 };
|
|
13
|
-
export { GatewayIntentBits as Intent } from 'discord-api-types/v10';
|
|
14
|
-
import { createMixin, applyMixins } from 'tiny-mixin';
|
|
15
|
-
|
|
16
|
-
// src/modules/gateway.ts
|
|
17
|
-
|
|
18
|
-
// src/lib/structures/BaseStructure.ts
|
|
19
|
-
var BaseStructure = class {
|
|
20
|
-
constructor(client) {
|
|
21
|
-
Object.defineProperty(this, "client", {
|
|
22
|
-
value: client,
|
|
23
|
-
enumerable: false,
|
|
24
|
-
writable: false
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
toJSON() {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
var User = class extends BaseStructure {
|
|
32
|
-
constructor(client, data) {
|
|
33
|
-
super(client);
|
|
34
|
-
this.data = data;
|
|
35
|
-
}
|
|
36
|
-
get id() {
|
|
37
|
-
return this.data.id;
|
|
38
|
-
}
|
|
39
|
-
get username() {
|
|
40
|
-
return this.data.username;
|
|
41
|
-
}
|
|
42
|
-
get discriminator() {
|
|
43
|
-
return this.data.discriminator;
|
|
44
|
-
}
|
|
45
|
-
get globalName() {
|
|
46
|
-
return this.data.global_name;
|
|
47
|
-
}
|
|
48
|
-
get tag() {
|
|
49
|
-
return this.discriminator !== "0" && this.discriminator !== "0000" ? `${this.username}#${this.discriminator}` : this.username;
|
|
50
|
-
}
|
|
51
|
-
get displayName() {
|
|
52
|
-
return this.globalName ?? this.tag;
|
|
53
|
-
}
|
|
54
|
-
get avatar() {
|
|
55
|
-
return this.data.avatar ?? void 0;
|
|
56
|
-
}
|
|
57
|
-
get bot() {
|
|
58
|
-
return !!this.data.bot;
|
|
59
|
-
}
|
|
60
|
-
get system() {
|
|
61
|
-
return !!this.data.system;
|
|
62
|
-
}
|
|
63
|
-
get mfaEnabled() {
|
|
64
|
-
return this.data.mfa_enabled;
|
|
65
|
-
}
|
|
66
|
-
get locale() {
|
|
67
|
-
return this.data.locale;
|
|
68
|
-
}
|
|
69
|
-
get verified() {
|
|
70
|
-
return this.data.verified;
|
|
71
|
-
}
|
|
72
|
-
get email() {
|
|
73
|
-
return this.data.email;
|
|
74
|
-
}
|
|
75
|
-
get flags() {
|
|
76
|
-
return this.data.flags;
|
|
77
|
-
}
|
|
78
|
-
get premiumType() {
|
|
79
|
-
return this.data.premium_type;
|
|
80
|
-
}
|
|
81
|
-
get publicFlags() {
|
|
82
|
-
return this.data.public_flags;
|
|
83
|
-
}
|
|
84
|
-
get banner() {
|
|
85
|
-
return this.data.banner;
|
|
86
|
-
}
|
|
87
|
-
get accentColor() {
|
|
88
|
-
return this.data.accent_color ?? void 0;
|
|
89
|
-
}
|
|
90
|
-
get createdAt() {
|
|
91
|
-
return getSnowflakeDate(this.id);
|
|
92
|
-
}
|
|
93
|
-
get createdTimestamp() {
|
|
94
|
-
return this.createdAt.getTime();
|
|
95
|
-
}
|
|
96
|
-
get hexAccentColor() {
|
|
97
|
-
return this.accentColor !== void 0 ? `#${this.accentColor.toString(16).padStart(6, "0")}` : void 0;
|
|
98
|
-
}
|
|
99
|
-
get defaultAvatarURL() {
|
|
100
|
-
return `https://cdn.discordapp.com/embed/avatars/${this.discriminator !== "0" && this.discriminator !== "0000" ? BigInt(this.discriminator) % 5n : (BigInt(this.id) >> 22n) % 6n}.png`;
|
|
101
|
-
}
|
|
102
|
-
getAvatarURL(options) {
|
|
103
|
-
if (!this.avatar)
|
|
104
|
-
return;
|
|
105
|
-
let isAnimated = this.avatar.startsWith("a_"), ext = options?.extension ?? (isAnimated ? "gif" : "png"), size = options?.size ? `?size=${options.size}` : "";
|
|
106
|
-
return `https://cdn.discordapp.com/avatars/${this.id}/${this.avatar}.${ext}${size}`;
|
|
107
|
-
}
|
|
108
|
-
getDisplayAvatarURL(options) {
|
|
109
|
-
return this.getAvatarURL(options) ?? this.defaultAvatarURL;
|
|
110
|
-
}
|
|
111
|
-
equals(other) {
|
|
112
|
-
return typeof other == "string" ? other === this.id : other.id === this.id && other.username === this.username && other.discriminator === this.discriminator && other.bot === this.bot && other.createdTimestamp === this.createdTimestamp;
|
|
113
|
-
}
|
|
114
|
-
toJSON() {
|
|
115
|
-
return this.data;
|
|
116
|
-
}
|
|
117
|
-
toString() {
|
|
118
|
-
return `<@${this.id}>`;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// src/lib/structures/Message.ts
|
|
123
|
-
var Message = class extends BaseStructure {
|
|
124
|
-
constructor(client, data) {
|
|
125
|
-
super(client);
|
|
126
|
-
this.data = data;
|
|
127
|
-
}
|
|
128
|
-
cachedAuthor;
|
|
129
|
-
get partial() {
|
|
130
|
-
return typeof this.data.content != "string" || typeof this.data.author != "object";
|
|
131
|
-
}
|
|
132
|
-
get content() {
|
|
133
|
-
return this.data.content;
|
|
134
|
-
}
|
|
135
|
-
get id() {
|
|
136
|
-
return this.data.id;
|
|
137
|
-
}
|
|
138
|
-
get channelId() {
|
|
139
|
-
return this.data.channel_id;
|
|
140
|
-
}
|
|
141
|
-
get channel() {
|
|
142
|
-
return this.guild.channels.get(this.channelId);
|
|
143
|
-
}
|
|
144
|
-
get guildId() {
|
|
145
|
-
return "guild_id" in this.data ? this.data.guild_id : void 0;
|
|
146
|
-
}
|
|
147
|
-
get guild() {
|
|
148
|
-
return this.guildId ? this.client.guilds.get(this.guildId) : void 0;
|
|
149
|
-
}
|
|
150
|
-
get author() {
|
|
151
|
-
return this.cachedAuthor ??= new User(this.client, this.data.author), this.cachedAuthor;
|
|
152
|
-
}
|
|
153
|
-
get createdAt() {
|
|
154
|
-
return new Date(this.data.timestamp);
|
|
155
|
-
}
|
|
156
|
-
get editedAt() {
|
|
157
|
-
return this.data.edited_timestamp ? new Date(this.data.edited_timestamp) : void 0;
|
|
158
|
-
}
|
|
159
|
-
get createdTimestamp() {
|
|
160
|
-
return this.createdAt.getTime();
|
|
161
|
-
}
|
|
162
|
-
get editedTimestamp() {
|
|
163
|
-
return this.editedAt?.getTime();
|
|
164
|
-
}
|
|
165
|
-
get url() {
|
|
166
|
-
return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`;
|
|
167
|
-
}
|
|
168
|
-
async fetch() {
|
|
169
|
-
let message = await this.client.helper.fetchMessage(this.channelId, this.id);
|
|
170
|
-
return this.data = message.data, this.cachedAuthor = message.cachedAuthor, this;
|
|
171
|
-
}
|
|
172
|
-
async reply(options) {
|
|
173
|
-
return this.client.helper.replyMessage(this.channelId, this.id, options);
|
|
174
|
-
}
|
|
175
|
-
async sendToChannel(options) {
|
|
176
|
-
return this.client.helper.createMessage(this.channelId, options);
|
|
177
|
-
}
|
|
178
|
-
toJSON() {
|
|
179
|
-
return this.data;
|
|
180
|
-
}
|
|
181
|
-
toString() {
|
|
182
|
-
return this.data.content;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// src/lib/structures/channel/BaseChannel.ts
|
|
187
|
-
var BaseChannel = class extends BaseStructure {
|
|
188
|
-
constructor(client, data) {
|
|
189
|
-
super(client);
|
|
190
|
-
this.data = data;
|
|
191
|
-
}
|
|
192
|
-
get id() {
|
|
193
|
-
return this.data.id;
|
|
194
|
-
}
|
|
195
|
-
get type() {
|
|
196
|
-
return this.data.type;
|
|
197
|
-
}
|
|
198
|
-
toString() {
|
|
199
|
-
return `<#${this.id}>`;
|
|
200
|
-
}
|
|
201
|
-
toJSON() {
|
|
202
|
-
return this.data;
|
|
203
|
-
}
|
|
204
|
-
isTextBased() {
|
|
205
|
-
return "send" in this;
|
|
206
|
-
}
|
|
207
|
-
isVoiceBased() {
|
|
208
|
-
return "join" in this;
|
|
209
|
-
}
|
|
210
|
-
inGuild() {
|
|
211
|
-
return "guild_id" in this.data;
|
|
212
|
-
}
|
|
213
|
-
_patch(data) {
|
|
214
|
-
this.data = { ...this.data, ...data };
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
var TextBasedChannelMixin = createMixin((base) => {
|
|
218
|
-
class TextBasedChannel extends base {
|
|
219
|
-
send(options) {
|
|
220
|
-
return this.client.helper.createMessage(this.id, options);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return TextBasedChannel;
|
|
224
|
-
}), VoiceBasedChannelMixin = createMixin((base) => {
|
|
225
|
-
class VoiceBasedChannel extends base {
|
|
226
|
-
}
|
|
227
|
-
return VoiceBasedChannel;
|
|
228
|
-
}), GuildChannelMixin = createMixin((base) => {
|
|
229
|
-
class GuildChannel extends base {
|
|
230
|
-
get guildId() {
|
|
231
|
-
if (!this.data.guild_id)
|
|
232
|
-
throw new Error("This channel is not a guild channel");
|
|
233
|
-
return this.data.guild_id;
|
|
234
|
-
}
|
|
235
|
-
get guild() {
|
|
236
|
-
return this.client.guilds.get(this.guildId);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return GuildChannel;
|
|
240
|
-
});
|
|
241
|
-
var GuildTextChannel = class extends applyMixins(BaseChannel, [
|
|
242
|
-
GuildChannelMixin,
|
|
243
|
-
TextBasedChannelMixin
|
|
244
|
-
]) {
|
|
245
|
-
};
|
|
246
|
-
var GuildVoiceChannel = class extends applyMixins(BaseChannel, [
|
|
247
|
-
GuildChannelMixin,
|
|
248
|
-
TextBasedChannelMixin,
|
|
249
|
-
VoiceBasedChannelMixin
|
|
250
|
-
]) {
|
|
251
|
-
};
|
|
252
|
-
function createChannel(client, data) {
|
|
253
|
-
switch (data.type) {
|
|
254
|
-
case ChannelType.GuildText:
|
|
255
|
-
return new GuildTextChannel(client, data);
|
|
256
|
-
case ChannelType.GuildVoice:
|
|
257
|
-
return new GuildVoiceChannel(client, data);
|
|
258
|
-
default:
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/lib/structures/Guild.ts
|
|
264
|
-
var Guild = class extends BaseStructure {
|
|
265
|
-
constructor(client, data) {
|
|
266
|
-
super(client);
|
|
267
|
-
this.data = data;
|
|
268
|
-
}
|
|
269
|
-
cachedChannels;
|
|
270
|
-
get id() {
|
|
271
|
-
return this.data.id;
|
|
272
|
-
}
|
|
273
|
-
get name() {
|
|
274
|
-
return this.data.name;
|
|
275
|
-
}
|
|
276
|
-
get icon() {
|
|
277
|
-
return this.data.icon;
|
|
278
|
-
}
|
|
279
|
-
get banner() {
|
|
280
|
-
return this.data.banner;
|
|
281
|
-
}
|
|
282
|
-
get owner() {
|
|
283
|
-
return this.data.owner_id;
|
|
284
|
-
}
|
|
285
|
-
get mfaLevel() {
|
|
286
|
-
return this.data.mfa_level;
|
|
287
|
-
}
|
|
288
|
-
get verificationLevel() {
|
|
289
|
-
return this.data.verification_level;
|
|
290
|
-
}
|
|
291
|
-
get channels() {
|
|
292
|
-
if (!this.cachedChannels && (this.cachedChannels = new Collection(), "channels" in this.data))
|
|
293
|
-
for (let data of this.data.channels) {
|
|
294
|
-
let channel = createChannel(this.client, data);
|
|
295
|
-
channel && this.cachedChannels.set(channel.id, channel);
|
|
296
|
-
}
|
|
297
|
-
return this.cachedChannels;
|
|
298
|
-
}
|
|
299
|
-
_patch(data) {
|
|
300
|
-
this.data = { ...this.data, ...data };
|
|
301
|
-
}
|
|
302
|
-
// public get roles() {
|
|
303
|
-
// return this.data.roles;
|
|
304
|
-
// }
|
|
305
|
-
};
|
|
306
|
-
var ClientHelper = class _ClientHelper {
|
|
307
|
-
constructor(client) {
|
|
308
|
-
Object.defineProperty(this, "client", {
|
|
309
|
-
value: client,
|
|
310
|
-
enumerable: false,
|
|
311
|
-
writable: false
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
async fetchMessage(channelId, messageId) {
|
|
315
|
-
let data = await this.client.rest.get(Routes.channelMessage(channelId, messageId));
|
|
316
|
-
return new Message(this.client, data);
|
|
317
|
-
}
|
|
318
|
-
async deleteMessage(channelId, messageId) {
|
|
319
|
-
return this.client.rest.delete(Routes.channelMessage(channelId, messageId));
|
|
320
|
-
}
|
|
321
|
-
async createMessage(channelId, options) {
|
|
322
|
-
return this.client.rest.post(Routes.channelMessages(channelId), {
|
|
323
|
-
body: _ClientHelper.toAPICreateMessagePayload(options)
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
async replyMessage(channelId, messageId, options) {
|
|
327
|
-
return this.createMessage(channelId, {
|
|
328
|
-
...options,
|
|
329
|
-
messageReference: {
|
|
330
|
-
channel_id: channelId,
|
|
331
|
-
message_id: messageId
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
async fetchGuild(guildId) {
|
|
336
|
-
let data = await this.client.rest.get(Routes.guild(guildId));
|
|
337
|
-
return new Guild(this.client, data);
|
|
338
|
-
}
|
|
339
|
-
static toAPICreateMessagePayload(options) {
|
|
340
|
-
return {
|
|
341
|
-
content: options.content,
|
|
342
|
-
tts: options.tts,
|
|
343
|
-
embeds: options.embeds,
|
|
344
|
-
allowed_mentions: options.allowedMentions,
|
|
345
|
-
message_reference: options.messageReference,
|
|
346
|
-
flags: options.flags
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
// src/lib/client/Partial.ts
|
|
352
|
-
var Partial = /* @__PURE__ */ ((Partial2) => (Partial2[Partial2.Message = 0] = "Message", Partial2[Partial2.User = 1] = "User", Partial2))(Partial || {});
|
|
353
|
-
var IntentsBitField = class _IntentsBitField {
|
|
354
|
-
value;
|
|
355
|
-
constructor(input) {
|
|
356
|
-
this.value = _IntentsBitField.resolve(input);
|
|
357
|
-
}
|
|
358
|
-
static resolve(input) {
|
|
359
|
-
return Array.isArray(input) ? input.reduce((acc, intent) => acc | BigInt(intent), 0n) : BigInt(input);
|
|
360
|
-
}
|
|
361
|
-
has(intent) {
|
|
362
|
-
return (this.value & BigInt(intent)) !== 0n;
|
|
363
|
-
}
|
|
364
|
-
toBigInt() {
|
|
365
|
-
return this.value;
|
|
366
|
-
}
|
|
367
|
-
toNumber() {
|
|
368
|
-
return Number(this.value);
|
|
369
|
-
}
|
|
370
|
-
toJSON() {
|
|
371
|
-
return this.value.toString();
|
|
372
|
-
}
|
|
373
|
-
toString() {
|
|
374
|
-
return this.value.toString();
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
// src/lib/client/Client.ts
|
|
379
|
-
var Client = class extends EventEmitter {
|
|
380
|
-
options;
|
|
381
|
-
shards;
|
|
382
|
-
rest;
|
|
383
|
-
helper;
|
|
384
|
-
guilds = new Collection();
|
|
385
|
-
#user;
|
|
386
|
-
#ready = false;
|
|
387
|
-
constructor(options, rest) {
|
|
388
|
-
super();
|
|
389
|
-
let intents = options.intents instanceof IntentsBitField ? options.intents : new IntentsBitField(options.intents), sharding = {
|
|
390
|
-
shardsPerCluster: options.sharding?.shardsPerCluster ?? 1,
|
|
391
|
-
totalShards: options.sharding?.totalShards ?? 1
|
|
392
|
-
};
|
|
393
|
-
this.options = {
|
|
394
|
-
token: options.token,
|
|
395
|
-
intents,
|
|
396
|
-
sharding,
|
|
397
|
-
partials: new Set(options.partials ?? [])
|
|
398
|
-
}, this.rest = rest ?? new REST({ token: options.token }), this.shards = new ShardingManager(
|
|
399
|
-
{
|
|
400
|
-
...this.options.sharding,
|
|
401
|
-
token: this.options.token,
|
|
402
|
-
intents: this.options.intents.toBigInt()
|
|
403
|
-
},
|
|
404
|
-
rest
|
|
405
|
-
), this.helper = new ClientHelper(this), this.#setupShardsListeners();
|
|
406
|
-
}
|
|
407
|
-
get user() {
|
|
408
|
-
return this.#user;
|
|
409
|
-
}
|
|
410
|
-
async login() {
|
|
411
|
-
if (this.#user || this.shards.ready || this.shards.clusters.size > 0)
|
|
412
|
-
throw new Error("Cannot login twice");
|
|
413
|
-
return await this.shards.spawn(), new Promise((resolve, reject) => {
|
|
414
|
-
let cleanup = () => {
|
|
415
|
-
this.removeListener("ready", onReady), this.removeListener("error", onError);
|
|
416
|
-
}, onReady = () => {
|
|
417
|
-
cleanup(), resolve();
|
|
418
|
-
}, onError = (error) => {
|
|
419
|
-
cleanup(), reject(error);
|
|
420
|
-
};
|
|
421
|
-
this.once("ready", onReady), this.once("error", onError);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
#setupShardsListeners() {
|
|
425
|
-
this.shards.on("dispatch", (_, shardId, payload) => this.#handleDispatch(shardId, payload)), this.shards.on("raw", (_, shardId, payload) => this.emit("raw", shardId, payload)), this.shards.once("ready", () => this.#tryEmitReady());
|
|
426
|
-
}
|
|
427
|
-
async #handleDispatch(shardId, payload) {
|
|
428
|
-
switch (this.emit("dispatch", shardId, payload), payload.t) {
|
|
429
|
-
case GatewayDispatchEvents.Ready: {
|
|
430
|
-
this.#user ??= new User(this, payload.d.user), this.#tryEmitReady();
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
case GatewayDispatchEvents.MessageCreate: {
|
|
434
|
-
let message = new Message(this, payload.d);
|
|
435
|
-
if (message.partial && !this.options.partials.has(0 /* Message */))
|
|
436
|
-
return;
|
|
437
|
-
this.emit("messageCreate", message);
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
case GatewayDispatchEvents.MessageUpdate: {
|
|
441
|
-
let message = new Message(this, payload.d);
|
|
442
|
-
if (message.partial && !this.options.partials.has(0 /* Message */))
|
|
443
|
-
return;
|
|
444
|
-
this.emit("messageUpdate", message);
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
case GatewayDispatchEvents.MessageDelete: {
|
|
448
|
-
this.emit("messageDelete", {
|
|
449
|
-
id: payload.d.id,
|
|
450
|
-
channelId: payload.d.channel_id,
|
|
451
|
-
guildId: payload.d.guild_id
|
|
452
|
-
});
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
case GatewayDispatchEvents.UserUpdate: {
|
|
456
|
-
payload.d.id === this.#user?.id && (this.#user = new User(this, payload.d)), this.emit("userUpdate", new User(this, payload.d));
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
case GatewayDispatchEvents.GuildCreate: {
|
|
460
|
-
let guild = this.guilds.get(payload.d.id);
|
|
461
|
-
guild ? guild._patch(payload.d) : guild = new Guild(this, payload.d), this.guilds.set(payload.d.id, guild), payload.d.unavailable ? this.emit("guildCreate", guild) : this.emit("guildAvailable", guild);
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
case GatewayDispatchEvents.GuildDelete: {
|
|
465
|
-
let guild = this.guilds.get(payload.d.id);
|
|
466
|
-
if (!guild)
|
|
467
|
-
return;
|
|
468
|
-
this.guilds.delete(payload.d.id), this.emit("guildDelete", guild);
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
case GatewayDispatchEvents.GuildUpdate: {
|
|
472
|
-
let guild = this.guilds.get(payload.d.id);
|
|
473
|
-
guild ? guild._patch(payload.d) : (guild = new Guild(this, payload.d), this.guilds.set(payload.d.id, guild)), this.emit("guildUpdate", guild);
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
case GatewayDispatchEvents.ChannelCreate: {
|
|
477
|
-
let channel = createChannel(this, payload.d);
|
|
478
|
-
if (!channel)
|
|
479
|
-
return;
|
|
480
|
-
channel.inGuild() && channel.guild.channels.set(channel.id, channel), this.emit("channelCreate", channel);
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
case GatewayDispatchEvents.ChannelUpdate: {
|
|
484
|
-
let guild = this.guilds.get(payload.d.guild_id);
|
|
485
|
-
if (!guild)
|
|
486
|
-
return;
|
|
487
|
-
let channel = guild.channels.get(payload.d.id);
|
|
488
|
-
if (channel)
|
|
489
|
-
channel._patch(payload.d);
|
|
490
|
-
else {
|
|
491
|
-
if (channel = createChannel(this, payload.d), !channel)
|
|
492
|
-
return;
|
|
493
|
-
guild.channels.set(payload.d.id, channel);
|
|
494
|
-
}
|
|
495
|
-
this.emit("channelUpdate", channel);
|
|
496
|
-
break;
|
|
497
|
-
}
|
|
498
|
-
case GatewayDispatchEvents.ChannelDelete: {
|
|
499
|
-
let guild = this.guilds.get(payload.d.guild_id);
|
|
500
|
-
if (!guild)
|
|
501
|
-
return;
|
|
502
|
-
let channel = guild.channels.get(payload.d.id);
|
|
503
|
-
if (!channel)
|
|
504
|
-
return;
|
|
505
|
-
guild.channels.delete(payload.d.id), this.emit("channelDelete", channel);
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* We use this method to emit ready event only once since we have 2 ways to emit it.
|
|
512
|
-
* @private
|
|
513
|
-
*/
|
|
514
|
-
#tryEmitReady() {
|
|
515
|
-
this.#ready || !this.#user || !this.shards.ready || (this.#ready = true, this.emit("ready", this.#user));
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
function createClient(options) {
|
|
519
|
-
return new Client(options);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
export { BaseChannel, Client, ClientHelper, Guild, GuildTextChannel, GuildVoiceChannel, IntentsBitField, Message, Partial, User, createClient };
|