-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
221 lines (202 loc) · 11 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
const { setImmediate } = require("async");
const { Builder, By, Key, until } = require("selenium-webdriver");
const webdriver = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const cred = require("./accounts.json");
let options = new chrome.Options();
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
options.addArguments("--start-maximized");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
//HEROKU VERSION
let resend;
let lastMessage;
let errCtr;
let driver = new webdriver.Builder().forBrowser("chrome").setChromeOptions(options).build();
start();
function start() {
(async () => {
try {
await driver.get("https://www.messenger.com");
await driver.sleep(3000)
await driver.findElement(By.xpath('//*[@id="email"]')).sendKeys(cred.email);
await driver.findElement(By.xpath('//*[@id="pass"]')).sendKeys(cred.password);
await driver.findElement(By.xpath('//*[@id="loginbutton"]')).click();
await driver.get("https://www.messenger.com/t/106882174524725");
await driver.sleep(3000)
startResendTimer();
await timeout();
while (true){
await checkNewMessage();
}
}
catch (e) {
console.log("Main Process error" + e);
process.exit();
}
})();
}
async function checkNewMessage() {
try {
await driver.wait(until.elementLocated(By.xpath('//div[@data-testid="incoming_group"][last()]')), 30000)
msg = await driver.findElement(By.xpath('//div[@data-testid="incoming_group"][last()]')).getText();
if (msg != lastMessage){
console.log(msg)
check(msg);
lastMessage = msg;
errCtr = 0;
}
} catch (e) {
if (e instanceof webdriver.error.NoSuchElementError){
console.log("Error getting last message..." + e )
errCtr++;
if (errCtr == 20){
timeout();
}
}
else if (e instanceof webdriver.error.NoSuchSessionError) {
await driver.quit();
process.exit();
}
else {
console.log(e)
//process.exit();
}
}
//process.nextTick(checkNewMessage);
}
async function timeout(){
try{
await driver.findElement(By.xpath('//div[@aria-label="Open persistent menu"]')).click();
await driver.wait(until.elementLocated(By.xpath("//span[text()='🎖️ STARTER ACCOUNT']")), 30000)
await driver.findElement(By.xpath("//span[text()='🎖️ STARTER ACCOUNT']")).click();
} catch (e){
console.log("Error Clicking Open persistent menu" + e);
}
}
function check(message){
(async () => {
try{
if (message.includes("Please type the captcha provided below to verify that you are human and not a robot"))
{
message = message.replace(/[^\x00-\x7F]/g, "");
message = message.split("\n");
await driver.findElement(By.className('_1mf _1mj')).sendKeys(message[4], Key.ENTER);
}
else if (message.includes("PROCEED")) {
await driver.findElement(By.className('_1mf _1mj')).sendKeys("PROCEED", Key.ENTER);
}
else if (message.includes("Continue")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Continue']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Continue']"))).click();
}
else if (message.includes("It's your lucky day! ")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='⛔ NO THANKS']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='⛔ NO THANKS']"))).click();
}
// QUESTIONS
else if (message.includes("What were ships never used for?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Testing power solar']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Testing power solar']"))).click();
}
else if (message.includes("What is the tall upright post called?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Mast']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Mast']"))).click();
}
else if (message.includes("What kind of machine is a ship?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='A vehicle']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='A vehicle']"))).click();
}
else if (message.includes("How were the ships powered 100 years ago?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Steam powered']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Steam powered']"))).click();
}
else if (message.includes("Which surface does ship travel?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Water']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Water']"))).click();
}
else if (message.includes("How the ships are constructed?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Naval architecture']")), 4000)
await driver.findElement(By.xpath("//span[text()='Naval architecture']")).click();
}
else if (message.includes("What is the life expectancy of a ship?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='20-30 years']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='20-30 years']"))).click();
}
else if (message.includes("What is the name of the minimum water depth a ship can safely navigate in?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Draft']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Draft']"))).click();
}
else if (message.includes("What is the difference between ships and boats?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='No distinction']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='No distinction']"))).click();
}
else if (message.includes("Where are ships usually constructed?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Shipyard']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Shipyard']"))).click();
}
//BAR
else if (message.includes("When checking someones ID it is ok to ask them to remove it from there wallet")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='True']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='True']"))).click();
}
else if (message.includes("When picking up glasses its ok to hold them at the rim.")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='False']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='False']"))).click();
}
else if (message.includes("What is the legal drinking age in virginia?")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='21']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='21']"))).click();
}
else if (message.includes("If a guest is not 21 but they are with a parent who gives them permission to drink alcohol it is ok to serve them.")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='False']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='False']"))).click();
}
else if (message.includes("What is not considered a valid form of ID")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='College ID']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='College ID']"))).click();
}
else if (message.includes("If a guest is intoxicated it is not your problem you dont have to worry about calling them a cab or notifying security")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='False']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='False']"))).click();
}
else if (message.includes("When picking up drinks from the bar never remove a drink without its drink ticket. Always stab your drink tickets when you have recieved your drink.")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='True']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='True']"))).click();
}
else if (message.includes("If you do come across a fake id you should always")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='Give ID to authority']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='Give ID to authority']"))).click();
}
else if (message.includes("When taking drink orders and serving drinks you always serve women first.")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='True']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='True']"))).click();
}
else if (message.includes("When cutting off alcohol service you should always tell a manager or supervisor")) {
await driver.wait(until.elementLocated(By.xpath("//span[text()='True']")), 4000)
await (await driver.findElement(By.xpath("//span[text()='True']"))).click();
}
//Dashboard
else if (message.includes("DASHBOARD")){
await driver.wait(until.elementLocated(By.xpath('(//div[@aria-label="CONTINUE"])[4]')), 30000)
await driver.findElement(By.xpath('(//div[@aria-label="CONTINUE"])[4]')).click();
await driver.get("https://www.messenger.com/t/106882174524725");
}
clearResendTimer();
} catch (e){
console.log(e);
}
})();
}
function startResendTimer() {
resend = setInterval(function() {
console.log("Reply Timeout");
timeout();
}, 90000);
}
function clearResendTimer() {
clearInterval(resend);
startResendTimer();
}