bakit 2.1.2 → 2.2.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/cli.js CHANGED
@@ -9,7 +9,7 @@ import { startServiceServer } from '@bakit/service';
9
9
  // package.json
10
10
  var package_default = {
11
11
  name: "bakit",
12
- version: "2.1.2"};
12
+ version: "2.2.0"};
13
13
 
14
14
  // src/lib/cli/index.ts
15
15
  config();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,146 @@
1
- export { DEFAULT_GATEWAY_MANAGER_OPTIONS, DEFAULT_WORKER_PATH, GatewayManager, GatewayManagerEvents, GatewayManagerOptions, GatewayWorker, GatewayWorkerEvents, GatewayWorkerOptions, GatewayWorkerState, createGatewayManager, createWorker } from '@bakit/gateway';
1
+ import { REST } from '@bakit/rest';
2
2
  export { REST, RESTEndpoint, RESTEvents, RESTMethod, RESTOptions, createREST } from '@bakit/rest';
3
+ import { EventBus } from '@bakit/utils';
3
4
  export { Awaitable, Collection, EventBus, EventMap, FunctionLike, Promisify, PromisifyValue, Queue, QueueOptions, ReadonlyCollection, RejectFn, ResolveFn, attachEventBus, capitalize, createEventBus, createQueue, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
5
+ import { APIUser, APIMessage, ChannelType, Snowflake, APIChannel, APIChannelBase, APIGuildTextChannel, APIDMChannel, APIPublicThreadChannel, APIPrivateThreadChannel, APITextBasedChannel, TextChannelType, APIGuildChannel, GuildTextChannelType, APIThreadChannel, MessageFlags, GatewayReceivePayload } from 'discord-api-types/v10';
6
+ import * as discord_api_types_globals from 'discord-api-types/globals';
7
+ export { DEFAULT_GATEWAY_MANAGER_OPTIONS, DEFAULT_WORKER_PATH, GatewayManager, GatewayManagerEvents, GatewayManagerOptions, GatewayWorker, GatewayWorkerEvents, GatewayWorkerOptions, GatewayWorkerState, createGatewayManager, createWorker } from '@bakit/gateway';
4
8
  export { RPCError, RPCErrorPayload, RPCHandler, RPCRequestMessage, RPCResponseMessage, Serializable, Service, ServiceFunction, ServiceOptions, TransportClient, TransportClientOptions, TransportDriver, TransportServer, TransportServerOptions, createIPCClient, createIPCServer, createService, createTransportClient, createTransportServer, deserializeRPCError, getIPCPath, serializeRPCError } from '@bakit/service';
9
+
10
+ interface User {
11
+ readonly client: Client;
12
+ readonly id: string;
13
+ readonly username: string;
14
+ readonly discriminator: string;
15
+ readonly globalName?: string | null;
16
+ readonly avatar?: string | null;
17
+ readonly system?: boolean;
18
+ readonly mfaEnabled?: boolean;
19
+ readonly banner?: string | null;
20
+ readonly accentColor?: number;
21
+ readonly locale?: string;
22
+ readonly verified?: boolean;
23
+ readonly email?: string | null;
24
+ readonly flags?: number;
25
+ readonly premiumType?: number;
26
+ readonly publicFlags?: number;
27
+ }
28
+ declare function createUser(client: Client, data: APIUser): User;
29
+
30
+ interface Message {
31
+ readonly client: Client;
32
+ readonly id: string;
33
+ readonly channelId: string;
34
+ readonly author: User;
35
+ readonly content: string;
36
+ readonly timestamp: string;
37
+ readonly editedTimestamp?: string;
38
+ readonly tts: boolean;
39
+ readonly mentionEveryone: boolean;
40
+ readonly mentions: readonly User[];
41
+ readonly mentionRoles: readonly string[];
42
+ readonly nonce?: string | number;
43
+ readonly pinned: boolean;
44
+ readonly webhookId?: string;
45
+ readonly type: number;
46
+ readonly applicationId?: string;
47
+ readonly flags?: number;
48
+ readonly referencedMessage?: Message;
49
+ readonly position?: number;
50
+ }
51
+ declare function createMessage(client: Client, data: APIMessage): Message;
52
+
53
+ interface TextBasedChannelSingleton {
54
+ lastMessageId?: Snowflake;
55
+ send(content: string): Promise<Message>;
56
+ send(options: CreateMessageOptions): Promise<Message>;
57
+ send(options: CreateMessageOptions | string): Promise<Message>;
58
+ }
59
+ interface VoiceBasedChannelSingleton {
60
+ join(): Promise<void>;
61
+ }
62
+ interface GuildBasedChannelSingleton {
63
+ readonly name: string;
64
+ readonly guildId?: Snowflake;
65
+ readonly parentId?: Snowflake;
66
+ }
67
+ interface GuildTextBasedChannelSingleton extends GuildBasedChannelSingleton, TextBasedChannelSingleton {
68
+ }
69
+ interface ThreadBasedChannelSingleton extends GuildTextBasedChannelSingleton {
70
+ readonly messageCount?: number;
71
+ readonly memberCount?: number;
72
+ readonly ownerId?: Snowflake;
73
+ readonly totalMessageSent?: number;
74
+ readonly appliedTags?: Snowflake[];
75
+ }
76
+ interface BaseChannel {
77
+ readonly client: Client;
78
+ readonly id: string;
79
+ readonly type: ChannelType;
80
+ isTextBased(): this is GuildTextChannel | DMChannel | PublicThreadChannel | PrivateThreadChannel;
81
+ isVoiceBased(): this is VoiceChannel | StageChannel;
82
+ isGuildBased(): this is GuildTextChannel | VoiceChannel | StageChannel | PublicThreadChannel | PrivateThreadChannel;
83
+ isThreadBased(): this is PublicThreadChannel | PrivateThreadChannel;
84
+ isDm(): this is DMChannel;
85
+ isGuildText(): this is GuildTextChannel;
86
+ isVoice(): this is VoiceChannel;
87
+ isStage(): this is StageChannel;
88
+ isPublicThread(): this is PublicThreadChannel;
89
+ isPrivateThread(): this is PrivateThreadChannel;
90
+ }
91
+ interface DMChannel extends BaseChannel, TextBasedChannelSingleton {
92
+ readonly recipients?: User[];
93
+ }
94
+ interface GuildTextChannel extends BaseChannel, GuildTextBasedChannelSingleton {
95
+ }
96
+ interface VoiceChannel extends GuildTextChannel, VoiceBasedChannelSingleton {
97
+ }
98
+ interface StageChannel extends GuildTextChannel, VoiceBasedChannelSingleton {
99
+ }
100
+ interface PublicThreadChannel extends BaseChannel, ThreadBasedChannelSingleton {
101
+ }
102
+ interface PrivateThreadChannel extends BaseChannel, ThreadBasedChannelSingleton {
103
+ }
104
+ type Channel = GuildTextChannel | DMChannel | PublicThreadChannel | VoiceChannel | StageChannel | BaseChannel;
105
+ declare function createChannel(client: Client, data: APIChannel): Channel;
106
+ declare function createBaseChannel(client: Client, data: APIChannelBase<ChannelType>): BaseChannel;
107
+ declare function createGuildTextChannel(client: Client, data: APIGuildTextChannel<ChannelType.GuildText>): GuildTextChannel;
108
+ declare function createDMChannel(client: Client, data: APIDMChannel): DMChannel;
109
+ declare function createPublicThreadChannel(client: Client, data: APIPublicThreadChannel): PublicThreadChannel;
110
+ declare function createPrivateThreadChannel(client: Client, data: APIPrivateThreadChannel): PrivateThreadChannel;
111
+ declare function createVoiceChannel(client: Client, data: APIGuildTextChannel<ChannelType.GuildVoice>): VoiceChannel;
112
+ declare function createStageChannel(client: Client, data: APIGuildTextChannel<ChannelType.GuildStageVoice>): StageChannel;
113
+ declare function createTextBasedChannelSingleton(client: Client, data: APITextBasedChannel<TextChannelType>): TextBasedChannelSingleton;
114
+ declare function createVoiceBasedChannelSingleton(_client: Client, _data: APIChannelBase<ChannelType.GuildVoice> | APIChannelBase<ChannelType.GuildStageVoice>): VoiceBasedChannelSingleton;
115
+ declare function createGuildBasedChannelSingleton(data: APIGuildChannel): GuildBasedChannelSingleton;
116
+ declare function createGuildTextBasedChannelSingleton(client: Client, data: APIGuildTextChannel<GuildTextChannelType>): GuildTextBasedChannelSingleton;
117
+ declare function createThreadBasedChannelSingleton(client: Client, data: APIThreadChannel): ThreadBasedChannelSingleton;
118
+
119
+ interface CreateMessageOptions {
120
+ content?: string;
121
+ flags?: MessageFlags;
122
+ }
123
+
124
+ declare function createHelpers(client: Client): {
125
+ user: {
126
+ getById(id: discord_api_types_globals.Snowflake): Promise<User | undefined>;
127
+ getCurrent(): Promise<User>;
128
+ };
129
+ channel: {
130
+ getById(id: discord_api_types_globals.Snowflake): Promise<Channel | undefined>;
131
+ createMessage(channelId: discord_api_types_globals.Snowflake, options: CreateMessageOptions | string): Promise<Message>;
132
+ deleteMessage(channelId: discord_api_types_globals.Snowflake, messageId: discord_api_types_globals.Snowflake): Promise<void>;
133
+ };
134
+ };
135
+
136
+ interface Client extends EventBus<ClientEvents> {
137
+ rest: REST;
138
+ helpers: ReturnType<typeof createHelpers>;
139
+ }
140
+ interface ClientEvents {
141
+ raw: [payload: GatewayReceivePayload];
142
+ messageCreate: [message: Message];
143
+ }
144
+ declare function createClient(rest: REST): Client;
145
+
146
+ export { type BaseChannel, type Channel, type Client, type ClientEvents, type DMChannel, type GuildBasedChannelSingleton, type GuildTextBasedChannelSingleton, type GuildTextChannel, type Message, type PrivateThreadChannel, type PublicThreadChannel, type StageChannel, type TextBasedChannelSingleton, type ThreadBasedChannelSingleton, type User, type VoiceBasedChannelSingleton, type VoiceChannel, createBaseChannel, createChannel, createClient, createDMChannel, createGuildBasedChannelSingleton, createGuildTextBasedChannelSingleton, createGuildTextChannel, createMessage, createPrivateThreadChannel, createPublicThreadChannel, createStageChannel, createTextBasedChannelSingleton, createThreadBasedChannelSingleton, createUser, createVoiceBasedChannelSingleton, createVoiceChannel };
package/dist/index.js CHANGED
@@ -1,4 +1,360 @@
1
+ import { attachEventBus } from '@bakit/utils';
2
+ export { Collection, attachEventBus, capitalize, createEventBus, createQueue, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
3
+ import { ChannelType, GatewayDispatchEvents } from 'discord-api-types/v10';
1
4
  export { DEFAULT_GATEWAY_MANAGER_OPTIONS, DEFAULT_WORKER_PATH, createGatewayManager, createWorker } from '@bakit/gateway';
2
5
  export { createREST } from '@bakit/rest';
3
- export { Collection, attachEventBus, capitalize, createEventBus, createQueue, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
4
6
  export { RPCError, createIPCClient, createIPCServer, createService, createTransportClient, createTransportServer, deserializeRPCError, getIPCPath, serializeRPCError } from '@bakit/service';
7
+
8
+ // src/lib/client/index.ts
9
+
10
+ // src/lib/structures/user.ts
11
+ function createUser(client, data) {
12
+ return {
13
+ get client() {
14
+ return client;
15
+ },
16
+ get id() {
17
+ return data.id;
18
+ },
19
+ get username() {
20
+ return data.username;
21
+ },
22
+ get discriminator() {
23
+ return data.discriminator;
24
+ },
25
+ get globalName() {
26
+ return data.global_name;
27
+ },
28
+ get avatar() {
29
+ return data.avatar;
30
+ },
31
+ get system() {
32
+ return data.system;
33
+ },
34
+ get mfaEnabled() {
35
+ return data.mfa_enabled;
36
+ },
37
+ get banner() {
38
+ return data.banner;
39
+ },
40
+ get accentColor() {
41
+ return data.accent_color ?? void 0;
42
+ },
43
+ get locale() {
44
+ return data.locale;
45
+ },
46
+ get verified() {
47
+ return data.verified;
48
+ },
49
+ get email() {
50
+ return data.email;
51
+ },
52
+ get flags() {
53
+ return data.flags;
54
+ },
55
+ get premiumType() {
56
+ return data.premium_type;
57
+ },
58
+ get publicFlags() {
59
+ return data.public_flags;
60
+ }
61
+ };
62
+ }
63
+
64
+ // src/lib/structures/message.ts
65
+ function createMessage(client, data) {
66
+ let author, mentions, referencedMessage;
67
+ return {
68
+ get client() {
69
+ return client;
70
+ },
71
+ get id() {
72
+ return data.id;
73
+ },
74
+ get channelId() {
75
+ return data.channel_id;
76
+ },
77
+ get author() {
78
+ return author || (author = createUser(client, data.author)), author;
79
+ },
80
+ get content() {
81
+ return data.content;
82
+ },
83
+ get timestamp() {
84
+ return data.timestamp;
85
+ },
86
+ get editedTimestamp() {
87
+ return data.edited_timestamp ?? void 0;
88
+ },
89
+ get tts() {
90
+ return data.tts;
91
+ },
92
+ get mentionEveryone() {
93
+ return data.mention_everyone;
94
+ },
95
+ get mentions() {
96
+ return mentions || (mentions = data.mentions.map((x) => createUser(client, x))), mentions;
97
+ },
98
+ get mentionRoles() {
99
+ return data.mention_roles;
100
+ },
101
+ get nonce() {
102
+ return data.nonce;
103
+ },
104
+ get pinned() {
105
+ return data.pinned;
106
+ },
107
+ get webhookId() {
108
+ return data.webhook_id;
109
+ },
110
+ get type() {
111
+ return data.type;
112
+ },
113
+ get applicationId() {
114
+ return data.application_id;
115
+ },
116
+ get flags() {
117
+ return data.flags;
118
+ },
119
+ get referencedMessage() {
120
+ if (data.referenced_message)
121
+ return referencedMessage || (referencedMessage = createMessage(client, data.referenced_message)), referencedMessage;
122
+ },
123
+ get position() {
124
+ return data.position;
125
+ }
126
+ };
127
+ }
128
+ function createChannel(client, data) {
129
+ switch (data.type) {
130
+ case ChannelType.GuildText:
131
+ return createGuildTextChannel(client, data);
132
+ case ChannelType.DM:
133
+ return createDMChannel(client, data);
134
+ case ChannelType.PublicThread:
135
+ return createPublicThreadChannel(client, data);
136
+ case ChannelType.PrivateThread:
137
+ return createPrivateThreadChannel(client, data);
138
+ case ChannelType.GuildVoice:
139
+ return createVoiceChannel(client, data);
140
+ case ChannelType.GuildStageVoice:
141
+ return createStageChannel(client, data);
142
+ default:
143
+ return createBaseChannel(client, data);
144
+ }
145
+ }
146
+ function createBaseChannel(client, data) {
147
+ return {
148
+ get client() {
149
+ return client;
150
+ },
151
+ get id() {
152
+ return data.id;
153
+ },
154
+ get type() {
155
+ return data.type;
156
+ },
157
+ isTextBased() {
158
+ return data.type === ChannelType.GuildText || data.type === ChannelType.DM || data.type === ChannelType.PublicThread || data.type === ChannelType.PrivateThread;
159
+ },
160
+ isVoiceBased() {
161
+ return data.type === ChannelType.GuildVoice || data.type === ChannelType.GuildStageVoice;
162
+ },
163
+ isGuildBased() {
164
+ return data.type === ChannelType.GuildText || data.type === ChannelType.GuildVoice || data.type === ChannelType.GuildStageVoice || data.type === ChannelType.PublicThread || data.type === ChannelType.PrivateThread;
165
+ },
166
+ isThreadBased() {
167
+ return data.type === ChannelType.PublicThread || data.type === ChannelType.PrivateThread;
168
+ },
169
+ isDm() {
170
+ return data.type === ChannelType.DM;
171
+ },
172
+ isGuildText() {
173
+ return data.type === ChannelType.GuildText;
174
+ },
175
+ isVoice() {
176
+ return data.type === ChannelType.GuildVoice;
177
+ },
178
+ isStage() {
179
+ return data.type === ChannelType.GuildStageVoice;
180
+ },
181
+ isPublicThread() {
182
+ return data.type === ChannelType.PublicThread;
183
+ },
184
+ isPrivateThread() {
185
+ return data.type === ChannelType.PrivateThread;
186
+ }
187
+ };
188
+ }
189
+ function createGuildTextChannel(client, data) {
190
+ return {
191
+ ...createBaseChannel(client, data),
192
+ ...createGuildBasedChannelSingleton(data),
193
+ ...createTextBasedChannelSingleton(client, data)
194
+ };
195
+ }
196
+ function createDMChannel(client, data) {
197
+ let recipients;
198
+ return {
199
+ ...createBaseChannel(client, data),
200
+ ...createTextBasedChannelSingleton(client, data),
201
+ get recipients() {
202
+ if (data.recipients)
203
+ return recipients || (recipients = data.recipients.map((x) => createUser(client, x))), recipients;
204
+ }
205
+ };
206
+ }
207
+ function createPublicThreadChannel(client, data) {
208
+ return {
209
+ ...createBaseChannel(client, data),
210
+ ...createThreadBasedChannelSingleton(client, data)
211
+ };
212
+ }
213
+ function createPrivateThreadChannel(client, data) {
214
+ return {
215
+ ...createBaseChannel(client, data),
216
+ ...createThreadBasedChannelSingleton(client, data)
217
+ };
218
+ }
219
+ function createVoiceChannel(client, data) {
220
+ return {
221
+ ...createBaseChannel(client, data),
222
+ ...createVoiceBasedChannelSingleton(),
223
+ ...createGuildBasedChannelSingleton(data),
224
+ ...createTextBasedChannelSingleton(client, data)
225
+ };
226
+ }
227
+ function createStageChannel(client, data) {
228
+ return {
229
+ ...createBaseChannel(client, data),
230
+ ...createVoiceBasedChannelSingleton(),
231
+ ...createGuildBasedChannelSingleton(data),
232
+ ...createTextBasedChannelSingleton(client, data)
233
+ };
234
+ }
235
+ function createTextBasedChannelSingleton(client, data) {
236
+ return {
237
+ get lastMessageId() {
238
+ return data.last_message_id ?? void 0;
239
+ },
240
+ async send(options) {
241
+ return client.helpers.channel.createMessage(data.id, options);
242
+ }
243
+ };
244
+ }
245
+ function createVoiceBasedChannelSingleton(_client, _data) {
246
+ return {
247
+ async join() {
248
+ }
249
+ };
250
+ }
251
+ function createGuildBasedChannelSingleton(data) {
252
+ return {
253
+ get name() {
254
+ return data.name;
255
+ },
256
+ get guildId() {
257
+ return data.guild_id;
258
+ },
259
+ get parentId() {
260
+ return data.parent_id ?? void 0;
261
+ }
262
+ };
263
+ }
264
+ function createGuildTextBasedChannelSingleton(client, data) {
265
+ return {
266
+ ...createGuildBasedChannelSingleton(data),
267
+ ...createTextBasedChannelSingleton(client, data)
268
+ };
269
+ }
270
+ function createThreadBasedChannelSingleton(client, data) {
271
+ return {
272
+ ...createGuildTextBasedChannelSingleton(client, data),
273
+ get messageCount() {
274
+ return data.message_count;
275
+ },
276
+ get memberCount() {
277
+ return data.member_count;
278
+ },
279
+ get ownerId() {
280
+ return data.owner_id;
281
+ },
282
+ get totalMessageSent() {
283
+ return data.total_message_sent;
284
+ },
285
+ get appliedTags() {
286
+ return data.applied_tags;
287
+ }
288
+ };
289
+ }
290
+
291
+ // src/lib/client/helpers/channel.ts
292
+ function createChannelHelpers(client) {
293
+ return {
294
+ async getById(id) {
295
+ try {
296
+ let data = await client.rest.get(`/channels/${id}`);
297
+ return createChannel(client, data);
298
+ } catch {
299
+ return;
300
+ }
301
+ },
302
+ async createMessage(channelId, options) {
303
+ typeof options == "string" && (options = { content: options });
304
+ let message = await client.rest.post(
305
+ `/channels/${channelId}/messages`,
306
+ {
307
+ content: options.content,
308
+ flags: options.flags
309
+ }
310
+ );
311
+ return createMessage(client, message);
312
+ },
313
+ async deleteMessage(channelId, messageId) {
314
+ await client.rest.delete(`/channels/${channelId}/messages/${messageId}`);
315
+ }
316
+ };
317
+ }
318
+
319
+ // src/lib/client/helpers/user.ts
320
+ function createUserHelpers(client) {
321
+ return {
322
+ async getById(id) {
323
+ try {
324
+ let data = await client.rest.get(`/users/${id}`);
325
+ return createUser(client, data);
326
+ } catch {
327
+ return;
328
+ }
329
+ },
330
+ async getCurrent() {
331
+ let data = await client.rest.get("/users/@me");
332
+ return createUser(client, data);
333
+ }
334
+ };
335
+ }
336
+
337
+ // src/lib/client/helpers/index.ts
338
+ function createHelpers(client) {
339
+ return {
340
+ user: createUserHelpers(client),
341
+ channel: createChannelHelpers(client)
342
+ };
343
+ }
344
+
345
+ // src/lib/client/index.ts
346
+ function createClient(rest) {
347
+ let self = attachEventBus({
348
+ rest,
349
+ helpers: void 0
350
+ });
351
+ return Object.assign(self, createHelpers(self)), self.on("raw", (payload) => {
352
+ switch (payload.t) {
353
+ case GatewayDispatchEvents.MessageCreate:
354
+ self.emit("messageCreate", createMessage(self, payload.d));
355
+ return;
356
+ }
357
+ }), self;
358
+ }
359
+
360
+ export { createBaseChannel, createChannel, createClient, createDMChannel, createGuildBasedChannelSingleton, createGuildTextBasedChannelSingleton, createGuildTextChannel, createMessage, createPrivateThreadChannel, createPublicThreadChannel, createStageChannel, createTextBasedChannelSingleton, createThreadBasedChannelSingleton, createUser, createVoiceBasedChannelSingleton, createVoiceChannel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "A framework for discordeno",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,12 +36,13 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "commander": "^14.0.2",
39
+ "discord-api-types": "^0.38.37",
39
40
  "dotenv": "^17.2.3",
40
41
  "tiny-glob": "^0.2.9",
41
42
  "type-fest": "^4.41.0",
42
- "@bakit/gateway": "^2.1.4",
43
- "@bakit/service": "^3.2.1",
44
43
  "@bakit/rest": "^2.1.0",
44
+ "@bakit/gateway": "^2.1.5",
45
+ "@bakit/service": "^3.2.1",
45
46
  "@bakit/utils": "^2.0.0"
46
47
  },
47
48
  "scripts": {