-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
131 lines (94 loc) · 3.45 KB
/
server.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
const puppeteer = require("puppeteer")
const schedule = require('node-schedule');
const { parseTime, parseDate, calculateEndTime } = require('./helpers');
require('dotenv').config()
const URL = process.env.MS_URL;
let page;
let browser
const gotoPage = async () => {
browser = await puppeteer.launch({headless: false});
const context = browser.defaultBrowserContext();
context.clearPermissionOverrides();
context.overridePermissions(URL, []);
page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768});
await page.goto(URL);
console.log("-- GOING TO TEAMS --");
await page.waitForSelector("#idSIButton9");
if(page.url().includes("login")){
console.log("-- LOGIN PAGE --");
await login();
}
console.log("-- HOME PAGE --");
await page.waitForSelector('#app-bar-ef56c0de-36fc-4ef8-b417-3d82ba9d073c')
await page.click("#app-bar-ef56c0de-36fc-4ef8-b417-3d82ba9d073c")
wait(4000)
await joinClass();
await page.waitForNavigation({ waitUntil: 'networkidle0' });
await page.screenshot({path: 'example.png'});
}
const login = async () => {
await page.type('#i0116', process.env.MS_EMAIL);
await page.click('#idSIButton9');
await page.waitForSelector('#i0118')
await page.type('#i0118', process.env.MS_PASS);
await wait(2000)
await page.click('#idSIButton9');
await wait(2000)
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
await useWebVersion()
await page.waitForNavigation({ waitUntil: 'networkidle0' });
}
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms))
const useWebVersion = async () => {
await page.click('a.use-app-lnk');
}
const joinClass = async (startTime, endTime) => {
console.log("-- CALANDER PAGE --");
try {
await wait(15000);
await page.click("button.node_modules--msteams-bridges-components-calendar-event-card-dist-es-src-renderers-event-card-renderer-event-card-renderer__joinButton--1AeXc");
console.log("-- JOINING MEET --");
}
catch (error) {
let joinTry = 1;
while (joinTry <= 30) {
wait(100000)
console.error("Join button not found, trying again");
await page.reload();
await joinClass()
joinTry++;
}
}
//Select continue without webcam
await page.waitForSelector('button.ts-btn')
await page.click("button.ts-btn");
// press join
await wait(5000)
const joinButton = await page.$x('//*[@id="page-content-wrapper"]/div[1]/div/calling-pre-join-screen/div/div/div[2]/div[1]/div[2]/div/div/section/div[1]/div/div/button')
await joinButton[0].click()
console.log("-- JOINED MEET --");
//wait for class duration 21:15
await wait(calculateEndTime());
const homeButton = await page.$x('//*[@id="teams-app-bar"]/ul/li[3]')
await homeButton[0].click()
wait(1000)
//Hang up
const hangUpButton = await page.$x('//*[@id="hangup-button"]')
await hangUpButton[0].click()
console.log("-- LEFT MEET --");
await wait(10000);
await browser.close()
}
const scheduleClasses = async () => {
schedule.scheduleJob(process.env.CRON_TIME, async (fireDate) => {
await gotoPage()
});
}
const init =() =>{
// Welcome to the Teams Bot
console.log("Welcome to The Teams Bot");
scheduleClasses()
}
init()