Skip to content

Commit

Permalink
ditching darkmore and figing login errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vasani-arpit committed Oct 1, 2019
1 parent ef5ce95 commit 4d66de6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
1 change: 0 additions & 1 deletion bot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"appconfig": {
"headless": false,
"darkmode": false,
"isGroupReply":false,
"webhook":"https://lazy-cow-87.localtunnel.me/api/messages"
},
Expand Down
33 changes: 17 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ async function Main() {
waitUntil: 'networkidle0',
timeout: 0
});
if (appconfig.appconfig.darkmode) {
page.addStyleTag({ path: path.join(__dirname, "style.css") });
}
//console.log(contents);
await injectScripts(page);
//await injectScripts(page);
botjson.then((data) => {
page.evaluate("var intents = " + data);
//console.log(data);
Expand All @@ -109,16 +106,20 @@ async function Main() {
}

async function injectScripts(page) {
page.waitForSelector('[data-icon=laptop]')
.then(async () => {
var filepath = path.join(__dirname, "WAPI.js");
await page.addScriptTag({ path: require.resolve(filepath) });
filepath = path.join(__dirname, "inject.js");
await page.addScriptTag({ path: require.resolve(filepath) });
})
.catch(() => {
console.log("User is not logged in. Waited 30 seconds.");
})
return new Promise(async (resolve, reject) => {
await page.waitForSelector('[data-icon=laptop]')
.then(async () => {
var filepath = path.join(__dirname, "WAPI.js");
await page.addScriptTag({ path: require.resolve(filepath) });
filepath = path.join(__dirname, "inject.js");
await page.addScriptTag({ path: require.resolve(filepath) });
resolve(true);
})
.catch(() => {
console.log("User is not logged in. Waited 30 seconds.");
reject(false);
})
})
}

async function checkLogin() {
Expand All @@ -145,12 +146,12 @@ async function Main() {
//console.log(imageData);
qrcode.generate(imageData, { small: true });
spinner.start("Waiting for scan \nKeep in mind that it will expire after few seconds");
var isLoggedIn = await page.evaluate("WAPI.isLoggedIn();");
var isLoggedIn = await injectScripts(page);
while (!isLoggedIn) {
//console.log("page is loading");
//TODO: avoid using delay and make it in a way that it would react to the event.
await utils.delay(300);
isLoggedIn = await page.evaluate("WAPI.isLoggedIn();");
isLoggedIn = await injectScripts(page);
}
if (isLoggedIn) {
spinner.stop("Looks like you are logged in now");
Expand Down

3 comments on commit 4d66de6

@SurielRuano
Copy link

@SurielRuano SurielRuano commented on 4d66de6 Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, my feedback, in this commit you solves the errors with the scripts but the bot is dead

@vasani-arpit
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurielRuano Can you tell me which steps you are following and where it is failing?

@vasani-arpit
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurielRuano I am able to reproduce it. Thanks for pointing this out. I am checking on it.

Please sign in to comment.