@roidev/kachina-md 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Roynaldi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # @kachina-md/core
2
+
3
+ WhatsApp Bot Framework - Simple, Fast, and Modular
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@kachina-md/core.svg)](https://www.npmjs.com/package/@kachina-md/core)
6
+ [![License](https://img.shields.io/npm/l/@kachina-md/core.svg)](https://github.com/your-username/kachina-core/blob/main/LICENSE)
7
+
8
+ ## 🚀 Features
9
+
10
+ - ✨ Simple and clean API
11
+ - 🔌 Plugin system with auto-loading
12
+ - 📦 Built-in database (LowDB)
13
+ - 🎯 Event-driven architecture
14
+ - 📱 Dual login method (QR Code & Pairing Code)
15
+ - 🛠️ Rich helper utilities
16
+ - 📝 TypeScript-ready
17
+ - 🔄 Auto-reconnect
18
+ - 💾 Message serialization
19
+
20
+ ## 📦 Installation
21
+
22
+ ```bash
23
+ npm install @kachina-md/core
24
+ ```
25
+
26
+ ## 🎯 Quick Start
27
+
28
+ ### Basic Usage
29
+
30
+ ```javascript
31
+ import { Client } from '@kachina-md/core';
32
+
33
+ const bot = new Client({
34
+ sessionId: 'my-session',
35
+ prefix: '!',
36
+ owner: ['628xxx']
37
+ });
38
+
39
+ bot.on('ready', (user) => {
40
+ console.log('Bot is ready!', user.id);
41
+ });
42
+
43
+ bot.on('message', async (m) => {
44
+ if (m.body === '!ping') {
45
+ await m.reply('Pong! 🏓');
46
+ }
47
+ });
48
+
49
+ await bot.start();
50
+ ```
51
+
52
+ ### With Plugins
53
+
54
+ ```javascript
55
+ import { Client } from '@kachina-md/core';
56
+ import path from 'path';
57
+
58
+ const bot = new Client({
59
+ sessionId: 'my-session',
60
+ prefix: '!',
61
+ owner: ['628xxx']
62
+ });
63
+
64
+ // Load plugins from directory
65
+ await bot.loadPlugins(path.join(process.cwd(), 'plugins'));
66
+
67
+ await bot.start();
68
+ ```
69
+
70
+ ## 🔌 Plugin System
71
+
72
+ ### Creating a Plugin
73
+
74
+ Create a file in `plugins/` directory:
75
+
76
+ ```javascript
77
+ // plugins/hello.js
78
+
79
+ export default {
80
+ name: 'hello',
81
+ commands: ['hello', 'hi'],
82
+ category: 'fun',
83
+ description: 'Say hello',
84
+
85
+ async exec({ m, args }) {
86
+ await m.reply(`Hello ${m.pushName}! 👋`);
87
+ }
88
+ };
89
+ ```
90
+
91
+ ### Plugin Structure
92
+
93
+ ```javascript
94
+ export default {
95
+ // Plugin metadata
96
+ name: 'plugin-name', // Required
97
+ commands: ['cmd1', 'cmd2'], // Command aliases
98
+ category: 'category', // Plugin category
99
+ description: 'Description', // Help text
100
+
101
+ // Plugin flags
102
+ owner: false, // Owner only
103
+ group: false, // Group only
104
+ private: false, // Private chat only
105
+ admin: false, // Group admin only
106
+ botAdmin: false, // Bot must be admin
107
+
108
+ // Execution function
109
+ async exec({ client, m, args, command, prefix, sock }) {
110
+ // Your code here
111
+ }
112
+ };
113
+ ```
114
+
115
+ ### Plugin Parameters
116
+
117
+ | Parameter | Type | Description |
118
+ |-----------|------|-------------|
119
+ | `client` | Client | Bot client instance |
120
+ | `m` | Message | Serialized message object |
121
+ | `args` | Array | Command arguments |
122
+ | `command` | String | Command name used |
123
+ | `prefix` | String | Command prefix |
124
+ | `sock` | Socket | Baileys socket |
125
+
126
+ ## 📝 Message Object
127
+
128
+ The serialized message object (`m`) includes:
129
+
130
+ ### Properties
131
+
132
+ ```javascript
133
+ m.key // Message key
134
+ m.chat // Chat ID
135
+ m.sender // Sender ID
136
+ m.pushName // Sender push name
137
+ m.body // Message text
138
+ m.type // Message type
139
+ m.isGroup // Is from group
140
+ m.fromMe // Is from bot
141
+ m.quoted // Quoted message (if any)
142
+ m.mentions // Mentioned JIDs
143
+ ```
144
+
145
+ ### Methods
146
+
147
+ ```javascript
148
+ // Reply to message
149
+ await m.reply('Text')
150
+
151
+ // React to message
152
+ await m.react('👍')
153
+
154
+ // Download media
155
+ const buffer = await m.download()
156
+
157
+ // Delete message
158
+ await m.delete()
159
+
160
+ // Forward message
161
+ await m.forward(jid)
162
+ ```
163
+
164
+ ## 🛠️ Client API
165
+
166
+ ### Methods
167
+
168
+ ```javascript
169
+ // Send messages
170
+ await bot.sendText(jid, 'Hello')
171
+
172
+ // Send media
173
+ await bot.sendImage(jid, buffer, 'Caption', { /* options */ })
174
+ await bot.sendVideo(jid, buffer, 'Caption', { /* options */ })
175
+ await bot.sendAudio(jid, buffer, { mimetype: 'audio/mp4', ptt: false })
176
+ await bot.sendDocument(jid, buffer, 'file.pdf', 'application/pdf')
177
+ await bot.sendSticker(jid, buffer)
178
+
179
+ // Send other content
180
+ await bot.sendContact(jid, [{ displayName: 'John', vcard: '...' }])
181
+ await bot.sendLocation(jid, latitude, longitude)
182
+ await bot.sendPoll(jid, 'Question?', ['Option 1', 'Option 2'])
183
+ await bot.sendReact(jid, messageKey, '👍')
184
+
185
+ // Group methods
186
+ await bot.groupMetadata(jid)
187
+ await bot.groupParticipantsUpdate(jid, [participant], 'add|remove|promote|demote')
188
+ await bot.groupUpdateSubject(jid, 'New Subject')
189
+ await bot.groupUpdateDescription(jid, 'New Description')
190
+
191
+ // Plugin methods
192
+ await bot.loadPlugin('./plugins/my-plugin.js')
193
+ await bot.loadPlugins('./plugins')
194
+ ```
195
+
196
+ ### Events
197
+
198
+ ```javascript
199
+ bot.on('ready', (user) => {
200
+ // Bot is ready
201
+ })
202
+
203
+ bot.on('message', async (m) => {
204
+ // New message
205
+ })
206
+
207
+ bot.on('group.update', (update) => {
208
+ // Group participants update
209
+ })
210
+
211
+ bot.on('pairing.code', (code) => {
212
+ // Pairing code (when using pairing method)
213
+ })
214
+
215
+ bot.on('reconnecting', () => {
216
+ // Reconnecting
217
+ })
218
+
219
+ bot.on('logout', () => {
220
+ // Bot logged out
221
+ })
222
+ ```
223
+
224
+ ## 💾 Database
225
+
226
+ ```javascript
227
+ import { Database } from '@kachina-md/core';
228
+
229
+ const db = new Database({ path: './database' });
230
+
231
+ // Basic operations
232
+ await db.set('users', 'user123', { name: 'John', balance: 100 })
233
+ await db.get('users', 'user123')
234
+ await db.has('users', 'user123')
235
+ await db.delete('users', 'user123')
236
+ await db.all('users')
237
+
238
+ // Advanced operations
239
+ await db.update('users', 'user123', { balance: 200 })
240
+ await db.increment('users', 'user123', 'balance', 50)
241
+ await db.push('users', 'user123.items', 'item1')
242
+ ```
243
+
244
+ ## 🔧 Helpers
245
+
246
+ ```javascript
247
+ import {
248
+ formatTime,
249
+ formatBytes,
250
+ parseCommand,
251
+ isUrl,
252
+ extractUrls,
253
+ randomString,
254
+ randomNumber,
255
+ pickRandom,
256
+ chunk,
257
+ createSticker,
258
+ createFullSticker,
259
+ createCroppedSticker,
260
+ createCircleSticker,
261
+ createRoundedSticker,
262
+ StickerTypes
263
+ } from '@kachina-md/core';
264
+
265
+ // Format utilities
266
+ formatTime(3600) // "1h 0m 0s"
267
+ formatBytes(1024) // "1 KB"
268
+
269
+ // String utilities
270
+ parseCommand('!ping test') // { command: 'ping', args: ['test'], text: 'test' }
271
+ isUrl('https://...') // true
272
+ extractUrls(text) // Array of URLs
273
+
274
+ // Random utilities
275
+ randomString(10) // Random string
276
+ randomNumber(1, 100) // Random number
277
+ pickRandom([1,2,3]) // Random item from array
278
+ chunk([1,2,3,4], 2) // [[1,2], [3,4]]
279
+
280
+ // Sticker utilities
281
+ const stickerBuffer = await createSticker(imageBuffer, {
282
+ pack: 'My Pack',
283
+ author: 'My Name',
284
+ type: StickerTypes.FULL,
285
+ quality: 50
286
+ })
287
+
288
+ // Sticker type shortcuts
289
+ await createFullSticker(buffer, options) // Full size
290
+ await createCroppedSticker(buffer, options) // Cropped
291
+ await createCircleSticker(buffer, options) // Circle
292
+ await createRoundedSticker(buffer, options) // Rounded
293
+ ```
294
+
295
+ ## 📚 Examples
296
+
297
+ ### Example 1: Simple Command
298
+
299
+ ```javascript
300
+ export default {
301
+ name: 'dice',
302
+ commands: ['dice', 'roll'],
303
+ category: 'fun',
304
+ description: 'Roll a dice',
305
+
306
+ async exec({ m }) {
307
+ const result = Math.floor(Math.random() * 6) + 1;
308
+ await m.reply(`🎲 You rolled: ${result}`);
309
+ }
310
+ };
311
+ ```
312
+
313
+ ### Example 2: With Arguments
314
+
315
+ ```javascript
316
+ export default {
317
+ name: 'say',
318
+ commands: ['say', 'echo'],
319
+ category: 'fun',
320
+ description: 'Repeat your message',
321
+
322
+ async exec({ m, args }) {
323
+ if (args.length === 0) {
324
+ return await m.reply('⚠️ Provide text to repeat!');
325
+ }
326
+
327
+ await m.reply(args.join(' '));
328
+ }
329
+ };
330
+ ```
331
+
332
+ ### Example 3: Owner Only
333
+
334
+ ```javascript
335
+ export default {
336
+ name: 'broadcast',
337
+ commands: ['bc', 'broadcast'],
338
+ category: 'owner',
339
+ description: 'Broadcast message',
340
+ owner: true,
341
+
342
+ async exec({ client, m, args }) {
343
+ const text = args.join(' ');
344
+ const chats = await client.sock.getChats();
345
+
346
+ for (const chat of chats) {
347
+ await client.sendText(chat.id, text);
348
+ }
349
+
350
+ await m.reply(`✅ Broadcasted to ${chats.length} chats`);
351
+ }
352
+ };
353
+ ```
354
+
355
+ ### Example 4: Group Only
356
+
357
+ ```javascript
358
+ export default {
359
+ name: 'tagall',
360
+ commands: ['tagall', 'everyone'],
361
+ category: 'group',
362
+ description: 'Mention all members',
363
+ group: true,
364
+ admin: true,
365
+
366
+ async exec({ client, m }) {
367
+ const metadata = await client.groupMetadata(m.chat);
368
+ const participants = metadata.participants.map(p => p.id);
369
+
370
+ const text = '📢 Attention everyone!\n\n' +
371
+ participants.map(p => `@${p.split('@')[0]}`).join('\n');
372
+
373
+ await client.sendMessage(m.chat, {
374
+ text,
375
+ mentions: participants
376
+ });
377
+ }
378
+ };
379
+ ```
380
+
381
+ ### Example 5: With Database
382
+
383
+ ```javascript
384
+ import { Database } from '@kachina-md/core';
385
+ const db = new Database();
386
+
387
+ export default {
388
+ name: 'balance',
389
+ commands: ['balance', 'bal'],
390
+ category: 'economy',
391
+ description: 'Check your balance',
392
+
393
+ async exec({ m }) {
394
+ const userId = m.sender;
395
+ const user = await db.get('users', userId, { balance: 0 });
396
+
397
+ await m.reply(`💰 Your balance: $${user.balance}`);
398
+ }
399
+ };
400
+ ```
401
+
402
+ ## 🔐 Configuration
403
+
404
+ ```javascript
405
+ const bot = new Client({
406
+ // Session
407
+ sessionId: 'my-session', // Session folder name
408
+ phoneNumber: '628xxx', // For pairing code
409
+
410
+ // Login
411
+ loginMethod: 'qr', // 'qr' or 'pairing'
412
+ printQRInTerminal: true, // Print QR in terminal
413
+
414
+ // Bot config
415
+ prefix: '!', // Command prefix
416
+ owner: ['628xxx', '628yyy'], // Owner numbers
417
+
418
+ // Advanced
419
+ browser: ['Bot', 'Chrome', '1.0.0'],
420
+ logger: pino({ level: 'silent' })
421
+ });
422
+ ```
423
+
424
+ ## 📦 Project Structure
425
+
426
+ ```
427
+ my-bot/
428
+ ├── plugins/
429
+ │ ├── ping.js
430
+ │ ├── help.js
431
+ │ └── ...
432
+ ├── database/
433
+ │ ├── users.json
434
+ │ └── groups.json
435
+ ├── my-session/
436
+ │ └── creds.json
437
+ ├── index.js
438
+ └── package.json
439
+ ```
440
+
441
+ ## 🤝 Contributing
442
+
443
+ Contributions are welcome! Please feel free to submit a Pull Request.
444
+
445
+ ## 📄 License
446
+
447
+ MIT © Roynaldi
448
+
449
+ ## 🔗 Links
450
+
451
+ - [Baileys](https://github.com/WhiskeySockets/Baileys) - WhatsApp Web API
452
+ - [NPM Package](https://www.npmjs.com/package/@kachina-md/core)
453
+ - [GitHub](https://github.com/your-username/kachina-core)
454
+
455
+ ## ⚠️ Disclaimer
456
+
457
+ This project is not affiliated with WhatsApp. Use at your own risk. Do not spam or violate WhatsApp Terms of Service.
458
+
459
+ ---
460
+
461
+ Made with ❤️ by Roynaldi