-
-
Save souravkl11/9ed8d6604ea9f63170a51fb3573e8d72 to your computer and use it in GitHub Desktop.
This file contains 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
const config = require("../config") | |
const fs = require("fs") | |
require("../main").Module({ | |
pattern: 'setsudo ?(.*)', | |
fromMe: true, | |
use: 'owner' | |
}, (async (message, match) => { | |
var m = message; | |
var newSudo = ( m.reply_message ? m.reply_message.jid : '' || m.mention[0] || match[1]).split("@")[0] | |
if (!newSudo) return await m.sendReply("*Need reply/mention/number*") | |
const oldSudo = config.SUDO | |
var setSudo = (config.SUDO+","+newSudo).replace(/,,/g,""); | |
setSudo = setSudo.startsWith(",")?setSudo.replace(",",""):setSudo | |
await m.sendReply('_*Successfully added! New Sudo numbers:* '+setSudo+"_") | |
if (process.env.KOYEB_API_KEY){ | |
const {update} = require("./misc/koyeb") | |
config.SUDO = setSudo | |
return await update("SUDO",setSudo) | |
} | |
try { | |
config["SUDO"]=setSudo | |
var envFile = fs.readFileSync(`./config.env`).toString('utf-8') | |
let matches = envFile.split('\n').filter(e=>e.startsWith("SUDO")) | |
if (matches.length==1){ | |
let newEnv = envFile.replace(oldSudo,config["SUDO"]) | |
await fs.writeFileSync(`./config.env`,newEnv) | |
} else { | |
let newEnv = envFile+'\n'+"SUDO"+'='+config["SUDO"] | |
await fs.writeFileSync(`./config.env`,newEnv) | |
}} catch(e){ | |
return await m.sendReply(e.message); | |
} | |
})); | |
require("../main").Module({ | |
pattern: 'getsudo ?(.*)', | |
fromMe: true, | |
use: 'owner' | |
}, (async (message, match) => { | |
return await message.sendReply(config.SUDO); | |
})); | |
require("../main").Module({pattern: 'delsudo ?(.*)', fromMe: true, desc: "Sets sudo"}, (async (m,mm) => { | |
const oldSudo = config.SUDO | |
var newSudo = ( m.reply_message ? m.reply_message.jid : '' || m.mention[0] || mm[1]).split("@")[0] | |
if (!newSudo) return await m.sendReply("*Need reply/mention/number*") | |
var setSudo = config.SUDO.replace(newSudo,"").replace(/,,/g,","); | |
setSudo = setSudo.startsWith(",")?setSudo.replace(",",""):setSudo | |
if (process.env.KOYEB_API_KEY){ | |
const {update} = require("./misc/koyeb") | |
config.SUDO = setSudo | |
return await update("SUDO",setSudo) | |
} | |
try { | |
config["SUDO"]=setSudo | |
await m.sendReply('_*Successfully removed* +'+newSudo+" *from sudo!*_") | |
var envFile = fs.readFileSync(`./config.env`).toString('utf-8') | |
let matches = envFile.split('\n').filter(e=>e.startsWith("SUDO")) | |
if (matches.length==1){ | |
let newEnv = envFile.replace(oldSudo,config["SUDO"]) | |
await fs.writeFileSync(`./config.env`,newEnv) | |
} else { | |
let newEnv = envFile+'\n'+"SUDO"+'='+config["SUDO"] | |
await fs.writeFileSync(`./config.env`,newEnv) | |
}} catch(e){ | |
return await m.sendReply(e.message); | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const config = require("../config")
const fs = require("fs")
require("../main").Module({
pattern: 'setsudo ?(.)',
fromMe: true,
use: 'owner'
}, (async (message, match) => {
var m = message;
var newSudo = ( m.reply_message ? m.reply_message.jid : '' || m.mention[0] || match[1]).split("@")[0]
if (!newSudo) return await m.sendReply("Need reply/mention/number")
const oldSudo = config.SUDO
var setSudo = (config.SUDO+","+newSudo).replace(/,,/g,"");
setSudo = setSudo.startsWith(",")?setSudo.replace(",",""):setSudo
await m.sendReply('Successfully added! New Sudo numbers: '+setSudo+"")
if (process.env.KOYEB_API_KEY){
const {update} = require("./misc/koyeb")
config.SUDO = setSudo
return await update("SUDO",setSudo)
}
try {
config["SUDO"]=setSudo
var envFile = fs.readFileSync(
./config.env
).toString('utf-8')let matches = envFile.split('\n').filter(e=>e.startsWith("SUDO"))
if (matches.length==1){
let newEnv = envFile.replace(oldSudo,config["SUDO"])
await fs.writeFileSync(
./config.env
,newEnv)} else {
let newEnv = envFile+'\n'+"SUDO"+'='+config["SUDO"]
await fs.writeFileSync(
./config.env
,newEnv)}} catch(e){
return await m.sendReply(e.message);
}
}));
require("../main").Module({
pattern: 'getsudo ?(.)',
fromMe: true,
use: 'owner'
}, (async (message, match) => {
return await message.sendReply(config.SUDO);
}));
require("../main").Module({pattern: 'delsudo ?(.*)', fromMe: true, desc: "Sets sudo"}, (async (m,mm) => {
const oldSudo = config.SUDO
var newSudo = ( m.reply_message ? m.reply_message.jid : '' || m.mention[0] || mm[1]).split("@")[0]
if (!newSudo) return await m.sendReply("Need reply/mention/number")
var setSudo = config.SUDO.replace(newSudo,"").replace(/,,/g,",");
setSudo = setSudo.startsWith(",")?setSudo.replace(",",""):setSudo
if (process.env.KOYEB_API_KEY){
const {update} = require("./misc/koyeb")
config.SUDO = setSudo
return await update("SUDO",setSudo)
}
try {
config["SUDO"]=setSudo
await m.sendReply('Successfully removed +'+newSudo+" from sudo!")
var envFile = fs.readFileSync(
./config.env
).toString('utf-8')let matches = envFile.split('\n').filter(e=>e.startsWith("SUDO"))
if (matches.length==1){
let newEnv = envFile.replace(oldSudo,config["SUDO"])
await fs.writeFileSync(
./config.env
,newEnv)} else {
let newEnv = envFile+'\n'+"SUDO"+'='+config["SUDO"]
await fs.writeFileSync(
./config.env
,newEnv)}} catch(e){
return await m.sendReply(e.message);
}
}));