GDBrowser/api/messages/countMessages.js

25 lines
1,020 B
JavaScript
Raw Normal View History

const request = require('request')
const XOR = require('../../classes/XOR.js');
const xor = new XOR();
module.exports = async (app, req, res) => {
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
if (!req.body.password) return res.status(400).send("No password provided!")
2020-11-01 15:29:32 -05:00
let params = req.gdParams({
accountID: req.body.accountID,
targetAccountID: req.body.accountID,
gjp: xor.encrypt(req.body.password, 37526),
})
2020-11-01 15:29:32 -05:00
request.post(app.endpoint + 'getGJUserInfo20.php', params, async function (err, resp, body) {
2021-01-11 16:00:21 -05:00
if (err || body == '-1' || body == '-2' || !body) return res.status(400).send(`Error counting messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince()} ago.`)
else app.trackSuccess()
let count = app.parseResponse(body)[38]
if (!count) return res.status(400).send("Error fetching unread messages!")
else res.status(200).send(count)
})
}