Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince-Mendiratta committed Dec 12, 2021
2 parents a8892c0 + 4ee5508 commit 7957937
Show file tree
Hide file tree
Showing 26 changed files with 1,600 additions and 535 deletions.
143 changes: 33 additions & 110 deletions BotsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}`)
Expand Down Expand Up @@ -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");
}
});

Expand All @@ -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 === "917838204238-1634977991@g.us") 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));
}
}
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]
### Added
- Disable the bot in support group #1.
- Disable the bot in support group #1 and support group #2.
- Ability to blacklist certain people / chats from using the bot in public mode.
- Generate invite link to invite people who cannot be added directly.
- Rename and resend file directly on WhatsApp.
- Create groups with the tagged person directly.
- Execute C++ code and get output directly on WhatsApp.
- Search for meaning in the dictionary for a word.
- Create QR code from text.
- Decode QR code to extract text.

### Changed
- Removed case sensitivity issue for WORK_TYPE.
- The getdp module can now get profile pictures of a tagged person as well.
- Improved the lyrics search module.
- Make the permission check asynchronous.
- Switch back to stable version of baileys.

## [1.0.1] - 2020-11-15
### Added
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ RUN git reset --hard origin/main

RUN npm install

RUN cp -r /root/Baileys/lib /BotsApp/node_modules/@adiwajshing/baileys/
# RUN cp -r /root/Baileys/lib /BotsApp/node_modules/@adiwajshing/baileys/

CMD [ "npm", "start"]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@ Feel free to post your queries or concerns on any of the discussion forums menti
## Copyright & License
- Copyright (C) 2021 - 2022 by [BotsAppOfficial](https://github.com/BotsAppOfficial)

- Licensed under the terms by [GNU GENERAL PUBLIC LICENSE](https://github.com/BotsAppOfficial/BotsApp/blob/main/LICENSE)
- Licensed under the terms by [GNU GENERAL PUBLIC LICENSE](https://github.com/BotsAppOfficial/BotsApp/blob/main/LICENSE)

## Legal
This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.
108 changes: 108 additions & 0 deletions core/clearance.js
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 === "917838204238-1634977991@g.us" || BotsApp.chatId === "120363020858647962@g.us"){
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;
1 change: 1 addition & 0 deletions core/gitpull.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const chalk = require('chalk');
const exec = require('child_process').exec;

const gitPull = async () => {
console.log(chalk.yellowBright.bold("[INFO] Checking for updates..."));
await git.fetch();
var newCommits = await git.log(['main..origin/main'])
if (newCommits.total) {
Expand Down
Loading

0 comments on commit 7957937

Please sign in to comment.