-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,600 additions
and
535 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,25 @@ const chalk = require('chalk'); | |
const wa = require('./core/helper'); | ||
const { MessageType } = require('@adiwajshing/baileys'); | ||
const Greetings = require('./database/greeting'); | ||
const Users = require('./database/user'); | ||
const sequelize = config.DATABASE; | ||
const adminCommands = require("./sidekick/input-sanitization").adminCommands; | ||
const sudoCommands = require("./sidekick/input-sanitization").sudoCommands; | ||
const STRINGS = require("./lib/db"); | ||
const Blacklist = require('./database/blacklist'); | ||
const GENERAL = STRINGS.general; | ||
// const gitPull = require('./core/gitpull'); | ||
const clearance = require('./core/clearance'); | ||
|
||
var client = conn.WhatsApp; | ||
|
||
async function main() { | ||
|
||
client.logger.level = 'error'; | ||
console.log(banner); | ||
var commandHandler = new Map(); | ||
console.log(chalk.yellowBright.bold("[INFO] Checking for updates...")); | ||
// await gitPull(); | ||
try{ | ||
try { | ||
var session = conn.restoreSession(config.STRING_SESSION) | ||
client.loadAuthInfo(session) | ||
} catch(err) { | ||
if (err instanceof TypeError || err.message === "given authInfo is null" || err instanceof SyntaxError){ | ||
} catch (err) { | ||
if (err instanceof TypeError || err.message === "given authInfo is null" || err instanceof SyntaxError) { | ||
console.log( | ||
chalk.redBright.bold("Incorrect Session String. Please authenticate again using command -> "), | ||
chalk.yellowBright.bold("npm start") | ||
|
@@ -53,15 +50,15 @@ async function main() { | |
client.on('open', async () => { | ||
console.log(chalk.yellowBright.bold("[INFO] Installing Plugins... Please wait.")); | ||
var moduleFiles = fs.readdirSync(join(__dirname, 'modules')).filter((file) => file.endsWith('.js')) | ||
for(var file of moduleFiles){ | ||
try{ | ||
for (var file of moduleFiles) { | ||
try { | ||
const command = require(join(__dirname, 'modules', `${file}`)); | ||
console.log( | ||
chalk.magentaBright("[INFO] Successfully imported module"), | ||
chalk.cyanBright.bold(`${file}`) | ||
) | ||
commandHandler.set(command.name, command); | ||
}catch(error){ | ||
} catch (error) { | ||
console.log( | ||
chalk.blueBright.bold("[INFO] Could not import module"), | ||
chalk.redBright.bold(`${file}`) | ||
|
@@ -96,36 +93,36 @@ async function main() { | |
|
||
|
||
client.on('group-participants-update', async update => { | ||
console.log("-------------------"+ "GROUP PARTICIPANT UPDATE" + "-------------------" ); | ||
console.log(update.participants); | ||
console.log(update.action); | ||
console.log(update.jid); | ||
// console.log("-------------------" + "GROUP PARTICIPANT UPDATE" + "-------------------"); | ||
// console.log(update.participants); | ||
// console.log(update.action); | ||
// console.log(update.jid); | ||
var groupId = update.jid; | ||
|
||
try{ | ||
if(update.action === 'add'){ | ||
var enable = await Greetings.checkSettings(groupId,"welcome"); | ||
if(enable === false || enable === "OFF"){ | ||
try { | ||
if (update.action === 'add') { | ||
var enable = await Greetings.checkSettings(groupId, "welcome"); | ||
if (enable === false || enable === "OFF") { | ||
return; | ||
} | ||
var Msg = await Greetings.getMessage(groupId, "welcome"); | ||
|
||
client.sendMessage(groupId, Msg.message, MessageType.text); | ||
return; | ||
} | ||
else if(update.action === 'remove'){ | ||
else if (update.action === 'remove') { | ||
var enable = await Greetings.checkSettings(groupId, "goodbye"); | ||
if(enable === false || enable === "OFF"){ | ||
if (enable === false || enable === "OFF") { | ||
return; | ||
} | ||
var Msg = await Greetings.getMessage(groupId, "goodbye"); | ||
|
||
client.sendMessage(groupId, Msg.message, MessageType.text); | ||
return; | ||
} | ||
} | ||
catch(err){ | ||
console.log("Greeting message are off"); | ||
catch (err) { | ||
// console.log("Greeting message are off"); | ||
} | ||
}); | ||
|
||
|
@@ -138,107 +135,33 @@ async function main() { | |
const groupMetadata = sender.endsWith("@g.us") ? await client.groupMetadata(sender) : ''; | ||
var BotsApp = wa.resolve(chat, client, groupMetadata); | ||
// console.log(BotsApp); | ||
if(BotsApp.chatId === "[email protected]") return; | ||
if (BotsApp.isCmd && (!BotsApp.fromMe && !BotsApp.isSenderSUDO)) { | ||
if (config.WORK_TYPE === "public") { | ||
if (adminCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderGroupAdmin) { | ||
console.log( | ||
chalk.redBright.bold(`[INFO] admin commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in public Work Type.` | ||
) | ||
); | ||
return client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.ADMIN_PERMISSION, | ||
MessageType.text | ||
); | ||
} else if (sudoCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderSUDO) { | ||
console.log( | ||
chalk.redBright.bold(`[INFO] sudo commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in public Work Type.` | ||
) | ||
); | ||
var messageSent = await Users.getUser(BotsApp.chatId); | ||
if(messageSent){ | ||
return console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)); | ||
} | ||
else{ | ||
await Users.addUser(BotsApp.chatId) | ||
return client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.SUDO_PERMISSION.format({ worktype: "public", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), | ||
MessageType.text, | ||
{ | ||
contextInfo: { | ||
stanzaId: chat.key.id, | ||
participant: BotsApp.sender, | ||
quotedMessage: { | ||
conversation: BotsApp.body, | ||
}, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
} | ||
} | ||
else if(config.WORK_TYPE === "private" && !BotsApp.isSenderSUDO){ | ||
console.log( | ||
chalk.redBright.bold(`[INFO] commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in private Work Type.` | ||
) | ||
); | ||
var messageSent = await Users.getUser(BotsApp.chatId); | ||
if(messageSent){ | ||
return console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)); | ||
} | ||
else{ | ||
await Users.addUser(BotsApp.chatId) | ||
return client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.SUDO_PERMISSION.format({ worktype: "private", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), | ||
MessageType.text, | ||
{ | ||
contextInfo: { | ||
stanzaId: chat.key.id, | ||
participant: BotsApp.sender, | ||
quotedMessage: { | ||
conversation: BotsApp.body, | ||
}, | ||
}, | ||
} | ||
); | ||
} | ||
if (BotsApp.isCmd) { | ||
let isBlacklist = await Blacklist.getBlacklistUser(BotsApp.sender, BotsApp.chatId); | ||
const cleared = await clearance(BotsApp, client, isBlacklist); | ||
if (!cleared) { | ||
return; | ||
} | ||
} | ||
if(BotsApp.isCmd){ | ||
console.log(chalk.redBright.bold(`[INFO] ${BotsApp.commandName} command executed.`)); | ||
const command = commandHandler.get(BotsApp.commandName); | ||
var args = BotsApp.body.trim().split(/\s+/).slice(1); | ||
// console.log("ARGS -> " + args); | ||
// args.forEach(arg => console.log("arg -> " + arg + " type -> " + typeof(arg))); | ||
// console.log("-------------------------------------------") | ||
if(!command){ | ||
if (!command) { | ||
client.sendMessage(BotsApp.chatId, "```Woops, invalid command! Use``` *.help* ```to display the command list.```", MessageType.text); | ||
return; | ||
}else if (command && BotsApp.commandName == "help"){ | ||
try{ | ||
} else if (command && BotsApp.commandName == "help") { | ||
try { | ||
command.handle(client, chat, BotsApp, args, commandHandler); | ||
return; | ||
}catch(err){ | ||
} catch (err) { | ||
console.log(chalk.red("[ERROR] ", err)); | ||
return; | ||
} | ||
} | ||
try{ | ||
try { | ||
command.handle(client, chat, BotsApp, args).catch(err => console.log("[ERROR] " + err)); | ||
}catch(err){ | ||
} catch (err) { | ||
console.log(chalk.red("[ERROR] ", err)); | ||
} | ||
} | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const chalk = require('chalk'); | ||
const config = require('../config') | ||
const adminCommands = require("../sidekick/input-sanitization").adminCommands; | ||
const sudoCommands = require("../sidekick/input-sanitization").sudoCommands; | ||
const STRINGS = require("../lib/db"); | ||
const GENERAL = STRINGS.general; | ||
const Users = require('../database/user'); | ||
const { MessageType } = require('@adiwajshing/baileys'); | ||
|
||
const clearance = async(BotsApp, client, isBlacklist) => { | ||
if((!BotsApp.fromMe && !BotsApp.isSenderSUDO && !BotsApp.isSenderGroupAdmin) && (isBlacklist)){ | ||
console.log(chalk.blueBright.bold(`[INFO] Blacklisted Chat or User.`)); | ||
return false; | ||
} | ||
else if(BotsApp.chatId === "[email protected]" || BotsApp.chatId === "[email protected]"){ | ||
console.log(chalk.blueBright.bold(`[INFO] Blacklisted Chat or User.`)); | ||
return false; | ||
} | ||
if (BotsApp.isCmd && (!BotsApp.fromMe && !BotsApp.isSenderSUDO)) { | ||
if (config.WORK_TYPE.toLowerCase() === "public") { | ||
if (adminCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderGroupAdmin) { | ||
console.log( | ||
chalk.redBright.bold(`[INFO] admin commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in public Work Type.` | ||
) | ||
); | ||
await client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.ADMIN_PERMISSION, | ||
MessageType.text | ||
); | ||
return false; | ||
} else if (sudoCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderSUDO) { | ||
console.log( | ||
chalk.redBright.bold(`[INFO] sudo commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in public Work Type.` | ||
) | ||
); | ||
var messageSent = await Users.getUser(BotsApp.chatId); | ||
if(messageSent){ | ||
console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)) | ||
return false; | ||
} | ||
else{ | ||
await client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.SUDO_PERMISSION.format({ worktype: "public", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), | ||
MessageType.text, | ||
{ | ||
contextInfo: { | ||
stanzaId: BotsApp.chatId, | ||
participant: BotsApp.sender, | ||
quotedMessage: { | ||
conversation: BotsApp.body, | ||
}, | ||
}, | ||
} | ||
); | ||
await Users.addUser(BotsApp.chatId) | ||
return false; | ||
} | ||
|
||
}else{ | ||
return true; | ||
} | ||
} | ||
else if(config.WORK_TYPE.toLowerCase() != "public" && !BotsApp.isSenderSUDO){ | ||
console.log( | ||
chalk.redBright.bold(`[INFO] commmand `), | ||
chalk.greenBright.bold(`${BotsApp.commandName}`), | ||
chalk.redBright.bold( | ||
`not executed in private Work Type.` | ||
) | ||
); | ||
var messageSent = await Users.getUser(BotsApp.chatId); | ||
if(messageSent){ | ||
console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)) | ||
return false; | ||
} | ||
else{ | ||
await client.sendMessage( | ||
BotsApp.chatId, | ||
GENERAL.SUDO_PERMISSION.format({ worktype: "private", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), | ||
MessageType.text, | ||
{ | ||
contextInfo: { | ||
stanzaId: BotsApp.chatId, | ||
participant: BotsApp.sender, | ||
quotedMessage: { | ||
conversation: BotsApp.body, | ||
}, | ||
}, | ||
} | ||
); | ||
await Users.addUser(BotsApp.chatId) | ||
return false; | ||
} | ||
} | ||
}else{ | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = clearance; |
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
Oops, something went wrong.