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