This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
/
robot.js
42 lines (41 loc) · 1.7 KB
/
robot.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
const QueryString = require('query-string')
const Tnwz = require('./common/tnwz')
const QuizModel = require('./database/quiz-model')
// AngProxy 只支持 yield 语法,暂不支持 await
module.exports = {
* beforeSendRequest (requestDetail) {
// 原先采用的是改数据发送,经测试发现会频繁的提示需要重新登录,所以改为只提示答案了
},
* beforeSendResponse (requestDetail, responseDetail) {
let data
let body
try {
body = JSON.parse(responseDetail.response.body.toString())
data = body.data
// console.log('[response]', response)
} catch (e) {}
if (requestDetail.url.indexOf('/question/bat/findQuiz') !== -1) {
this._findQuiz = data
console.log('[题目信息]', JSON.stringify(data))
// 从题库里找答案
this._quiz = yield QuizModel.findOne({quiz: this._findQuiz.quiz})
if (this._quiz) {
const answer = Tnwz.transformAnswer(this._quiz, this._findQuiz) - 1
const option = this._findQuiz.options[answer]
this._findQuiz.options[answer] = '√ ' + option
body.data = this._findQuiz
const response = Object.assign({}, responseDetail.response)
response.body = JSON.stringify(body)
console.log('[题库有答案]', option)
return {response}
}
} else if (requestDetail.url.indexOf('/question/bat/choose') !== -1) {
// 提交完答案,会返回正确答案,如果题库没有,就存起来
if (!this._quiz) {
const quizModel = new QuizModel(Object.assign(this._findQuiz, {answer: data.answer}))
yield quizModel.save()
console.log('[保存到题库]', JSON.stringify(this._findQuiz), data.answer)
}
}
}
}