(sock, chatId, message)
| 1 | const axios = require('axios'); |
| 2 | |
| 3 | async function soraCommand(sock, chatId, message) { |
| 4 | try { |
| 5 | const rawText = message.message?.conversation?.trim() || |
| 6 | message.message?.extendedTextMessage?.text?.trim() || |
| 7 | message.message?.imageMessage?.caption?.trim() || |
| 8 | message.message?.videoMessage?.caption?.trim() || |
| 9 | ''; |
| 10 | |
| 11 | // Extract prompt after command keyword or use quoted text |
| 12 | const used = (rawText || '').split(/\s+/)[0] || '.sora'; |
| 13 | const args = rawText.slice(used.length).trim(); |
| 14 | const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 15 | const quotedText = quoted?.conversation || quoted?.extendedTextMessage?.text || ''; |
| 16 | const input = args || quotedText; |
| 17 | |
| 18 | if (!input) { |
| 19 | await sock.sendMessage(chatId, { text: 'Provide a prompt. Example: .sora anime girl with short blue hair' }, { quoted: message }); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | const apiUrl = `https://okatsu-rolezapiiz.vercel.app/ai/txt2video?text=${encodeURIComponent(input)}`; |
| 24 | const { data } = await axios.get(apiUrl, { timeout: 60000, headers: { 'user-agent': 'Mozilla/5.0' } }); |
| 25 | |
| 26 | const videoUrl = data?.videoUrl || data?.result || data?.data?.videoUrl; |
| 27 | if (!videoUrl) { |
| 28 | throw new Error('No videoUrl in API response'); |
| 29 | } |
| 30 | |
| 31 | await sock.sendMessage(chatId, { |
| 32 | video: { url: videoUrl }, |
| 33 | mimetype: 'video/mp4', |
| 34 | caption: `Prompt: ${input}` |
| 35 | }, { quoted: message }); |
| 36 | |
| 37 | } catch (error) { |
| 38 | console.error('[SORA] error:', error?.message || error); |
| 39 | await sock.sendMessage(chatId, { text: 'Failed to generate video. Try a different prompt later.' }, { quoted: message }); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | module.exports = soraCommand; |
| 44 |
nothing calls this directly
no outgoing calls
no test coverage detected