Skip to content

Commit

Permalink
Cleanup, Module Bug Fixes, Changed file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tuhinpal committed Sep 17, 2021
1 parent 27a521e commit a997d55
Show file tree
Hide file tree
Showing 37 changed files with 1,940 additions and 622 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ session.json
.cache/
.env
tempdata/*.json
cache/*
!cache/readme.txt
public/*
!public/readme.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
### Deploy :

[![Deploy with Heroku](https://www.herokucdn.com/deploy/button.svg "Deploy with Heroku")](https://heroku.com/deploy?template=https://github.com/TheWhatsBot/WhatsBot "Deploy with Heroku")<br>
[![Deploy+on+Railway](https://railway.app/button.svg)](<https://railway.app/new/template?template=https://github.com/TheWhatsBot/WhatsBot&plugins=mongodb&envs=SESSION,PMPERMIT_ENABLED,PMPERMIT_MUTETIME,DEFAULT_TR_LANG,ENABLE_DELETE_ALERT,YT_DATA_API_KEY,OCR_SPACE_API_KEY,INFOSPACE_API_KEY&SESSIONDesc=Puppeteer+Session.+Ge+it+by+running+genToken.js&PMPERMIT_ENABLEDDesc=Enable+Pmpermit+write+true+or+false+only&PMPERMIT_ENABLEDDefault=true&PMPERMIT_MUTETIMEDesc=How+many+seconds+an+user+get+muted+if+he+is+spamming.+Default+is+30+Minutes+(1800+Secs)&PMPERMIT_MUTETIMEDefault=1800&YT_DATA_API_KEYDesc=Youtube+DATA+API+key+grab+it+from+cloud.google.com&DEFAULT_TR_LANGDesc=Default+Translation+Language&DEFAULT_TR_LANGDefault=en&ENABLE_DELETE_ALERTDesc=If+true+and+if+someone+delete+message+in+PM,+Bot+will+send+the+deleted+message+in+that+chat+(Exclude+Media)&ENABLE_DELETE_ALERTDefault=true&OCR_SPACE_API_KEYDesc=Get+it+from+https://ocr.space/OCRAPI&INFOSPACE_API_KEYDesc=Get+it+from+https://infospace.club>)<br>
[![Deploy+on+Railway](https://railway.app/button.svg)](<https://railway.app/new/template?template=https://github.com/TheWhatsBot/WhatsBot&plugins=mongodb&envs=SESSION,PMPERMIT_ENABLED,DEFAULT_TR_LANG,ENABLE_DELETE_ALERT,YT_DATA_API_KEY,OCR_SPACE_API_KEY,INFOSPACE_API_KEY&SESSIONDesc=Puppeteer+Session.+Ge+it+by+running+genToken.js&PMPERMIT_ENABLEDDesc=Enable+Pmpermit+write+true+or+false+only&PMPERMIT_ENABLEDDefault=true&YT_DATA_API_KEYDesc=Youtube+DATA+API+key+grab+it+from+cloud.google.com&DEFAULT_TR_LANGDesc=Default+Translation+Language&DEFAULT_TR_LANGDefault=en&ENABLE_DELETE_ALERTDesc=If+true+and+if+someone+delete+message+in+PM,+Bot+will+send+the+deleted+message+in+that+chat+(Exclude+Media)&ENABLE_DELETE_ALERTDefault=true&OCR_SPACE_API_KEYDesc=Get+it+from+https://ocr.space/OCRAPI&INFOSPACE_API_KEYDesc=Get+it+from+https://infospace.club>)<br>
Read the [wiki](https://github.com/TheWhatsBot/WhatsBot/wiki/Deploy-with-Heroku) before Deploy it with Heroku<br><br>
[Deploy in VPS](https://github.com/TheWhatsBot/WhatsBot/wiki/Deploy-in-VPS)

Expand Down
7 changes: 2 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
"description": "MongoDB URL, Get it for free from cloud.mongodb.com",
"value": ""
},
"PMPERMIT_MUTETIME": {
"description": "How many seconds an user get muted if he is spamming. Default is 30 Minutes (1800 Secs)",
"value": "1800"
},

"YT_DATA_API_KEY": {
"description": "Youtube DATA API key, grab it from cloud.google.com",
"value": ""
Expand All @@ -49,4 +46,4 @@
"value": ""
}
}
}
}
File renamed without changes.
33 changes: 17 additions & 16 deletions commands/allow.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//jshint esversion:8
const config = require('../config');
const pmpermit = require('../modules/pmpermit');
const config = require("../config");
const pmpermit = require("../helpers/pmpermit");

const execute = async (client,msg) => {
if(config.pmpermit_enabled == "true" && !msg.to.includes("-")){
pmpermit.permitacton(msg.to.split("@")[0]);
let chat = await msg.getChat();
await chat.unmute(true);
msg.reply("Allowed for PM");
}
const execute = async (client, msg) => {
if (config.pmpermit_enabled == "true" && !msg.to.includes("-")) {
await pmpermit.permit(msg.to.split("@")[0]);
let chat = await msg.getChat();
await chat.unmute(true);
msg.reply("Allowed for PM");
}
};

module.exports = {
name: 'Allow for PM',
description: 'Allow personal messaging for a conatct',
command: '!allow',
commandType: 'admin',
isDependent: false,
help: `_You can allow him for pm by these commands_ 👇\n*!allow* - Allow an user for PM\n*!nopm* - Disallow an allowed user for PM`, // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute};
name: "Allow for PM",
description: "Allow personal messaging for a conatct",
command: "!allow",
commandType: "admin",
isDependent: false,
help: `_You can allow him for pm by these commands_ 👇\n*!allow* - Allow an user for PM\n*!nopm* - Disallow an allowed user for PM`, // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute,
};
21 changes: 11 additions & 10 deletions commands/awake.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//jshint esversion:8
const execute = async (client,msg) => {
client.sendPresenceAvailable();
msg.reply("```" + "I will be online from now." + "```");
const execute = async (client, msg) => {
client.sendPresenceAvailable();
msg.reply("```" + "I will be online from now." + "```");
};

module.exports = {
name: 'Awake',
description: 'marks user as online',
command: '!awake',
commandType: 'plugin',
isDependent: false,
help: undefined,
execute};
name: "Awake",
description: "Stay online always !",
command: "!awake",
commandType: "plugin",
isDependent: false,
help: undefined,
execute,
};
26 changes: 12 additions & 14 deletions commands/block.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//jshint esversion:8
const execute = async (client,msg) => {
if (!msg.to.includes("-")) {
let chat = await msg.getChat();
let contact = await chat.getContact();
msg.reply("You have been Blocked");
contact.block();
}
const execute = async (client, msg) => {
if (!msg.to.includes("-")) {
await (await msg.getContact()).block();
}
};

module.exports = {
name: 'Block', //name of the module
description: 'Block current chat', // short description of what this command does
command: '!block', //command with prefix. Ex command: '!test'
commandType: 'admin', //
isDependent: false, //whether this command is related/dependent to some other command
help: 'Type !block in the chat to block the user', // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute};
name: "Block", //name of the module
description: "Block current chat", // short description of what this command does
command: "!block", //command with prefix. Ex command: '!test'
commandType: "admin", //
isDependent: false, //whether this command is related/dependent to some other command
help: "Type !block in the chat to block the user", // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute,
};
2 changes: 2 additions & 0 deletions commands/carbon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//jshint esversion:8

//TODO: fix it
const { MessageMedia } = require('whatsapp-web.js');
const axios = require('axios');

Expand Down
23 changes: 0 additions & 23 deletions commands/delete.js

This file was deleted.

15 changes: 8 additions & 7 deletions commands/dldsong.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//jshint esversion:8
const {MessageMedia} = require('whatsapp-web.js');
const {download} = require('../modules/song');
const { MessageMedia } = require('whatsapp-web.js');
const { download } = require('../helpers/song');

const execute = async (client,msg,args) => {
if(msg.hasQuotedMsg) {
const execute = async (client, msg, args) => {
if (msg.hasQuotedMsg) {
msg.delete(true);
let quotedMsg = await msg.getQuotedMessage();
let getdata = await download(args[0], quotedMsg.id.id);
Expand All @@ -12,11 +12,11 @@ const execute = async (client,msg,args) => {
} else {
await client.sendMessage(msg.to, getdata.content);
}
}
}
else {
await client.sendMessage(msg.to, '```Search for the song with !song and then reply to the query result with this command```');
}

};

module.exports = {
Expand All @@ -26,4 +26,5 @@ module.exports = {
commandType: 'plugin',
isDependent: true,
help: 'use !help song to learn about this command',
execute};
execute
};
33 changes: 17 additions & 16 deletions commands/mute.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//jshint esversion:8
const config = require('../config');
const config = require("../config");

const execute = async (client,msg) => {
if (!msg.to.includes("-")) {
let chat = await msg.getChat();
let unmuteDate = new Date();
unmuteDate.setSeconds(Number(unmuteDate.getSeconds()) + Number(config.pmpermit_mutetime));
await chat.mute(unmuteDate);
msg.reply(`You have been muted for ${config.pmpermit_mutetime / 60} Minutes`);
}
const execute = async (client, msg) => {
if (!msg.to.includes("-")) {
let chat = await msg.getChat();
let unmuteDate = new Date();
unmuteDate.setSeconds(Number(unmuteDate.getSeconds()) + 3600);
await chat.mute(unmuteDate);
msg.reply(`You have been muted for 1 hour`);
}
};

module.exports = {
name: 'Mute', //name of the module
description: 'mute the current chat', // short description of what this command does
command: '!mute', //command with prefix. Ex command: '!test'
commandType: 'admin', //
isDependent: false, //whether this command is related/dependent to some other command
help: `Type !mute in chat to mute the chat for ${config.pmpermit_mutetime / 60} Minutes. use !unmute to unmute the chat.`, // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute};
name: "Mute", //name of the module
description: "mute the current chat", // short description of what this command does
command: "!mute", //command with prefix. Ex command: '!test'
commandType: "admin", //
isDependent: false, //whether this command is related/dependent to some other command
help: `Type !mute in chat to mute the chat for 1 hour. use !unmute to unmute the chat.`, // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute,
};
30 changes: 15 additions & 15 deletions commands/nopm.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//jshint esversion:8
const config = require('../config');
const pmpermit = require('../modules/pmpermit');
const config = require("../config");
const pmpermit = require("../helpers/pmpermit");

const execute = async (client,msg) => {
if (config.pmpermit_enabled == "true" && !msg.to.includes("-")) {
pmpermit.nopermitacton(msg.to.split("@")[0]);
msg.reply("Not Allowed for PM");
}

const execute = async (client, msg) => {
if (config.pmpermit_enabled == "true" && !msg.to.includes("-")) {
await pmpermit.nopermit(msg.to.split("@")[0]);
msg.reply("Not Allowed for PM");
}
};

module.exports = {
name: 'Disallow PM', //name of the module
description: 'Disallow an allowed user for Personal messaging', // short description of what this command does
command: '!nopm', //command with prefix. Ex command: '!test'
commandType: 'admin', //
isDependent: false, //whether this command is related/dependent to some other command
help: 'Type !nopm in the chat to execute.', // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute};
name: "Disallow PM", //name of the module
description: "Disallow an allowed user for Personal messaging", // short description of what this command does
command: "!nopm", //command with prefix. Ex command: '!test'
commandType: "admin", //
isDependent: false, //whether this command is related/dependent to some other command
help: "Type !nopm in the chat to execute.", // a string descring how to use this command Ex = help : 'To use this command type !test arguments'
execute,
};
38 changes: 21 additions & 17 deletions commands/song.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
//jshint esversion:8
const fs = require('fs');
const path = require('path');
const {search} = require('../modules/song');
const fs = require("fs");
const path = require("path");
const { search } = require("../helpers/song");

const execute = async (client,msg,args) => {
msg.delete(true);
let getdata = await search(args.join(' '));
let sendmessage = await client.sendMessage(msg.to, getdata.content); // have to grab the message ID
if (getdata.status) {
fs.writeFileSync(path.join(__dirname,`../tempdata/song~${sendmessage.id.id}.json`), JSON.stringify(getdata.songarray));
}
const execute = async (client, msg, args) => {
msg.delete(true);
let getdata = await search(args.join(" "));
let sendmessage = await client.sendMessage(msg.to, getdata.content); // have to grab the message ID
if (getdata.status) {
fs.writeFileSync(
path.join(__dirname, `../cache/song~${sendmessage.id.id}.json`),
JSON.stringify(getdata.songarray)
);
}
};

module.exports = {
name: 'Search Song',
description: 'Search songs on jiosaavn',
command: '!song',
commandType: 'plugin',
isDependent: false,
help: `*Song*\n\nSearch a song and download it. \n\n*!song [search-query]*\nEx: !song makhna\n\nThen replay the message with *!dldsong [id]*\nEx. !dldsong 1\n\n⚡ Powered by musicder.net`,
execute};
name: "Search Song",
description: "Search songs on jiosaavn",
command: "!song",
commandType: "plugin",
isDependent: false,
help: `*Song*\n\nSearch a song and download it. \n\n*!song [search-query]*\nEx: !song makhna\n\nThen replay the message with *!dldsong [id]*\nEx. !dldsong 1\n\n⚡ Powered by musicder.net`,
execute,
};
37 changes: 0 additions & 37 deletions commands/start.js

This file was deleted.

2 changes: 1 addition & 1 deletion commands/tr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//jshint esversion:8
const translate = require("@iamtraction/google-translate");
const config = require("../config");
const tr_languages = require("../helperdata/tr_languages");
const tr_languages = require("../helpers/tr_languages");

async function translator(langReq, text) {
let lang;
Expand Down
Loading

0 comments on commit a997d55

Please sign in to comment.