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