Skip to content

Commit e54bc76

Browse files
authored
Create unban.js
Unbans a User from Roblox group.
1 parent 793f993 commit e54bc76

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

lib/groups/unban.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Includes
2+
const http = require('../util/http.js').func
3+
const getGeneralToken = require('../util/getGeneralToken.js').func
4+
5+
// Args
6+
exports.required = ['group', 'target']
7+
exports.optional = ['jar']
8+
9+
// Docs
10+
/**
11+
* 🔐 Unban a user from a group.
12+
* @category Group
13+
* @alias unban
14+
* @param {number} group - The id of the group.
15+
* @param {number} target - The userId of the user being Unbanned.
16+
* @returns {Promise<void>}
17+
* @example const noblox = require("noblox.js")
18+
* // Login using your cookie
19+
* noblox.unban(1, 2)
20+
**/
21+
22+
function unbanUser (group, target, jar, xcsrf) {
23+
return new Promise((resolve, reject) => {
24+
const httpOpt = {
25+
url: `https://groups.roblox.com/v1/groups/${group}/bans/${target}`,
26+
options: {
27+
method: 'DELETE',
28+
resolveWithFullResponse: true,
29+
jar,
30+
headers: {
31+
'X-CSRF-TOKEN': xcsrf
32+
}
33+
}
34+
}
35+
36+
return http(httpOpt)
37+
.then(function (res) {
38+
const responseData = JSON.parse(res.body)
39+
if (res.statusCode !== 200) {
40+
let error = 'An unknown error has occurred.'
41+
if (responseData && responseData.errors) {
42+
error = responseData.errors.map((e) => e.message).join('\n')
43+
}
44+
reject(new Error(error))
45+
} else {
46+
resolve()
47+
}
48+
}).catch(error => reject(error))
49+
})
50+
}
51+
52+
// Define
53+
exports.func = function (args) {
54+
const jar = args.jar
55+
return getGeneralToken({ jar })
56+
.then(function (xcsrf) {
57+
return unbanUser(args.group, args.target, args.jar, xcsrf)
58+
})
59+
}

0 commit comments

Comments
 (0)