-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
38 lines (31 loc) · 867 Bytes
/
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
const fetch = require('node-fetch')
// 0 to 1, with which to show survey
const probability = 0.04
const getSurveyUrl = 'https://era1vrrco0.execute-api.us-east-2.amazonaws.com'
const postSurveyAnswerUrl = 'https://mj9jbzlpxi.execute-api.us-east-2.amazonaws.com'
function maybeShowSurvey() {
if ((new Date().getSeconds() / 60) < probability) {
fetch(getSurveyUrl)
.then((res) => res.json())
.then((res) => console.log(`
${res.text}
You can type $ hf answer ... to answer :)
`))
}
}
async function answerSurvey(text) {
const currentSurvey = await fetch(getSurveyUrl)
.then((res) => res.json())
await fetch(postSurveyAnswerUrl, {
method: 'POST',
body: JSON.stringify({
currentSurvey: currentSurvey,
answer: text,
date: new Date(),
}),
})
}
module.exports = {
maybeShowSurvey,
answerSurvey,
}