dcsv.js 1.0.0 → 1.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/README.md CHANGED
@@ -11,6 +11,7 @@ dcsv.js is a lightweight, raw-performance focused Discord library designed for m
11
11
 
12
12
  - **Stackless Architecture**: Zero caching. 100% control.
13
13
  - **Auto-Sharding**: Built-in, zero-config sharding. Just set `shards: 'auto'`.
14
+ - **Container UI**: 💎 **Exclusive:** Built-in helper for beautiful, professional "Container" style layouts (Ansi-enhanced).
14
15
  - **Memory Efficient**: Runs 20,000+ server bots on <500MB RAM.
15
16
  - **Raw Events**: Listen to any Discord event directly.
16
17
  - **Interaction Focused**: Optimized for Slash Commands and Buttons.
@@ -93,6 +94,82 @@ dcsv.js emits standard Discord event names as per [Discord API Docs](https://dis
93
94
  - `VOICE_STATE_UPDATE`
94
95
  - ...and all others!
95
96
 
97
+ ## 🍳 Cookbook / Recipes
98
+
99
+ Since **dcsv.js** is stackless, you rely on the **Discord API** for data. Here are common patterns:
100
+
101
+ ### 1. Fetching User Banner
102
+ We don't cache users. To get a banner, fetch the user profile dynamically.
103
+
104
+ ```javascript
105
+ // GET /users/{id}
106
+ const user = await client.request('GET', `/users/${userId}`);
107
+
108
+ if (user.banner) {
109
+ const ext = user.banner.startsWith('a_') ? 'gif' : 'png';
110
+ const url = `https://cdn.discordapp.com/banners/${user.id}/${user.banner}.${ext}?size=1024`;
111
+ console.log(url);
112
+ }
113
+ ```
114
+
115
+ ### 2. Fetching Server Details
116
+ Need member counts? Ask the API.
117
+
118
+ ```javascript
119
+ // GET /guilds/{id}?with_counts=true
120
+ const guild = await client.request('GET', `/guilds/${guildId}?with_counts=true`);
121
+
122
+ console.log(`Server: ${guild.name}`);
123
+ console.log(`Members: ${guild.approximate_member_count}`);
124
+ console.log(`Online: ${guild.approximate_presence_count}`);
125
+ ```
126
+
127
+ ### 3. Sending an Embed
128
+ We support standard Discord Embed objects.
129
+
130
+ ```javascript
131
+ await client.createMessage(channelId, {
132
+ content: "Here is your info:",
133
+ embeds: [{
134
+ title: "Hello World",
135
+ color: 0x00FF00, // Hex Color
136
+ description: "This is a stackless embed.",
137
+ fields: [
138
+ { name: "Field 1", value: "Value 1", inline: true }
139
+ ]
140
+ }]
141
+ });
142
+ ```
143
+
144
+ ### 4. Handling Buttons (Interactions)
145
+ ```javascript
146
+ client.on('interactionCreate', async (interaction) => {
147
+ if (interaction.isButton()) {
148
+ if (interaction.customId === 'click_me') {
149
+ await interaction.reply({
150
+ content: "You clicked the button!",
151
+ flags: 64 // Ephemeral (Hidden)
152
+ });
153
+ }
154
+ }
155
+ });
156
+ ```
157
+
158
+ ### 5. ✨ Exclusive: Create Container Message
159
+ Build professional, modern UIs instantly.
160
+
161
+ ```javascript
162
+ await client.createContainer(channelId, {
163
+ title: "SERVER STATUS",
164
+ color: 0x5865F2, // Blurple
165
+ sections: [
166
+ { title: "Performance", content: " [32mStable [0m" },
167
+ { title: "Uptime", content: " [34m99.9% [0m", inline: true }
168
+ ],
169
+ footer: "Powered by dcsv.js"
170
+ });
171
+ ```
172
+
96
173
  ## 🤝 Contributing
97
174
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
98
175
 
@@ -0,0 +1,82 @@
1
+ const { Client, GatewayIntentBits } = require('../index');
2
+
3
+ // 1. Setup Client
4
+ const client = new Client({
5
+ intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent | GatewayIntentBits.GuildMembers,
6
+ shards: 'auto',
7
+ debug: true
8
+ });
9
+
10
+ client.on('ready', () => {
11
+ console.log(`logged in as ${client.user.username}`);
12
+ });
13
+
14
+ client.on('messageCreate', async (msg) => {
15
+ if (msg.author.bot) return;
16
+
17
+ // EXAMPLE 1: Fetching User Banner (Stackless)
18
+ // Since we don't cache users, we fetch fresh data from API
19
+ if (msg.content === '!banner') {
20
+ try {
21
+ // Raw API Call: GET /users/{id}
22
+ const user = await client.request('GET', `/users/${msg.author.id}`);
23
+
24
+ if (user.banner) {
25
+ // Construct CDN URL
26
+ const extension = user.banner.startsWith('a_') ? 'gif' : 'png';
27
+ const url = `https://cdn.discordapp.com/banners/${user.id}/${user.banner}.${extension}?size=512`;
28
+
29
+ await client.createMessage(msg.channel_id, {
30
+ content: `Here is your banner: ${url}`
31
+ });
32
+ } else {
33
+ await client.createMessage(msg.channel_id, { content: 'You have no banner set.' });
34
+ }
35
+ } catch (err) {
36
+ console.error(err);
37
+ }
38
+ }
39
+
40
+ // EXAMPLE 2: Fetching Server Details (Stackless)
41
+ if (msg.content === '!serverinfo') {
42
+ try {
43
+ // We can use the helper client.getGuild() or raw request
44
+ // with_counts=true key to get exact member counts
45
+ const guild = await client.request('GET', `/guilds/${msg.guild_id}?with_counts=true`);
46
+
47
+ const embed = {
48
+ title: guild.name,
49
+ description: guild.description || 'No description',
50
+ fields: [
51
+ { name: 'Owner ID', value: guild.owner_id, inline: true },
52
+ { name: 'Members', value: String(guild.approximate_member_count), inline: true },
53
+ { name: 'Boosts', value: String(guild.premium_subscription_count), inline: true }
54
+ ],
55
+ thumbnail: {
56
+ url: guild.icon ? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.png` : null
57
+ }
58
+ };
59
+
60
+ await client.createMessage(msg.channel_id, { embeds: [embed] });
61
+ } catch (err) {
62
+ console.error(err);
63
+ }
64
+ }
65
+ });
66
+
67
+ // EXAMPLE 3: Handling Raw Events (e.g., specific reaction add)
68
+ client.on('MESSAGE_REACTION_ADD', async (event) => {
69
+ // event contains { user_id, channel_id, message_id, emoji ... }
70
+ console.log(`User ${event.user_id} reacted with ${event.emoji.name}`);
71
+
72
+ // We can interact immediately without fetching the message object!
73
+ if (event.emoji.name === '⭐') {
74
+ await client.createMessage(event.channel_id, {
75
+ content: `<@${event.user_id}> you starred a message!`
76
+ });
77
+ }
78
+ });
79
+
80
+
81
+ //client.login('TOKEN');
82
+ console.log("Edit this file and add your token to test!");
package/index.js CHANGED
@@ -370,6 +370,44 @@ class Client extends EventEmitter {
370
370
  this.emit('raw', { event, data, shardId: shard.id });
371
371
  }
372
372
 
373
+ /**
374
+ * DCSV Exclusive: Create a "Container" style message
375
+ * Auto-formats a modern Discord UI using native Embeds
376
+ * @param {string} channelId
377
+ * @param {Object} options { title, color, sections: [{ title, content, inline }] }
378
+ */
379
+ async createContainer(channelId, options) {
380
+ const embed = {
381
+ title: options.title,
382
+ color: options.color || 0x2f3136, // Standard Dark
383
+ description: options.description || null,
384
+ fields: [],
385
+ footer: options.footer ? { text: options.footer } : null,
386
+ timestamp: options.timestamp ? new Date().toISOString() : null
387
+ };
388
+
389
+ if (options.sections) {
390
+ for (const section of options.sections) {
391
+ // Add separator if needed
392
+ if (embed.fields.length > 0) {
393
+ embed.fields.push({ name: '\u200b', value: '\u200b', inline: false });
394
+ }
395
+
396
+ embed.fields.push({
397
+ name: section.title.toUpperCase(),
398
+ value: `\`\`\`ansi\n${section.content}\n\`\`\``,
399
+ inline: section.inline || false
400
+ });
401
+ }
402
+ }
403
+
404
+ return this.createMessage(channelId, {
405
+ content: options.content || null,
406
+ embeds: [embed],
407
+ components: options.components || []
408
+ });
409
+ }
410
+
373
411
  async request(method, endpoint, body = null, retries = 0) {
374
412
  await this.rateLimiter.wait(endpoint);
375
413
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dcsv.js",
3
- "version": "1.0.0",
4
- "description": "Ultra High Performance, Stackless Discord Interaction Library. Optimized for low memory usage and high scale.",
3
+ "version": "1.1.0",
4
+ "description": "Ultra High Performance, Stackless Discord Library + Container UI System",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -27,4 +27,4 @@
27
27
  "type": "git",
28
28
  "url": "https://github.com/dcsv-project/dcsv.js"
29
29
  }
30
- }
30
+ }