Skip to content

Commit

Permalink
Update bot dynamically
Browse files Browse the repository at this point in the history
Signed-off-by: Prince Mendiratta <[email protected]>
  • Loading branch information
Prince-Mendiratta committed Nov 5, 2021
1 parent 1401adf commit 58ad272
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ build/Release
package-lock.json
tmp/*.*
.vs/
BotsApp.db
.idea/
.idea/
BotsApp.db
Binary file removed BotsApp.db
Binary file not shown.
9 changes: 6 additions & 3 deletions BotsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const adminCommands = require("./sidekick/input-sanitization").adminCommands;
const sudoCommands = require("./sidekick/input-sanitization").sudoCommands;
const STRINGS = require("./lib/db");
const GENERAL = STRINGS.general;
const gitPull = require('./core/gitpull');

var client = conn.WhatsApp;

Expand All @@ -21,6 +22,8 @@ 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{
var session = conn.restoreSession(config.STRING_SESSION)
client.loadAuthInfo(session)
Expand Down Expand Up @@ -48,7 +51,7 @@ async function main() {
})

client.on('open', async () => {
console.log(chalk.whiteBright.bold("[INFO] Installing Plugins... Please wait."));
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{
Expand All @@ -60,7 +63,7 @@ async function main() {
commandHandler.set(command.name, command);
}catch(error){
console.log(
chalk.blueBright.bold("[INFO] Can not imported module"),
chalk.blueBright.bold("[INFO] Could not import module"),
chalk.redBright.bold(`${file}`)
)
console.log(`[ERROR] `, error);
Expand Down Expand Up @@ -160,7 +163,7 @@ async function main() {
);
var messageSent = await Users.getUser(BotsApp.sender);
if(messageSent){
return console.log(chalk.blueBright.bold("Promo message had already been sent to " + BotsApp.sender));
return console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.sender));
}
else{
await Users.addUser(BotsApp.sender)
Expand Down
23 changes: 23 additions & 0 deletions core/gitpull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const git = require('simple-git')()
// const path = ''
const chalk = require('chalk');

const gitPull = async () => {
await git.fetch();
var newCommits = await git.log(['main..origin/main'])
if (newCommits.total) {
console.log(chalk.blueBright("[INFO] New Update pending, updating..."));
await git.pull("origin", "main", (err, update) => {
if(update && update.summary.changes){
console.log(chalk.greenBright.bold("[INFO] Updated the bot with latest changes."));
}else if(err){
console.log(chalk.redBright.bold("[ERROR] Could not pull latest changes!"));
console.log(err);
}
});
}else{
console.log(chalk.greenBright.bold("[INFO] Bot is already working on latest version."));
}
}

module.exports = gitPull
1 change: 1 addition & 0 deletions core/sessionString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const chalk = require('chalk')
const config = require('../config');

const conn = new WAConnection();
conn.version = [3, 3234, 9];

exports.WhatsApp = conn;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"pg": "^8.7.1",
"python-format-js": "^1.3.9",
"sequelize": "^6.7.0",
"simple-git": "^2.47.0",
"sqlite3": "^5.0.2",
"unofficial-carbon-now": "^1.0.3",
"urban-dictionary": "^3.0.2",
Expand Down

0 comments on commit 58ad272

Please sign in to comment.