Skip to content

Commit 2c06428

Browse files
committed
Implement declineAllFriendRequests
1 parent b2f92e4 commit 2c06428

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/user/declineAllFriendRequests.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Includes
2+
var http = require('../util/http.js').func
3+
var getGeneralToken = require('../util/getGeneralToken.js').func
4+
5+
// Args
6+
exports.required = []
7+
exports.optional = ['jar']
8+
9+
// Define
10+
function declineAllFriendRequests (jar, token) {
11+
return new Promise((resolve, reject) => {
12+
var httpOpt = {
13+
url: '//friends.roblox.com/v1/user/friend-requests/decline-all',
14+
options: {
15+
method: 'POST',
16+
jar: jar,
17+
headers: {
18+
'X-CSRF-TOKEN': token
19+
},
20+
resolveWithFullResponse: true
21+
}
22+
}
23+
return http(httpOpt)
24+
.then(function (res) {
25+
if (res.statusCode === 200) {
26+
resolve()
27+
} else {
28+
const body = JSON.parse(res.body) || {}
29+
if (body.errors && body.errors.length > 0) {
30+
var errors = body.errors.map((e) => {
31+
return e.message
32+
})
33+
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
34+
}
35+
}
36+
})
37+
})
38+
}
39+
40+
exports.func = function (args) {
41+
var jar = args.jar
42+
return getGeneralToken({ jar: jar })
43+
.then(function (xcsrf) {
44+
return declineAllFriendRequests(jar, xcsrf)
45+
})
46+
}

0 commit comments

Comments
 (0)