(sock, message, args, context)
| 27 | description: 'Compress or decompress text/files using Run-Length Encoding (C++ powered)', |
| 28 | usage: '.rle compress <text or reply to media>\n.rle decompress <encoded or reply to compressed file>', |
| 29 | async handler(sock, message, args, context) { |
| 30 | const { chatId, channelInfo } = context; |
| 31 | const quoted = getQuoted(message); |
| 32 | const quotedText = quoted?.conversation || quoted?.extendedTextMessage?.text || ''; |
| 33 | const mediaType = getMediaType(quoted); |
| 34 | if (!args.length) { |
| 35 | return await sock.sendMessage(chatId, { |
| 36 | text: `🗜️ *RLE Compressor*\n\n` + |
| 37 | `*Text:*\n` + |
| 38 | `\`.rle compress AAABBBCCDDDD\`\n` + |
| 39 | `\`.rle decompress <encoded>\`\n\n` + |
| 40 | `*File/Media (reply to any file or media):*\n` + |
| 41 | `\`.rle compress\` — reply to image/video/audio/doc\n` + |
| 42 | `\`.rle decompress\` — reply to .rle compressed file\n\n` + |
| 43 | `⚠️ RLE works best on data with repeated bytes.\n` + |
| 44 | `For photos/videos, compression may increase size.`, |
| 45 | ...channelInfo |
| 46 | }, { quoted: message }); |
| 47 | } |
| 48 | const mode = args[0]?.toLowerCase(); |
| 49 | if (mode !== 'compress' && mode !== 'decompress') { |
| 50 | return await sock.sendMessage(chatId, { |
| 51 | text: `❌ Use \`compress\` or \`decompress\``, |
| 52 | ...channelInfo |
| 53 | }, { quoted: message }); |
| 54 | } |
| 55 | const binPath = path.join(process.cwd(), 'lib', 'bin', 'rle'); |
| 56 | if (!fs.existsSync(binPath)) { |
| 57 | return await sock.sendMessage(chatId, { |
| 58 | text: `❌ RLE binary not available on this server (g++ not installed).`, |
| 59 | ...channelInfo |
| 60 | }, { quoted: message }); |
| 61 | } |
| 62 | const tempDir = path.join(process.cwd(), 'temp'); |
| 63 | fs.mkdirSync(tempDir, { recursive: true }); |
| 64 | const id = Date.now(); |
| 65 | try { |
| 66 | if (mode === 'compress') { |
| 67 | let inputBuffer; |
| 68 | let sourceLabel; |
| 69 | let originalName = `file_${id}`; |
| 70 | if (mediaType && quoted) { |
| 71 | await sock.sendMessage(chatId, { text: '⏳ Downloading media...', ...channelInfo }, { quoted: message }); |
| 72 | const msgObj = { message: { [`${mediaType}Message`]: quoted[`${mediaType}Message`] } }; |
| 73 | inputBuffer = await downloadMediaMessage(msgObj, 'buffer', {}); |
| 74 | sourceLabel = `${mediaType} (${inputBuffer.length.toLocaleString()} bytes)`; |
| 75 | originalName = `${mediaType}_${id}`; |
| 76 | } |
| 77 | else { |
| 78 | const textInput = args.slice(1).join(' ').trim() || quotedText; |
| 79 | if (!textInput) { |
| 80 | return await sock.sendMessage(chatId, { |
| 81 | text: `❌ No input. Provide text or reply to a media message.`, |
| 82 | ...channelInfo |
| 83 | }, { quoted: message }); |
| 84 | } |
| 85 | inputBuffer = Buffer.from(textInput, 'utf8'); |
| 86 | sourceLabel = `text (${inputBuffer.length} bytes)`; |
nothing calls this directly
no test coverage detected