Last active
August 8, 2022 13:00
-
-
Save nizamparkerz/96c9dd63bdf81a4fb4b86ba09cfce3c3 to your computer and use it in GitHub Desktop.
pn : instead of plugin, rm : remove plugin with quick restart ,rs : quick restart ⚡
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // by nizam . Special thanks to mask ser// | |
| const { | |
| bot, | |
| parseGistUrls, | |
| getPlugin, | |
| setPlugin, | |
| pluginsList, | |
| delPlugin, | |
| genButtonMessage, | |
| } = require('../lib/') | |
| const { writeFileSync, unlinkSync } = require('fs') | |
| const got = require('got') | |
| bot( | |
| { | |
| pattern: 'pn ?(.*)', | |
| fromMe: true, | |
| desc: 'Install External plugins', | |
| type: 'misc', | |
| }, | |
| async (message, match) => { | |
| match = match || message.reply_message.text | |
| if (!match && match !== 'list') | |
| return await message.sendMessage('*Example : pn url*') | |
| if (match == 'list') { | |
| const plugins = await getPlugin() | |
| if (!plugins) return await message.sendMessage(`*Plugins not installed*`) | |
| let msg = '' | |
| plugins.map(({ name, url }) => { | |
| msg += `${name} : ${url}\n` | |
| }) | |
| return await message.sendMessage('```' + msg + '```') | |
| } | |
| const isValidUrl = parseGistUrls(match) | |
| if (!isValidUrl) { | |
| const { url } = await getPlugin(match) | |
| if (url) return await message.sendMessage(url, { quoted: message.data }) | |
| } | |
| if (!isValidUrl) | |
| return await message.sendMessage('*Give valid urls*') | |
| for (const url of isValidUrl) { | |
| try { | |
| const res = await got(url) | |
| if (res.statusCode == 200) { | |
| let plugin_name = /pattern: ["'](.*)["'],/g.exec(res.body) | |
| plugin_name = plugin_name[1].split(' ')[0] | |
| writeFileSync('./plugins/' + plugin_name + '.js', res.body) | |
| try { | |
| require('./' + plugin_name) | |
| } catch (e) { | |
| await message.sendMessage(e.stack, { quoted: message.quoted }) | |
| return unlinkSync('./plugins/' + plugin_name + '.js') | |
| } | |
| await setPlugin(plugin_name, url) | |
| await message.sendMessage( | |
| `_Installed : ${pluginsList(res.body).join(',')}_` | |
| ) | |
| } | |
| } catch (error) { | |
| await message.sendMessage(`${error}\n${url}`) | |
| } | |
| } | |
| } | |
| ) | |
| bot( {pattern: 'rs ?(.*)', | |
| fromMe: true, | |
| desc: 'quick restart', | |
| type: 'misc' } | |
| ,async (message, match) => { await message.sendMessage(`_Restarting quickly⚡_`) | |
| require('pm2').restart('index.js') }); | |
| bot( | |
| { | |
| pattern: 'rm ?(.*)', | |
| fromMe: true, | |
| desc: 'Delete External Plugins', | |
| type: 'misc', | |
| }, | |
| async (message, match) => { | |
| if (!match) return await message.sendMessage('*Example : rm mforward*') | |
| if (match == 'all') { | |
| await delPlugin() | |
| return await message.sendMessage( | |
| '_All plugins deleted Successfully_\n*Restart BOT*' | |
| ) | |
| } | |
| const isDeleted = await delPlugin(match) | |
| if (!isDeleted) | |
| return await message.sendMessage(`*Plugin ${match} not found*`) | |
| delete require.cache[require.resolve('../plugins/' + match + '.js')] | |
| unlinkSync('./plugins/' + match + '.js') | |
| return await message.sendMessage( | |
| await genButtonMessage( | |
| [{ text: 'quick restart⚡', id: 'rs' }], | |
| '_Plugin deleted successfully ☑️_' | |
| ), | |
| {}, | |
| 'button' | |
| ) | |
| } | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment