fluxer.ts 0.1.0 → 0.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/README.md CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  Lightweight, TypeScript-first SDK for building [Fluxer](https://fluxer.gg) bots.
4
4
 
5
- - **Small** — single package, one dependency (`ws`), ~22KB compiled
6
- - **TypeScript-first** — full type definitions, no `any`
5
+ - **Small** — single package, one dependency (`ws`), ~60KB compiled
6
+ - **TypeScript-first** — 870+ lines of type definitions generated from the Fluxer OpenAPI spec
7
7
  - **Simple API** — connect, listen, send — no unnecessary abstractions
8
8
  - **Built for Fluxer** — handles Fluxer-specific gateway behavior (guild `properties`, v1 gateway protocol)
9
+ - **Complete** — 94 route builders, 40+ gateway events, 65 convenience methods
9
10
 
10
11
  ## Install
11
12
 
@@ -48,86 +49,261 @@ await client.sendMessage(channelId, 'Hello!');
48
49
  // Send with embeds
49
50
  await client.sendMessage(channelId, {
50
51
  content: 'Check this out',
51
- embeds: [{ title: 'My Embed', description: 'Content here', color: 0x7c6fff }],
52
+ embeds: [{ type: 'rich', title: 'My Embed', description: 'Content here', color: 0x7c6fff }],
52
53
  });
53
54
 
54
55
  // Reply to a message
55
56
  await client.replyTo(message, 'Got it!');
56
57
 
57
- // Edit a message
58
+ // Edit / delete
58
59
  await client.editMessage(channelId, messageId, 'Updated content');
59
-
60
- // Delete a message
61
60
  await client.deleteMessage(channelId, messageId);
62
61
 
63
- // React
64
- await client.react(channelId, messageId, '👍');
62
+ // Bulk delete (2-100 messages)
63
+ await client.bulkDelete(channelId, messageIds);
64
+
65
+ // Fetch messages
66
+ const messages = await client.fetchMessages(channelId, { limit: 50 });
67
+ const single = await client.fetchMessage(channelId, messageId);
65
68
 
66
69
  // Typing indicator
67
70
  await client.sendTyping(channelId);
68
71
  ```
69
72
 
73
+ ### Reactions
74
+
75
+ ```typescript
76
+ // Add / remove reactions
77
+ await client.react(channelId, messageId, '👍');
78
+ await client.unreact(channelId, messageId, '👍');
79
+
80
+ // Remove another user's reaction
81
+ await client.removeReaction(channelId, messageId, '👍', userId);
82
+
83
+ // Remove all reactions
84
+ await client.removeAllReactions(channelId, messageId);
85
+ await client.removeAllReactionsForEmoji(channelId, messageId, '👍');
86
+
87
+ // Fetch who reacted
88
+ const users = await client.fetchReactions(channelId, messageId, '👍');
89
+ ```
90
+
91
+ ### Pins
92
+
93
+ ```typescript
94
+ await client.pinMessage(channelId, messageId);
95
+ await client.unpinMessage(channelId, messageId);
96
+ const pins = await client.fetchPinnedMessages(channelId);
97
+ ```
98
+
70
99
  ### Guilds
71
100
 
72
101
  ```typescript
73
- // Access cached guilds (populated on connect)
102
+ // Fetch guild info
103
+ const guild = await client.fetchGuild(guildId);
104
+
105
+ // Edit guild
106
+ await client.editGuild(guildId, { name: 'New Name' });
107
+
108
+ // Access cached guilds
74
109
  for (const [id, guild] of client.guilds) {
75
110
  console.log(guild.name);
76
111
  }
77
112
 
113
+ // Audit log
114
+ const log = await client.fetchAuditLog(guildId, { limit: 50 });
115
+
116
+ // Vanity URL
117
+ const vanity = await client.fetchVanityUrl(guildId);
118
+ ```
119
+
120
+ ### Members
121
+
122
+ ```typescript
78
123
  // Fetch members
79
- const members = await client.fetchMembers(guildId);
124
+ const members = await client.fetchMembers(guildId, { limit: 100 });
125
+ const member = await client.fetchMember(guildId, userId);
80
126
 
81
- // Fetch roles
82
- const roles = await client.fetchRoles(guildId);
127
+ // Edit member
128
+ await client.editMember(guildId, userId, { nick: 'Cool Name' });
129
+
130
+ // Kick
131
+ await client.kickMember(guildId, userId);
83
132
 
84
133
  // Set bot nickname
85
- await client.setNickname(guildId, 'Cool Bot');
134
+ await client.setNickname(guildId, 'Bot Name');
86
135
  ```
87
136
 
88
- ### Interactions (Slash Commands)
137
+ ### Roles
89
138
 
90
139
  ```typescript
91
- import { InteractionCallbackType } from 'fluxer.ts';
140
+ const roles = await client.fetchRoles(guildId);
92
141
 
93
- // Register commands
94
- await client.registerCommands(applicationId, [
95
- { name: 'ping', description: 'Pong!' },
96
- ]);
142
+ // Create / edit / delete
143
+ const role = await client.createRole(guildId, { name: 'Moderator', color: 0x3498db });
144
+ await client.editRole(guildId, roleId, { name: 'Admin' });
145
+ await client.deleteRole(guildId, roleId);
97
146
 
98
- // Handle interactions
99
- client.on('interactionCreate', async (interaction) => {
100
- if (interaction.data?.name === 'ping') {
101
- await client.respondToInteraction(
102
- interaction.id,
103
- interaction.token,
104
- InteractionCallbackType.ChannelMessageWithSource,
105
- { content: 'Pong!' },
106
- );
107
- }
147
+ // Add / remove from member
148
+ await client.addRole(guildId, userId, roleId);
149
+ await client.removeRole(guildId, userId, roleId);
150
+ ```
151
+
152
+ ### Bans
153
+
154
+ ```typescript
155
+ await client.banMember(guildId, userId, { reason: 'Rule violation' });
156
+ await client.unbanMember(guildId, userId);
157
+ const bans = await client.fetchBans(guildId);
158
+ ```
159
+
160
+ ### Channels
161
+
162
+ ```typescript
163
+ const channel = await client.fetchChannel(channelId);
164
+ const guildChannels = await client.fetchGuildChannels(guildId);
165
+
166
+ // Create / edit / delete
167
+ const ch = await client.createChannel(guildId, { name: 'general', type: 0 });
168
+ await client.editChannel(channelId, { topic: 'Updated topic' });
169
+ await client.deleteChannel(channelId);
170
+
171
+ // Permission overwrites
172
+ await client.editPermission(channelId, roleId, { type: 0, allow: '1024', deny: '0' });
173
+ await client.deletePermission(channelId, roleId);
174
+ ```
175
+
176
+ ### Emojis & Stickers
177
+
178
+ ```typescript
179
+ const emojis = await client.fetchEmojis(guildId);
180
+ const emoji = await client.createEmoji(guildId, { name: 'cool', image: 'data:image/png;base64,...' });
181
+ await client.editEmoji(guildId, emojiId, { name: 'cooler' });
182
+ await client.deleteEmoji(guildId, emojiId);
183
+
184
+ const stickers = await client.fetchStickers(guildId);
185
+ const sticker = await client.createSticker(guildId, {
186
+ name: 'cool', description: 'A cool sticker', tags: 'cool',
187
+ file: { name: 'sticker.png', data: stickerBuffer },
108
188
  });
189
+ await client.editSticker(guildId, stickerId, { name: 'cooler' });
190
+ await client.deleteSticker(guildId, stickerId);
191
+ ```
192
+
193
+ ### Invites
194
+
195
+ ```typescript
196
+ const invite = await client.createInvite(channelId, { max_age: 86400 });
197
+ const channelInvites = await client.fetchChannelInvites(channelId);
198
+ const guildInvites = await client.fetchGuildInvites(guildId);
199
+ const info = await client.fetchInvite('abc123');
200
+ await client.deleteInvite('abc123');
201
+ ```
202
+
203
+ ### Webhooks
204
+
205
+ ```typescript
206
+ const webhook = await client.createWebhook(channelId, { name: 'My Webhook' });
207
+ await client.editWebhook(webhookId, { name: 'Updated' });
208
+ await client.executeWebhook(webhookId, token, 'Hello from webhook!');
209
+ await client.deleteWebhook(webhookId);
210
+
211
+ const channelHooks = await client.fetchChannelWebhooks(channelId);
212
+ const guildHooks = await client.fetchGuildWebhooks(guildId);
213
+ ```
214
+
215
+ ### Users
216
+
217
+ ```typescript
218
+ const user = await client.fetchUser(userId);
219
+ const dm = await client.createDM(userId);
220
+ await client.sendMessage(dm.id, 'Hello!');
221
+ ```
222
+
223
+ ### Lifecycle
224
+
225
+ ```typescript
226
+ // Connect
227
+ await client.login('your-bot-token');
228
+
229
+ // Leave a guild
230
+ await client.leaveGuild(guildId);
231
+
232
+ // Disconnect
233
+ client.destroy();
109
234
  ```
110
235
 
111
236
  ### Events
112
237
 
113
238
  ```typescript
239
+ // Session
114
240
  client.on('ready', (user, guilds) => { });
241
+
242
+ // Messages
115
243
  client.on('messageCreate', (message) => { });
116
244
  client.on('messageUpdate', (message) => { });
117
245
  client.on('messageDelete', ({ id, channel_id }) => { });
118
- client.on('interactionCreate', (interaction) => { });
246
+ client.on('messageDeleteBulk', ({ ids, channel_id }) => { });
247
+
248
+ // Reactions
249
+ client.on('messageReactionAdd', (data) => { });
250
+ client.on('messageReactionRemove', (data) => { });
251
+ client.on('messageReactionRemoveAll', (data) => { });
252
+ client.on('messageReactionRemoveEmoji', (data) => { });
253
+
254
+ // Guilds
119
255
  client.on('guildCreate', (guild) => { });
256
+ client.on('guildUpdate', (guild) => { });
120
257
  client.on('guildDelete', ({ id }) => { });
258
+
259
+ // Members
121
260
  client.on('guildMemberAdd', (member) => { });
261
+ client.on('guildMemberUpdate', (member) => { });
122
262
  client.on('guildMemberRemove', ({ guild_id, user }) => { });
263
+
264
+ // Roles
265
+ client.on('guildRoleCreate', ({ guild_id, role }) => { });
266
+ client.on('guildRoleUpdate', ({ guild_id, role }) => { });
267
+ client.on('guildRoleDelete', ({ guild_id, role_id }) => { });
268
+ client.on('guildRoleUpdateBulk', ({ guild_id, roles }) => { });
269
+
270
+ // Bans
271
+ client.on('guildBanAdd', ({ guild_id, user }) => { });
272
+ client.on('guildBanRemove', ({ guild_id, user }) => { });
273
+
274
+ // Emojis & Stickers
275
+ client.on('guildEmojisUpdate', ({ guild_id, emojis }) => { });
276
+ client.on('guildStickersUpdate', ({ guild_id, stickers }) => { });
277
+
278
+ // Channels
123
279
  client.on('channelCreate', (channel) => { });
124
280
  client.on('channelUpdate', (channel) => { });
281
+ client.on('channelUpdateBulk', (channels) => { });
125
282
  client.on('channelDelete', (channel) => { });
126
- client.on('messageReactionAdd', (data) => { });
127
- client.on('messageReactionRemove', (data) => { });
283
+ client.on('channelPinsUpdate', (data) => { });
284
+
285
+ // Invites
286
+ client.on('inviteCreate', ({ code, channel_id }) => { });
287
+ client.on('inviteDelete', ({ code, channel_id }) => { });
288
+
289
+ // Webhooks
290
+ client.on('webhooksUpdate', ({ guild_id, channel_id }) => { });
291
+
292
+ // Voice
293
+ client.on('voiceStateUpdate', (state) => { });
294
+ client.on('voiceServerUpdate', (data) => { });
295
+
296
+ // Typing & Presence
128
297
  client.on('typingStart', (data) => { });
298
+ client.on('presenceUpdate', (data) => { });
299
+ client.on('userUpdate', (user) => { });
300
+
301
+ // System
129
302
  client.on('error', (error) => { });
130
303
  client.on('debug', (message) => { });
304
+
305
+ // Raw — any unhandled gateway event
306
+ client.on('raw', (event, data) => { });
131
307
  ```
132
308
 
133
309
  ### REST API (Direct)
@@ -154,15 +330,28 @@ const intents = GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIn
154
330
  const client = new Client({ intents: IntentsAll });
155
331
  ```
156
332
 
333
+ ## Type Generation
334
+
335
+ Types are auto-generated from the Fluxer OpenAPI spec:
336
+
337
+ ```bash
338
+ node tools/generate-types.mjs > src/types.generated.ts
339
+ ```
340
+
341
+ The generator reads `reference/openapi.json` and outputs TypeScript interfaces and enums for all bot-relevant API objects. Modify `tools/generate-types.mjs` to add schemas or change mappings.
342
+
157
343
  ## How it differs from @fluxerjs/core
158
344
 
159
345
  | | fluxer.ts | @fluxerjs/core |
160
346
  |---|---|---|
161
- | Size | ~22KB | ~809KB |
347
+ | Size | ~60KB | ~809KB |
162
348
  | Packages | 1 | 7 (monorepo) |
163
349
  | Dependencies | 1 (ws) | 6 |
164
350
  | TypeScript | Source + declarations | Declarations only |
165
351
  | Fluxer-specific | Yes (properties, v1 gateway) | Discord.js port |
352
+ | API types | Generated from OpenAPI spec | Manual |
353
+ | Events | 40+ | Unknown |
354
+ | Client methods | 65 | Unknown |
166
355
 
167
356
  ## License
168
357