-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunwayMessaging.js
56 lines (51 loc) · 2.19 KB
/
runwayMessaging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import rw from '@runwayml/hosted-models';
import puppeteer from 'puppeteer';
import friends from './friends.js';
import prompt from './prompt.js';
export default function(data){
const model = new rw.HostedModel({
url: data.rwurl,
token: data.rwtoken,
});
//fetching a randomly generated text from runway
let seed = Math.floor(Math.random()*300);
let runwayPrompt = Math.floor(Math.random()*(prompt.length-1));
const inputs = {
"prompt": prompt[runwayPrompt],
"max_characters": 300,
"top_p": 0.9,
"seed": seed
};
model.query(inputs).then(async function(outputs) {
const { generated_text, encountered_end } = outputs;
//logging in to instgram and sending the message to a selected person using puppeteer
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
await page.goto("https://www.instagram.com/direct/inbox/");
let useFacebook = await page.waitForSelector('.yWX7d');
await useFacebook.click();
page.waitForSelector("[aria-label='Email address or phone number']");
await email.click();
await page.waitForTimeout(3000);
await page.type("[aria-label='Email address or phone number']",data.instauser);
await page.type("[aria-label='Password']",data.instapwd);
let login = await page.waitForSelector('._52e0');
await login.click();
await page.waitForTimeout(30000);
const getThemAll = await page.$$('.DPiy6');
console.log('getThemAll',getThemAll.length);
if(getThemAll && getThemAll.length) {
const random = Math.floor(Math.random()*(getThemAll.length));
await getThemAll[random].click();
await page.waitForSelector('.PjuAP .qyrsm');
const userName = await page.$eval('.PjuAP .qyrsm', el => el.innerText);
if(friends.indexOf(userName) > -1) {
let messageBox = await page.waitForSelector('.ItkAi');
await messageBox.click();
await page.keyboard.type(generated_text , {delay: 30});
await page.keyboard.press('Enter');
await page.waitForTimeout(3000);
}
}
});
}