-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (42 loc) · 1.3 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
const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');
const { authorize } = require('./gAuth.js');
const { bot } = require('./bot.js');
const { client } = require('./ww.js');
client.initialize();
// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
// Authorize a client with credentials, then call the Google Classroom API.
authorize(JSON.parse(content), listenMessages);
});
const listenMessages = (auth) => {
const classroom = google.classroom({ version: 'v1', auth });
client.on('message_create', async msg => {
let data = {
msg,
classroom
};
bot.parse(msg.body, data);
});
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout,
// });
// rl.question('> ', (message) => {
// rl.close();
// // when a new message arrives, check if bot should reply to it
// // if yes, parse it and return reply
// const data = {
// name: 'Amey',
// reply: (msg) => {
// console.log(msg);
// },
// classroom,
// };
// // pass a metadata object to bot
// bot.parse(message, data);
// // parseMessage(classroom, message);
// });
};