noblox.js-async 0.0.1-security → 4.6.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of noblox.js-async might be problematic. Click here for more details.
- package/.eslintrc.js +21 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
- package/.github/workflows/doc-publish.yml +33 -0
- package/.github/workflows/npmpublish.yml +70 -0
- package/.travis.yml +13 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/LICENSE +21 -0
- package/README.md +166 -3
- package/examples/cleanPlayers.js +130 -0
- package/examples/cleanWall.js +110 -0
- package/examples/revertRanks.js +100 -0
- package/examples/savePlayers.js +119 -0
- package/examples/saveWall.js +96 -0
- package/img/moderatedThumbnails/moderatedThumbnail_100x100.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_110x110.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_140x140.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_150x150.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_150x200.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_180x180.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_250x250.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_30x30.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_352x352.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_420x420.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_48x48.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_50x50.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_60x60.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_720x720.png +0 -0
- package/img/moderatedThumbnails/moderatedThumbnail_75x75.png +0 -0
- package/img/noblox-js-small.png +0 -0
- package/img/noblox-js.png +0 -0
- package/img/thumbnailSizes.png +0 -0
- package/jsDocsConfig.json +55 -0
- package/lib/accountinformation/getUserSocialLinks.js +42 -0
- package/lib/accountsettings/block.js +58 -0
- package/lib/accountsettings/unblock.js +58 -0
- package/lib/asset/deleteFromInventory.js +69 -0
- package/lib/asset/getGamePassProductInfo.js +51 -0
- package/lib/asset/getProductInfo.js +56 -0
- package/lib/asset/uploadAnimation.js +103 -0
- package/lib/asset/uploadItem.js +83 -0
- package/lib/asset/uploadModel.js +90 -0
- package/lib/avatar/avatarRules.js +38 -0
- package/lib/avatar/currentlyWearing.js +32 -0
- package/lib/avatar/getAvatar.js +35 -0
- package/lib/avatar/getCurrentAvatar.js +37 -0
- package/lib/avatar/getRecentItems.js +37 -0
- package/lib/avatar/outfitDetails.js +32 -0
- package/lib/avatar/outfits.js +37 -0
- package/lib/avatar/redrawAvatar.js +48 -0
- package/lib/avatar/removeAssetId.js +55 -0
- package/lib/avatar/setAvatarBodyColors.js +60 -0
- package/lib/avatar/setAvatarScales.js +60 -0
- package/lib/avatar/setPlayerAvatarType.js +50 -0
- package/lib/avatar/setWearingAssets.js +50 -0
- package/lib/avatar/wearAssetId.js +55 -0
- package/lib/badges/getAwardedTimestamps.js +52 -0
- package/lib/badges/getBadgeInfo.js +43 -0
- package/lib/badges/getGameBadges.js +62 -0
- package/lib/badges/getPlayerBadges.js +28 -0
- package/lib/badges/updateBadgeInfo.js +80 -0
- package/lib/cache/add.js +14 -0
- package/lib/cache/addIf.js +26 -0
- package/lib/cache/clear.js +8 -0
- package/lib/cache/get.js +28 -0
- package/lib/cache/index.js +17 -0
- package/lib/cache/new.js +12 -0
- package/lib/cache/wrap.js +25 -0
- package/lib/chat/addUsersToConversation.js +61 -0
- package/lib/chat/chatSettings.js +33 -0
- package/lib/chat/getChatMessages.js +40 -0
- package/lib/chat/getConversations.js +43 -0
- package/lib/chat/getRolloutSettings.js +35 -0
- package/lib/chat/getUnreadConversationCount.js +33 -0
- package/lib/chat/getUnreadMessages.js +38 -0
- package/lib/chat/getUserConversations.js +37 -0
- package/lib/chat/markChatAsRead.js +52 -0
- package/lib/chat/markChatAsSeen.js +50 -0
- package/lib/chat/multiGetLatestMessages.js +37 -0
- package/lib/chat/onNewConversation.js +50 -0
- package/lib/chat/onNewMessage.js +53 -0
- package/lib/chat/onNewMessageBySelf.js +50 -0
- package/lib/chat/onUserOnline.js +50 -0
- package/lib/chat/onUserTyping.js +54 -0
- package/lib/chat/removeFromGroupConversation.js +62 -0
- package/lib/chat/renameGroupConversation.js +57 -0
- package/lib/chat/sendChatMessage.js +57 -0
- package/lib/chat/setChatUserTyping.js +61 -0
- package/lib/chat/start121Conversation.js +50 -0
- package/lib/chat/startCloudEditConversation.js +50 -0
- package/lib/chat/startGroupConversation.js +62 -0
- package/lib/client/onNotification.js +70 -0
- package/lib/client/setAPIKey.js +18 -0
- package/lib/client/setCookie.js +38 -0
- package/lib/datastores/deleteDatastoreEntry.js +66 -0
- package/lib/datastores/getDatastoreEntry.js +98 -0
- package/lib/datastores/getDatastoreEntryVersions.js +83 -0
- package/lib/datastores/getDatastoreKeys.js +73 -0
- package/lib/datastores/getDatastores.js +72 -0
- package/lib/datastores/incrementDatastoreEntry.js +93 -0
- package/lib/datastores/setDatastoreEntry.js +90 -0
- package/lib/develop/canManage.js +44 -0
- package/lib/develop/configureItem.js +142 -0
- package/lib/develop/updateUniverse.js +53 -0
- package/lib/develop/updateUniverseAccess.js +55 -0
- package/lib/economy/buy.js +99 -0
- package/lib/economy/getGroupFunds.js +43 -0
- package/lib/economy/getGroupRevenueSummary.js +48 -0
- package/lib/economy/getGroupTransactions.js +32 -0
- package/lib/economy/getResaleData.js +54 -0
- package/lib/economy/getResellers.js +35 -0
- package/lib/economy/getUserTransactions.js +34 -0
- package/lib/economy/onGroupTransaction.js +74 -0
- package/lib/friends/acceptFriendRequest.js +59 -0
- package/lib/friends/declineAllFriendRequests.js +57 -0
- package/lib/friends/declineFriendRequest.js +59 -0
- package/lib/friends/getFollowers.js +61 -0
- package/lib/friends/getFollowings.js +61 -0
- package/lib/friends/getFriendRequests.js +56 -0
- package/lib/friends/getFriends.js +53 -0
- package/lib/friends/onFriendRequest.js +58 -0
- package/lib/friends/removeFriend.js +58 -0
- package/lib/friends/sendFriendRequest.js +59 -0
- package/lib/friends/unfollow.js +58 -0
- package/lib/games/addDeveloperProduct.js +65 -0
- package/lib/games/checkDeveloperProductName.js +39 -0
- package/lib/games/configureGamePass.js +146 -0
- package/lib/games/getDeveloperProducts.js +51 -0
- package/lib/games/getGameInstances.js +31 -0
- package/lib/games/getGamePasses.js +39 -0
- package/lib/games/getGameRevenue.js +49 -0
- package/lib/games/getGameSocialLinks.js +45 -0
- package/lib/games/getGroupGames.js +30 -0
- package/lib/games/getPlaceInfo.js +48 -0
- package/lib/games/getUniverseInfo.js +51 -0
- package/lib/games/updateDeveloperProduct.js +69 -0
- package/lib/groups/changeRank.js +59 -0
- package/lib/groups/deleteWallPost.js +64 -0
- package/lib/groups/deleteWallPostsByUser.js +59 -0
- package/lib/groups/demote.js +25 -0
- package/lib/groups/exile.js +59 -0
- package/lib/groups/getAuditLog.js +67 -0
- package/lib/groups/getGroup.js +57 -0
- package/lib/groups/getGroupSocialLinks.js +44 -0
- package/lib/groups/getGroups.js +88 -0
- package/lib/groups/getJoinRequest.js +52 -0
- package/lib/groups/getJoinRequests.js +58 -0
- package/lib/groups/getPlayers.js +108 -0
- package/lib/groups/getRankInGroup.js +52 -0
- package/lib/groups/getRankNameInGroup.js +52 -0
- package/lib/groups/getRole.js +64 -0
- package/lib/groups/getRolePermissions.js +51 -0
- package/lib/groups/getRoles.js +56 -0
- package/lib/groups/getShout.js +49 -0
- package/lib/groups/getWall.js +59 -0
- package/lib/groups/groupPayout.js +103 -0
- package/lib/groups/handleJoinRequest.js +60 -0
- package/lib/groups/leaveGroup.js +60 -0
- package/lib/groups/onAuditLog.js +62 -0
- package/lib/groups/onJoinRequest.js +63 -0
- package/lib/groups/onJoinRequestHandle.js +105 -0
- package/lib/groups/onShout.js +57 -0
- package/lib/groups/onWallPost.js +58 -0
- package/lib/groups/promote.js +25 -0
- package/lib/groups/searchGroups.js +32 -0
- package/lib/groups/setGroupDescription.js +65 -0
- package/lib/groups/setGroupName.js +66 -0
- package/lib/groups/setRank.js +79 -0
- package/lib/groups/shout.js +65 -0
- package/lib/index.js +30 -0
- package/lib/internal/levelOneCopy.js +16 -0
- package/lib/internal/queue.js +61 -0
- package/lib/internal/timeout.js +30 -0
- package/lib/internal/wrap.js +78 -0
- package/lib/inventory/getCollectibles.js +31 -0
- package/lib/inventory/getInventory.js +32 -0
- package/lib/inventory/getInventoryById.js +31 -0
- package/lib/inventory/getOwnership.js +54 -0
- package/lib/inventory/getUAIDs.js +47 -0
- package/lib/itemconfiguration/getGroupAssets.js +32 -0
- package/lib/options.js +26 -0
- package/lib/party/onPartyDeleted.js +53 -0
- package/lib/party/onPartyInvite.js +53 -0
- package/lib/party/onPartyJoinedGame.js +53 -0
- package/lib/party/onPartyLeftGame.js +53 -0
- package/lib/party/onPartySelfJoined.js +53 -0
- package/lib/party/onPartySelfLeft.js +53 -0
- package/lib/party/onPartyUserJoined.js +53 -0
- package/lib/party/onPartyUserLeft.js +53 -0
- package/lib/premiumfeatures/getPremium.js +51 -0
- package/lib/presence/getPresences.js +63 -0
- package/lib/privatemessages/getMessages.js +60 -0
- package/lib/privatemessages/message.js +80 -0
- package/lib/privatemessages/onMessage.js +88 -0
- package/lib/thumbnails/getLogo.js +60 -0
- package/lib/thumbnails/getPlayerThumbnail.js +121 -0
- package/lib/thumbnails/getThumbnails.js +93 -0
- package/lib/trades/acceptTrade.js +58 -0
- package/lib/trades/canTradeWith.js +48 -0
- package/lib/trades/counterTrade.js +84 -0
- package/lib/trades/declineTrade.js +58 -0
- package/lib/trades/getTradeInfo.js +52 -0
- package/lib/trades/getTrades.js +37 -0
- package/lib/trades/sendTrade.js +82 -0
- package/lib/users/getBlurb.js +36 -0
- package/lib/users/getIdFromUsername.js +53 -0
- package/lib/users/getPlayerInfo.js +100 -0
- package/lib/users/getUsernameFromId.js +44 -0
- package/lib/users/onBlurbChange.js +46 -0
- package/lib/util/clearSession.js +32 -0
- package/lib/util/generalRequest.js +61 -0
- package/lib/util/getAction.js +45 -0
- package/lib/util/getCurrentUser.js +44 -0
- package/lib/util/getGeneralToken.js +52 -0
- package/lib/util/getHash.js +29 -0
- package/lib/util/getInputs.js +37 -0
- package/lib/util/getPageResults.js +89 -0
- package/lib/util/getSenderUserId.js +30 -0
- package/lib/util/getSession.js +38 -0
- package/lib/util/getVerification.js +60 -0
- package/lib/util/getVerificationInputs.js +31 -0
- package/lib/util/http.js +110 -0
- package/lib/util/jar.js +24 -0
- package/lib/util/refreshCookie.js +52 -0
- package/lib/util/relog.js +81 -0
- package/lib/util/setOptions.js +54 -0
- package/lib/util/shortPoll.js +102 -0
- package/lib/util/threaded.js +80 -0
- package/package.json +91 -3
- package/postinstall.js +1 -0
- package/settings.json +107 -0
- package/test/accountinformation.test.js +27 -0
- package/test/accountsettings.test.js +27 -0
- package/test/asset.test.js +81 -0
- package/test/assets/Great-White-Shark-Fin.rbxm +0 -0
- package/test/assets/KeyframeSequence.rbxm +0 -0
- package/test/avatar.test.js +164 -0
- package/test/badges.test.js +96 -0
- package/test/chat.test.js +104 -0
- package/test/datastore.test.js +105 -0
- package/test/develop.test.js +53 -0
- package/test/economy.test.js +137 -0
- package/test/friends.test.js +128 -0
- package/test/games.test.js +212 -0
- package/test/groups.test.js +311 -0
- package/test/inventory.test.js +98 -0
- package/test/itemconfiguration.test.js +24 -0
- package/test/premiumfeatures.test.js +17 -0
- package/test/presence.test.js +25 -0
- package/test/privatemessages.test.js +33 -0
- package/test/thumbnails.test.js +53 -0
- package/test/users.test.js +68 -0
- package/tutorials/Authentication.md +75 -0
- package/tutorials/Event Emitters.md +26 -0
- package/tutorials/Promises.md +86 -0
- package/tutorials/VPS Authentication.md +72 -0
- package/typings/index.d.ts +2525 -0
- package/typings/jsDocs.ts +1927 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
|
4
|
+
// Args
|
5
|
+
exports.required = ['group', ['rolesetId']]
|
6
|
+
exports.optional = ['sortOrder', 'limit', 'cursor', 'jar']
|
7
|
+
|
8
|
+
// Docs
|
9
|
+
/**
|
10
|
+
* ✅ Get the players in a group for a specific role.
|
11
|
+
* @category Group
|
12
|
+
* @alias getPlayers
|
13
|
+
* @param {number} group - The id of the group.
|
14
|
+
* @param {number | Array<number>} rolesetId - The roleset's id.
|
15
|
+
* @param {SortOrder=} sortOrder - The order to get the players in.
|
16
|
+
* @param {Limit=} limit - The maximum result per a page.
|
17
|
+
* @param {string=} cursor - The cursor for the next page.
|
18
|
+
* @returns {Promise<GroupUser[]>}
|
19
|
+
* @example const noblox = require("noblox.js")
|
20
|
+
* const players = await noblox.getPlayers(1, 1117747196)
|
21
|
+
**/
|
22
|
+
|
23
|
+
// Define
|
24
|
+
function getPlayersInRoleOnPage (jar, group, rolesetId, sortOrder, limit, cursor) {
|
25
|
+
return new Promise((resolve, reject) => {
|
26
|
+
const httpOpt = {
|
27
|
+
url: `//groups.roblox.com/v1/groups/${group}/roles/${rolesetId}/users?cursor=${cursor}&limit=${limit}&sortOrder=${sortOrder}`,
|
28
|
+
options: {
|
29
|
+
method: 'GET',
|
30
|
+
jar: jar,
|
31
|
+
resolveWithFullResponse: true
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return http(httpOpt)
|
35
|
+
.then(function (res) {
|
36
|
+
if (res.statusCode === 200) {
|
37
|
+
resolve(JSON.parse(res.body))
|
38
|
+
} else {
|
39
|
+
const body = JSON.parse(res.body) || {}
|
40
|
+
if (body.errors && body.errors.length > 0) {
|
41
|
+
const errors = body.errors.map((e) => {
|
42
|
+
return e.message
|
43
|
+
})
|
44
|
+
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}).catch(error => reject(error))
|
48
|
+
})
|
49
|
+
}
|
50
|
+
|
51
|
+
function getPlayersInRole (jar, group, rolesetId, sortOrder, limit, cursor, currentPlayers) {
|
52
|
+
return new Promise((resolve, reject) => {
|
53
|
+
if (!currentPlayers) currentPlayers = []
|
54
|
+
|
55
|
+
getPlayersInRoleOnPage(jar, group, rolesetId, sortOrder, 100, cursor, currentPlayers)
|
56
|
+
.then(function (pageData) {
|
57
|
+
const nextPageCursor = pageData.nextPageCursor
|
58
|
+
const dataArray = pageData.data
|
59
|
+
|
60
|
+
if (!dataArray) return reject(new Error('Error while retrieving players!'))
|
61
|
+
|
62
|
+
currentPlayers = currentPlayers.concat(dataArray)
|
63
|
+
|
64
|
+
if (limit > 0 && currentPlayers.length >= limit) {
|
65
|
+
return resolve(currentPlayers.slice(0, limit))
|
66
|
+
} else if (nextPageCursor === null) {
|
67
|
+
return resolve(currentPlayers)
|
68
|
+
}
|
69
|
+
|
70
|
+
getPlayersInRole(jar, group, rolesetId, sortOrder, limit, nextPageCursor, currentPlayers)
|
71
|
+
.then(function (newCurrentPlayers) {
|
72
|
+
return resolve(newCurrentPlayers)
|
73
|
+
})
|
74
|
+
}).catch(error => reject(error))
|
75
|
+
})
|
76
|
+
}
|
77
|
+
|
78
|
+
async function getPlayersInRoles (jar, group, rolesetIds, sortOrder, limit, cursor) {
|
79
|
+
let currentPlayers = []
|
80
|
+
|
81
|
+
for (let i = 0; i < rolesetIds.length; i++) {
|
82
|
+
const rolesetId = rolesetIds[i]
|
83
|
+
const roleLimit = limit <= 0 ? limit : limit - currentPlayers.length
|
84
|
+
|
85
|
+
await getPlayersInRole(jar, group, rolesetId, sortOrder, roleLimit, cursor)
|
86
|
+
.then((newData) => {
|
87
|
+
currentPlayers = currentPlayers.concat(newData)
|
88
|
+
})
|
89
|
+
.catch((error) => {
|
90
|
+
throw new Error(error)
|
91
|
+
})
|
92
|
+
|
93
|
+
if (limit > 0 && currentPlayers.length >= limit) {
|
94
|
+
return currentPlayers
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
return currentPlayers
|
99
|
+
}
|
100
|
+
|
101
|
+
exports.func = function (args) {
|
102
|
+
const jar = args.jar
|
103
|
+
const rolesetIds = Array.isArray(args.rolesetId) ? args.rolesetId : [args.rolesetId]
|
104
|
+
const sortOrder = args.sortOrder || 'Desc'
|
105
|
+
const limit = args.limit || -1
|
106
|
+
const cursor = args.cursor || ''
|
107
|
+
return getPlayersInRoles(jar, args.group, rolesetIds, sortOrder, limit, cursor)
|
108
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
const cache = require('../cache')
|
4
|
+
|
5
|
+
// Args
|
6
|
+
exports.required = ['group', 'userId']
|
7
|
+
|
8
|
+
// Docs
|
9
|
+
/**
|
10
|
+
* ✅ Get the user's rank in the group.
|
11
|
+
* @category Group
|
12
|
+
* @alias getRankInGroup
|
13
|
+
* @param {number} group - The id of the group.
|
14
|
+
* @param {number} userId - The id of the user.
|
15
|
+
* @returns {Promise<number>}
|
16
|
+
* @example const noblox = require("noblox.js")
|
17
|
+
* const rankId = await noblox.getRankInGroup(1, 1)
|
18
|
+
**/
|
19
|
+
|
20
|
+
// Define
|
21
|
+
function getRankInGroup (groupId, userId) {
|
22
|
+
if (typeof groupId === 'string') {
|
23
|
+
if (!isNaN(groupId)) {
|
24
|
+
// It's a number in a string
|
25
|
+
groupId = parseInt(groupId, 10)
|
26
|
+
} else {
|
27
|
+
throw new Error('Group id should be a number')
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return http({ url: `//groups.roblox.com/v2/users/${userId}/groups/roles`, options: { json: true } }).then((body) => {
|
31
|
+
const error = body.errors && body.errors[0]
|
32
|
+
|
33
|
+
if (error) {
|
34
|
+
if (error.message === 'NotFound') {
|
35
|
+
throw new Error('An invalid UserID or GroupID was provided.')
|
36
|
+
} else {
|
37
|
+
throw new Error(error.message)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
const groupObject = body.data.find((info) => groupId === info.group.id)
|
42
|
+
|
43
|
+
return groupObject ? parseInt(groupObject.role.rank) : 0
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
exports.func = function (args) {
|
48
|
+
const id = args.userId
|
49
|
+
return cache.wrap('Rank', id, function () {
|
50
|
+
return getRankInGroup(args.group, id)
|
51
|
+
})
|
52
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
const cache = require('../cache')
|
4
|
+
|
5
|
+
// Args
|
6
|
+
exports.required = ['group', 'userId']
|
7
|
+
|
8
|
+
// Docs
|
9
|
+
/**
|
10
|
+
* ✅ Get a user's rank name in a group.
|
11
|
+
* @category Group
|
12
|
+
* @alias getRankNameInGroup
|
13
|
+
* @param {number} group - The id of the group.
|
14
|
+
* @param {number} userId - The id of the user.
|
15
|
+
* @returns {Promise<string>}
|
16
|
+
* @example const noblox = require("noblox.js")
|
17
|
+
* const rankName = await noblox.getRankNameInGroup(1, 1)
|
18
|
+
**/
|
19
|
+
|
20
|
+
// Define
|
21
|
+
function getRankNameInGroup (group, userId) {
|
22
|
+
if (typeof group === 'string') {
|
23
|
+
if (!isNaN(group)) {
|
24
|
+
// It's a number in a string
|
25
|
+
group = parseInt(group, 10)
|
26
|
+
} else {
|
27
|
+
throw new Error('Group id should be a number')
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return http({ url: `//groups.roblox.com/v2/users/${userId}/groups/roles`, options: { json: true } }).then((body) => {
|
31
|
+
const error = body.errors && body.errors[0]
|
32
|
+
|
33
|
+
if (error) {
|
34
|
+
if (error.message === 'NotFound') {
|
35
|
+
throw new Error('An invalid UserID or GroupID was provided.')
|
36
|
+
} else {
|
37
|
+
throw new Error(error.message)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
const groupObject = body.data.find((info) => group === info.group.id)
|
42
|
+
|
43
|
+
return groupObject ? groupObject.role.name : 'Guest'
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
exports.func = function (args) {
|
48
|
+
const id = args.userId
|
49
|
+
return cache.wrap('Rank', id + 'Name', function () {
|
50
|
+
return getRankNameInGroup(args.group, id)
|
51
|
+
})
|
52
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
// Dependencies
|
2
|
+
const entities = require('entities')
|
3
|
+
|
4
|
+
// Includes
|
5
|
+
const getRoles = require('./getRoles.js').func
|
6
|
+
|
7
|
+
// Args
|
8
|
+
exports.required = ['group', 'roleQuery']
|
9
|
+
exports.optional = []
|
10
|
+
|
11
|
+
// Docs
|
12
|
+
/**
|
13
|
+
* ✅ Get a role in a group.
|
14
|
+
* @category Group
|
15
|
+
* @alias getRole
|
16
|
+
* @param {number | Array<number>} group - The ID of the group or an array of roles to query.
|
17
|
+
* @param {number | string} roleQuery - The rank of a role, the name of the role, or roleset ID.
|
18
|
+
* @returns {Promise<Role>}
|
19
|
+
* @example const noblox = require("noblox.js")
|
20
|
+
* const customerRole = await noblox.getRole(1, "Customer")
|
21
|
+
**/
|
22
|
+
|
23
|
+
// Define
|
24
|
+
function getRole (roles, roleQuery) {
|
25
|
+
return new Promise((resolve, reject) => {
|
26
|
+
const result = []
|
27
|
+
|
28
|
+
for (let i = 0; i < roles.length; i++) {
|
29
|
+
const role = roles[i]
|
30
|
+
let find
|
31
|
+
if (typeof roleQuery === 'number' && roleQuery <= 255) {
|
32
|
+
find = role.rank
|
33
|
+
} else if (typeof roleQuery === 'string') {
|
34
|
+
find = entities.decodeHTML(role.name)
|
35
|
+
} else if (typeof roleQuery === 'number' || roleQuery > 255) {
|
36
|
+
find = role.id
|
37
|
+
}
|
38
|
+
|
39
|
+
if (roleQuery === find) {
|
40
|
+
result.push(role)
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if (result.length === 1) {
|
45
|
+
resolve(result[0])
|
46
|
+
} else if (result.length > 1) {
|
47
|
+
reject(new Error(`There are two or more roles with the rank ${roleQuery}. You must specify the role name.`))
|
48
|
+
} else {
|
49
|
+
reject(new Error('Role not found with provided query.'))
|
50
|
+
}
|
51
|
+
})
|
52
|
+
}
|
53
|
+
|
54
|
+
exports.func = function (args) {
|
55
|
+
if (typeof args.group === 'number' || typeof args.group === 'string') {
|
56
|
+
return getRoles({ group: parseInt(args.group, 10) }).then(function (roles) {
|
57
|
+
return getRole(roles, args.roleQuery)
|
58
|
+
})
|
59
|
+
} else if (typeof args.group === 'object') {
|
60
|
+
return getRole(args.group, args.roleQuery)
|
61
|
+
} else {
|
62
|
+
throw new Error('Please provide a valid group or an array of roles to query.')
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
|
4
|
+
exports.required = ['group', 'rolesetId']
|
5
|
+
exports.optional = ['jar']
|
6
|
+
|
7
|
+
// Docs
|
8
|
+
/**
|
9
|
+
* 🔐 Get the permissions for a role.
|
10
|
+
* @category Group
|
11
|
+
* @alias getRolePermissions
|
12
|
+
* @param {number} group - The id of the group.
|
13
|
+
* @param {number} rolesetId - The rolesetId of the role.
|
14
|
+
* @returns {Promise<RolePermissions>}
|
15
|
+
* @example const noblox = require("noblox.js")
|
16
|
+
* // Login using your cookie
|
17
|
+
* const rolePermissions = await noblox.getRolePermissions(1, 1117747196)
|
18
|
+
**/
|
19
|
+
|
20
|
+
function getRolePermissions (group, rolesetId, jar) {
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
const httpOpt = {
|
23
|
+
url: `https://groups.roblox.com/v1/groups/${group}/roles/${rolesetId}/permissions`,
|
24
|
+
options: {
|
25
|
+
method: 'GET',
|
26
|
+
resolveWithFullResponse: true,
|
27
|
+
jar: jar
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
return http(httpOpt)
|
32
|
+
.then(function (res) {
|
33
|
+
const responseData = JSON.parse(res.body)
|
34
|
+
if (res.statusCode !== 200) {
|
35
|
+
let error = 'An unknown error has occurred.'
|
36
|
+
if (responseData && responseData.errors) {
|
37
|
+
error = responseData.errors.map((e) => e.message).join('\n')
|
38
|
+
}
|
39
|
+
reject(new Error(error))
|
40
|
+
} else {
|
41
|
+
resolve(responseData)
|
42
|
+
}
|
43
|
+
}).catch(error => reject(error))
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
// Define
|
48
|
+
exports.func = function (args) {
|
49
|
+
const jar = args.jar
|
50
|
+
return getRolePermissions(args.group, args.rolesetId, jar)
|
51
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
const cache = require('../cache')
|
4
|
+
|
5
|
+
// Args
|
6
|
+
exports.required = ['group']
|
7
|
+
|
8
|
+
// Docs
|
9
|
+
/**
|
10
|
+
* ✅ Get the roles in a group.
|
11
|
+
* @category Group
|
12
|
+
* @alias getRoles
|
13
|
+
* @param {number} group - The id of the group.
|
14
|
+
* @returns {Promise<Role[]>}
|
15
|
+
* @example const noblox = require("noblox.js")
|
16
|
+
* const roles = await noblox.getRoles(1)
|
17
|
+
**/
|
18
|
+
|
19
|
+
// Define
|
20
|
+
function getRoles (group) {
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
const httpOpt = {
|
23
|
+
url: `https://groups.roblox.com/v1/groups/${group}/roles`,
|
24
|
+
options: {
|
25
|
+
method: 'GET',
|
26
|
+
resolveWithFullResponse: true
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return http(httpOpt)
|
30
|
+
.then(function (res) {
|
31
|
+
const responseData = JSON.parse(res.body)
|
32
|
+
if (res.statusCode !== 200) {
|
33
|
+
let error = 'An unknown error has occurred.'
|
34
|
+
if (responseData && responseData.errors) {
|
35
|
+
error = responseData.errors.map((e) => e.message).join('\n')
|
36
|
+
}
|
37
|
+
reject(new Error(error))
|
38
|
+
} else {
|
39
|
+
let roles = responseData.roles
|
40
|
+
roles = roles.sort((a, b) => a.rank - b.rank)
|
41
|
+
for (let i = 0; i < roles.length; i++) {
|
42
|
+
const role = roles[i]
|
43
|
+
role.ID = role.id
|
44
|
+
}
|
45
|
+
resolve(roles)
|
46
|
+
}
|
47
|
+
}).catch(error => reject(error))
|
48
|
+
})
|
49
|
+
}
|
50
|
+
|
51
|
+
exports.func = function (args) {
|
52
|
+
const group = args.group
|
53
|
+
return cache.wrap('Roles', group, function () {
|
54
|
+
return getRoles(group)
|
55
|
+
})
|
56
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// Includes
|
2
|
+
const http = require('../util/http.js').func
|
3
|
+
|
4
|
+
// Args
|
5
|
+
exports.required = ['group']
|
6
|
+
exports.optional = []
|
7
|
+
|
8
|
+
// Docs
|
9
|
+
/**
|
10
|
+
* 🔓 Get the group's shout.
|
11
|
+
* @category Group
|
12
|
+
* @alias getShout
|
13
|
+
* @param {number} group - The id of the group.
|
14
|
+
* @returns {Promise<GroupShout>}
|
15
|
+
* @example const noblox = require("noblox.js")
|
16
|
+
* const groupShout = await noblox.getShout(1)
|
17
|
+
**/
|
18
|
+
|
19
|
+
// Define
|
20
|
+
function getShout (group, jar) {
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
const httpOpt = {
|
23
|
+
url: `https://groups.roblox.com/v1/groups/${group}`,
|
24
|
+
options: {
|
25
|
+
method: 'GET',
|
26
|
+
resolveWithFullResponse: true,
|
27
|
+
jar: jar
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
return http(httpOpt)
|
32
|
+
.then(function (res) {
|
33
|
+
const responseData = JSON.parse(res.body)
|
34
|
+
if (res.statusCode === 400) {
|
35
|
+
reject(new Error('The group is invalid or does not exist.'))
|
36
|
+
}
|
37
|
+
if (responseData.shout === null) {
|
38
|
+
reject(new Error('You do not have permissions to view the shout for the group.'))
|
39
|
+
} else {
|
40
|
+
resolve(responseData.shout)
|
41
|
+
}
|
42
|
+
})
|
43
|
+
.catch(error => reject(error))
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
exports.func = function (args) {
|
48
|
+
return getShout(args.group, args.jar)
|
49
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
const http = require('../util/http.js').func
|
2
|
+
|
3
|
+
exports.required = ['group']
|
4
|
+
exports.optional = ['sortOrder', 'limit', 'cursor', 'jar']
|
5
|
+
|
6
|
+
// Docs
|
7
|
+
/**
|
8
|
+
* 🔓 Get the posts on the group wall.
|
9
|
+
* @category Group
|
10
|
+
* @alias getWall
|
11
|
+
* @param {number} group - The id of the group.
|
12
|
+
* @param {SortOrder=} sortOrder - The order to get the players in.
|
13
|
+
* @param {Limit=} limit - The maximum result per a page.
|
14
|
+
* @param {string=} cursor - The cursor for the next page.
|
15
|
+
* @returns {Promise<WallPostPage>}
|
16
|
+
* @example const noblox = require("noblox.js")
|
17
|
+
* // Login using your cookie
|
18
|
+
* const wallPosts = await noblox.getWall(1)
|
19
|
+
**/
|
20
|
+
|
21
|
+
function getPosts (group, sortOrder, limit, cursor, jar) {
|
22
|
+
return new Promise((resolve, reject) => {
|
23
|
+
const httpOpt = {
|
24
|
+
url: `https://groups.roblox.com/v2/groups/${group}/wall/posts?limit=${limit}&sortOrder=${sortOrder}&cursor=${cursor}`,
|
25
|
+
options: {
|
26
|
+
method: 'GET',
|
27
|
+
resolveWithFullResponse: true,
|
28
|
+
jar: jar
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return http(httpOpt)
|
33
|
+
.then(function (res) {
|
34
|
+
const responseData = JSON.parse(res.body)
|
35
|
+
if (res.statusCode !== 200) {
|
36
|
+
let error = 'An unknown error has occurred.'
|
37
|
+
if (responseData && responseData.errors) {
|
38
|
+
error = responseData.errors.map((e) => e.message).join('\n')
|
39
|
+
}
|
40
|
+
reject(new Error(error))
|
41
|
+
} else {
|
42
|
+
responseData.data = responseData.data.map((entry) => {
|
43
|
+
entry.created = new Date(entry.created)
|
44
|
+
entry.updated = new Date(entry.updated)
|
45
|
+
return entry
|
46
|
+
})
|
47
|
+
resolve(responseData)
|
48
|
+
}
|
49
|
+
}).catch(error => reject(error))
|
50
|
+
})
|
51
|
+
}
|
52
|
+
|
53
|
+
// Define
|
54
|
+
exports.func = function (args) {
|
55
|
+
const sortOrder = args.sortOrder || 'Asc'
|
56
|
+
const limit = args.limit || 100
|
57
|
+
const cursor = args.cursor || ''
|
58
|
+
return getPosts(args.group, sortOrder, limit, cursor, args.jar)
|
59
|
+
}
|
@@ -0,0 +1,103 @@
|
|
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', 'member', 'amount']
|
7
|
+
exports.optional = ['recurring', 'usePercentage', 'jar']
|
8
|
+
|
9
|
+
// Docs
|
10
|
+
/**
|
11
|
+
* 🔐 Pay group funds out to a user.
|
12
|
+
* @category Group
|
13
|
+
* @alias groupPayout
|
14
|
+
* @param {number} group - The id of the group.
|
15
|
+
* @param {number | Array<number>} member - The member or array of members to payout.
|
16
|
+
* @param {number} amount - The amount of Robux for each recipient to receive.
|
17
|
+
* @param {boolean=} [recurring=false] - If the payment is recurring.
|
18
|
+
* @param {boolean=} [usePercentage=false] - If the amount is a percentage.
|
19
|
+
* @returns {Promise<void>}
|
20
|
+
* @example const noblox = require("noblox.js")
|
21
|
+
* // Login using your cookie
|
22
|
+
* noblox.groupPayout(1117747196, 55549140, 30)
|
23
|
+
**/
|
24
|
+
|
25
|
+
// Define
|
26
|
+
function groupPayout (jar, token, group, data, recurring, usePercentage) {
|
27
|
+
return new Promise((resolve, reject) => {
|
28
|
+
const httpOpt = {
|
29
|
+
url: `//groups.roblox.com/v1/groups/${group}/payouts${recurring ? '/recurring' : ''}`,
|
30
|
+
options: {
|
31
|
+
resolveWithFullResponse: true,
|
32
|
+
method: 'POST',
|
33
|
+
jar: jar,
|
34
|
+
headers: {
|
35
|
+
'X-CSRF-TOKEN': token,
|
36
|
+
'Content-Type': 'application/json'
|
37
|
+
},
|
38
|
+
body: JSON.stringify({
|
39
|
+
PayoutType: (usePercentage ? 'Percentage' : 'FixedAmount'),
|
40
|
+
Recipients: data
|
41
|
+
})
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return http(httpOpt)
|
45
|
+
.then(function (res) {
|
46
|
+
if (res.statusCode === 200) {
|
47
|
+
resolve()
|
48
|
+
} else {
|
49
|
+
const body = JSON.parse(res.body) || {}
|
50
|
+
if (body.errors && body.errors.length > 0) {
|
51
|
+
const errors = body.errors.map((e) => {
|
52
|
+
return e.message
|
53
|
+
})
|
54
|
+
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}).catch(error => reject(error))
|
58
|
+
})
|
59
|
+
}
|
60
|
+
|
61
|
+
// Although I would normally leave it to the endpoint to error when incorrect percentages are given, it's not very reliable so I'll do it instead
|
62
|
+
function isPercentage (num) {
|
63
|
+
return num >= 0 && num <= 100 && num % 1 === 0
|
64
|
+
}
|
65
|
+
|
66
|
+
exports.func = function (args) {
|
67
|
+
const jar = args.jar
|
68
|
+
let member = args.member
|
69
|
+
let amount = args.amount
|
70
|
+
const recurring = args.recurring || false
|
71
|
+
const usePercentage = recurring ? true : args.usePercentage
|
72
|
+
const data = []
|
73
|
+
|
74
|
+
if (!(member instanceof Array)) {
|
75
|
+
member = [member]
|
76
|
+
amount = [amount]
|
77
|
+
} else if (!(amount instanceof Array) || member.length !== amount.length) {
|
78
|
+
throw new Error('If member is an array amount must be a parallel array')
|
79
|
+
}
|
80
|
+
let total = 0
|
81
|
+
for (let i = 0; i < member.length; i++) {
|
82
|
+
const value = amount[i]
|
83
|
+
if (usePercentage) {
|
84
|
+
if (!isPercentage(value)) {
|
85
|
+
throw new Error('Percent values must be whole numbers between 0 and 100 inclusive')
|
86
|
+
}
|
87
|
+
total += value
|
88
|
+
if (total > 100) {
|
89
|
+
throw new Error('Sum of percent values must be less than 100')
|
90
|
+
}
|
91
|
+
}
|
92
|
+
data.push({
|
93
|
+
recipientId: member[i],
|
94
|
+
recipientType: 'User',
|
95
|
+
amount: value
|
96
|
+
})
|
97
|
+
}
|
98
|
+
|
99
|
+
return getGeneralToken({ jar: jar })
|
100
|
+
.then(function (xcsrf) {
|
101
|
+
return groupPayout(jar, xcsrf, args.group, data, recurring, usePercentage)
|
102
|
+
})
|
103
|
+
}
|
@@ -0,0 +1,60 @@
|
|
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', 'userId', 'accept']
|
7
|
+
exports.optional = ['jar']
|
8
|
+
|
9
|
+
// Docs
|
10
|
+
/**
|
11
|
+
* 🔐 Accept/decline a user's join request.
|
12
|
+
* @category Group
|
13
|
+
* @alias handleJoinRequest
|
14
|
+
* @param {number} group - The id of the group.
|
15
|
+
* @param {number} userId - The id of the user.
|
16
|
+
* @param {boolean} accept - If the user should be accepted into the group.
|
17
|
+
* @returns {Promise<void>}
|
18
|
+
* @example const noblox = require("noblox.js")
|
19
|
+
* // Login using your cookie
|
20
|
+
* noblox.handleJoinRequest(1, 1, true)
|
21
|
+
**/
|
22
|
+
|
23
|
+
function handleJoinRequest (group, userId, accept, jar, xcsrf) {
|
24
|
+
return new Promise((resolve, reject) => {
|
25
|
+
const httpOpt = {
|
26
|
+
url: `https://groups.roblox.com/v1/groups/${group}/join-requests/users/${userId}`,
|
27
|
+
options: {
|
28
|
+
method: accept ? 'POST' : 'DELETE',
|
29
|
+
resolveWithFullResponse: true,
|
30
|
+
jar: jar,
|
31
|
+
headers: {
|
32
|
+
'X-CSRF-TOKEN': xcsrf
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return http(httpOpt)
|
38
|
+
.then(function (res) {
|
39
|
+
const responseData = JSON.parse(res.body)
|
40
|
+
if (res.statusCode !== 200) {
|
41
|
+
let error = 'An unknown error has occurred.'
|
42
|
+
if (responseData && responseData.errors) {
|
43
|
+
error = responseData.errors.map((e) => e.message).join('\n')
|
44
|
+
}
|
45
|
+
reject(new Error(error))
|
46
|
+
} else {
|
47
|
+
resolve()
|
48
|
+
}
|
49
|
+
}).catch(error => reject(error))
|
50
|
+
})
|
51
|
+
}
|
52
|
+
|
53
|
+
// Define
|
54
|
+
exports.func = function (args) {
|
55
|
+
const jar = args.jar
|
56
|
+
return getGeneralToken({ jar: jar })
|
57
|
+
.then(function (xcsrf) {
|
58
|
+
return handleJoinRequest(args.group, args.userId, args.accept, args.jar, xcsrf)
|
59
|
+
})
|
60
|
+
}
|