* @param {object} sock - Baileys sock * @param {object} message - the original message object * @param {Array} args - command arguments * @param {object} context - additional context
(sock, message, args, context)
| 14 | * @param {object} context - additional context |
| 15 | */ |
| 16 | async handler(sock, message, args, context) { |
| 17 | const chatId = context.chatId || message.key.remoteJid; |
| 18 | const text = args?.[0]; |
| 19 | if (!text) { |
| 20 | return await sock.sendMessage(chatId, { |
| 21 | text: 'Please provide a plugin URL.\nExample: .addplugin https://gist.github.com/username/gistid' |
| 22 | }, { quoted: message }); |
| 23 | } |
| 24 | const gistMatch = text.match(/(?:\/|gist\.github\.com\/)([a-fA-F0-9]+)/); |
| 25 | if (!gistMatch) { |
| 26 | return await sock.sendMessage(chatId, { text: '❌ Invalid plugin URL.' }, { quoted: message }); |
| 27 | } |
| 28 | const gistId = gistMatch[1]; |
| 29 | const gistURL = `https://api.github.com/gists/${gistId}`; |
| 30 | try { |
| 31 | const response = await axios.get(gistURL); |
| 32 | const gistData = response.data; |
| 33 | if (!gistData || !gistData.files) { |
| 34 | return await sock.sendMessage(chatId, { text: '❌ No valid files found in the Gist.' }, { quoted: message }); |
| 35 | } |
| 36 | const pluginDir = path.join(process.cwd(), 'plugins'); |
| 37 | for (const file of Object.values(gistData.files)) { |
| 38 | const pluginName = file.filename; |
| 39 | const pluginPath = path.join(pluginDir, pluginName); |
| 40 | await fs.promises.writeFile(pluginPath, file.content); |
| 41 | } |
| 42 | await sock.sendMessage(chatId, { text: '*✅ Successfully installed plugin from Gist.*' }, { quoted: message }); |
| 43 | } |
| 44 | catch (error) { |
| 45 | console.error('install plugin error:', error); |
| 46 | await sock.sendMessage(chatId, { text: `❌ Error fetching or saving the plugin: ${error.message}` }, { quoted: message }); |
| 47 | } |
| 48 | } |
| 49 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected