roblox-ts-core 0.0.1-security.1 → 4.6.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of roblox-ts-core might be problematic. Click here for more details.

Files changed (259) hide show
  1. package/.eslintrc.js +21 -0
  2. package/.github/FUNDING.yml +3 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
  5. package/.github/workflows/doc-publish.yml +33 -0
  6. package/.github/workflows/npmpublish.yml +70 -0
  7. package/.travis.yml +13 -0
  8. package/CODE_OF_CONDUCT.md +76 -0
  9. package/LICENSE +21 -0
  10. package/README.md +166 -3
  11. package/examples/cleanPlayers.js +130 -0
  12. package/examples/cleanWall.js +110 -0
  13. package/examples/revertRanks.js +100 -0
  14. package/examples/savePlayers.js +119 -0
  15. package/examples/saveWall.js +96 -0
  16. package/img/moderatedThumbnails/moderatedThumbnail_100x100.png +0 -0
  17. package/img/moderatedThumbnails/moderatedThumbnail_110x110.png +0 -0
  18. package/img/moderatedThumbnails/moderatedThumbnail_140x140.png +0 -0
  19. package/img/moderatedThumbnails/moderatedThumbnail_150x150.png +0 -0
  20. package/img/moderatedThumbnails/moderatedThumbnail_150x200.png +0 -0
  21. package/img/moderatedThumbnails/moderatedThumbnail_180x180.png +0 -0
  22. package/img/moderatedThumbnails/moderatedThumbnail_250x250.png +0 -0
  23. package/img/moderatedThumbnails/moderatedThumbnail_30x30.png +0 -0
  24. package/img/moderatedThumbnails/moderatedThumbnail_352x352.png +0 -0
  25. package/img/moderatedThumbnails/moderatedThumbnail_420x420.png +0 -0
  26. package/img/moderatedThumbnails/moderatedThumbnail_48x48.png +0 -0
  27. package/img/moderatedThumbnails/moderatedThumbnail_50x50.png +0 -0
  28. package/img/moderatedThumbnails/moderatedThumbnail_60x60.png +0 -0
  29. package/img/moderatedThumbnails/moderatedThumbnail_720x720.png +0 -0
  30. package/img/moderatedThumbnails/moderatedThumbnail_75x75.png +0 -0
  31. package/img/noblox-js-small.png +0 -0
  32. package/img/noblox-js.png +0 -0
  33. package/img/thumbnailSizes.png +0 -0
  34. package/jsDocsConfig.json +55 -0
  35. package/lib/accountinformation/getUserSocialLinks.js +42 -0
  36. package/lib/accountsettings/block.js +58 -0
  37. package/lib/accountsettings/unblock.js +58 -0
  38. package/lib/asset/deleteFromInventory.js +69 -0
  39. package/lib/asset/getGamePassProductInfo.js +51 -0
  40. package/lib/asset/getProductInfo.js +56 -0
  41. package/lib/asset/uploadAnimation.js +103 -0
  42. package/lib/asset/uploadItem.js +83 -0
  43. package/lib/asset/uploadModel.js +90 -0
  44. package/lib/avatar/avatarRules.js +38 -0
  45. package/lib/avatar/currentlyWearing.js +32 -0
  46. package/lib/avatar/getAvatar.js +35 -0
  47. package/lib/avatar/getCurrentAvatar.js +37 -0
  48. package/lib/avatar/getRecentItems.js +37 -0
  49. package/lib/avatar/outfitDetails.js +32 -0
  50. package/lib/avatar/outfits.js +37 -0
  51. package/lib/avatar/redrawAvatar.js +48 -0
  52. package/lib/avatar/removeAssetId.js +55 -0
  53. package/lib/avatar/setAvatarBodyColors.js +60 -0
  54. package/lib/avatar/setAvatarScales.js +60 -0
  55. package/lib/avatar/setPlayerAvatarType.js +50 -0
  56. package/lib/avatar/setWearingAssets.js +50 -0
  57. package/lib/avatar/wearAssetId.js +55 -0
  58. package/lib/badges/getAwardedTimestamps.js +52 -0
  59. package/lib/badges/getBadgeInfo.js +43 -0
  60. package/lib/badges/getGameBadges.js +62 -0
  61. package/lib/badges/getPlayerBadges.js +28 -0
  62. package/lib/badges/updateBadgeInfo.js +80 -0
  63. package/lib/cache/add.js +14 -0
  64. package/lib/cache/addIf.js +26 -0
  65. package/lib/cache/clear.js +8 -0
  66. package/lib/cache/get.js +28 -0
  67. package/lib/cache/index.js +17 -0
  68. package/lib/cache/new.js +12 -0
  69. package/lib/cache/wrap.js +25 -0
  70. package/lib/chat/addUsersToConversation.js +61 -0
  71. package/lib/chat/chatSettings.js +33 -0
  72. package/lib/chat/getChatMessages.js +40 -0
  73. package/lib/chat/getConversations.js +43 -0
  74. package/lib/chat/getRolloutSettings.js +35 -0
  75. package/lib/chat/getUnreadConversationCount.js +33 -0
  76. package/lib/chat/getUnreadMessages.js +38 -0
  77. package/lib/chat/getUserConversations.js +37 -0
  78. package/lib/chat/markChatAsRead.js +52 -0
  79. package/lib/chat/markChatAsSeen.js +50 -0
  80. package/lib/chat/multiGetLatestMessages.js +37 -0
  81. package/lib/chat/onNewConversation.js +50 -0
  82. package/lib/chat/onNewMessage.js +53 -0
  83. package/lib/chat/onNewMessageBySelf.js +50 -0
  84. package/lib/chat/onUserOnline.js +50 -0
  85. package/lib/chat/onUserTyping.js +54 -0
  86. package/lib/chat/removeFromGroupConversation.js +62 -0
  87. package/lib/chat/renameGroupConversation.js +57 -0
  88. package/lib/chat/sendChatMessage.js +57 -0
  89. package/lib/chat/setChatUserTyping.js +61 -0
  90. package/lib/chat/start121Conversation.js +50 -0
  91. package/lib/chat/startCloudEditConversation.js +50 -0
  92. package/lib/chat/startGroupConversation.js +62 -0
  93. package/lib/client/onNotification.js +70 -0
  94. package/lib/client/setAPIKey.js +18 -0
  95. package/lib/client/setCookie.js +38 -0
  96. package/lib/datastores/deleteDatastoreEntry.js +66 -0
  97. package/lib/datastores/getDatastoreEntry.js +98 -0
  98. package/lib/datastores/getDatastoreEntryVersions.js +83 -0
  99. package/lib/datastores/getDatastoreKeys.js +73 -0
  100. package/lib/datastores/getDatastores.js +72 -0
  101. package/lib/datastores/incrementDatastoreEntry.js +93 -0
  102. package/lib/datastores/setDatastoreEntry.js +90 -0
  103. package/lib/develop/canManage.js +44 -0
  104. package/lib/develop/configureItem.js +142 -0
  105. package/lib/develop/updateUniverse.js +53 -0
  106. package/lib/develop/updateUniverseAccess.js +55 -0
  107. package/lib/economy/buy.js +99 -0
  108. package/lib/economy/getGroupFunds.js +43 -0
  109. package/lib/economy/getGroupRevenueSummary.js +48 -0
  110. package/lib/economy/getGroupTransactions.js +32 -0
  111. package/lib/economy/getResaleData.js +54 -0
  112. package/lib/economy/getResellers.js +35 -0
  113. package/lib/economy/getUserTransactions.js +34 -0
  114. package/lib/economy/onGroupTransaction.js +74 -0
  115. package/lib/friends/acceptFriendRequest.js +59 -0
  116. package/lib/friends/declineAllFriendRequests.js +57 -0
  117. package/lib/friends/declineFriendRequest.js +59 -0
  118. package/lib/friends/getFollowers.js +61 -0
  119. package/lib/friends/getFollowings.js +61 -0
  120. package/lib/friends/getFriendRequests.js +56 -0
  121. package/lib/friends/getFriends.js +53 -0
  122. package/lib/friends/onFriendRequest.js +58 -0
  123. package/lib/friends/removeFriend.js +58 -0
  124. package/lib/friends/sendFriendRequest.js +59 -0
  125. package/lib/friends/unfollow.js +58 -0
  126. package/lib/games/addDeveloperProduct.js +65 -0
  127. package/lib/games/checkDeveloperProductName.js +39 -0
  128. package/lib/games/configureGamePass.js +146 -0
  129. package/lib/games/getDeveloperProducts.js +51 -0
  130. package/lib/games/getGameInstances.js +31 -0
  131. package/lib/games/getGamePasses.js +39 -0
  132. package/lib/games/getGameRevenue.js +49 -0
  133. package/lib/games/getGameSocialLinks.js +45 -0
  134. package/lib/games/getGroupGames.js +30 -0
  135. package/lib/games/getPlaceInfo.js +48 -0
  136. package/lib/games/getUniverseInfo.js +51 -0
  137. package/lib/games/updateDeveloperProduct.js +69 -0
  138. package/lib/groups/changeRank.js +59 -0
  139. package/lib/groups/deleteWallPost.js +64 -0
  140. package/lib/groups/deleteWallPostsByUser.js +59 -0
  141. package/lib/groups/demote.js +25 -0
  142. package/lib/groups/exile.js +59 -0
  143. package/lib/groups/getAuditLog.js +67 -0
  144. package/lib/groups/getGroup.js +57 -0
  145. package/lib/groups/getGroupSocialLinks.js +44 -0
  146. package/lib/groups/getGroups.js +88 -0
  147. package/lib/groups/getJoinRequest.js +52 -0
  148. package/lib/groups/getJoinRequests.js +58 -0
  149. package/lib/groups/getPlayers.js +108 -0
  150. package/lib/groups/getRankInGroup.js +52 -0
  151. package/lib/groups/getRankNameInGroup.js +52 -0
  152. package/lib/groups/getRole.js +64 -0
  153. package/lib/groups/getRolePermissions.js +51 -0
  154. package/lib/groups/getRoles.js +56 -0
  155. package/lib/groups/getShout.js +49 -0
  156. package/lib/groups/getWall.js +59 -0
  157. package/lib/groups/groupPayout.js +103 -0
  158. package/lib/groups/handleJoinRequest.js +60 -0
  159. package/lib/groups/leaveGroup.js +60 -0
  160. package/lib/groups/onAuditLog.js +62 -0
  161. package/lib/groups/onJoinRequest.js +63 -0
  162. package/lib/groups/onJoinRequestHandle.js +105 -0
  163. package/lib/groups/onShout.js +57 -0
  164. package/lib/groups/onWallPost.js +58 -0
  165. package/lib/groups/promote.js +25 -0
  166. package/lib/groups/searchGroups.js +32 -0
  167. package/lib/groups/setGroupDescription.js +65 -0
  168. package/lib/groups/setGroupName.js +66 -0
  169. package/lib/groups/setRank.js +79 -0
  170. package/lib/groups/shout.js +65 -0
  171. package/lib/index.js +30 -0
  172. package/lib/internal/levelOneCopy.js +16 -0
  173. package/lib/internal/queue.js +61 -0
  174. package/lib/internal/timeout.js +30 -0
  175. package/lib/internal/wrap.js +78 -0
  176. package/lib/inventory/getCollectibles.js +31 -0
  177. package/lib/inventory/getInventory.js +32 -0
  178. package/lib/inventory/getInventoryById.js +31 -0
  179. package/lib/inventory/getOwnership.js +54 -0
  180. package/lib/inventory/getUAIDs.js +47 -0
  181. package/lib/itemconfiguration/getGroupAssets.js +32 -0
  182. package/lib/options.js +26 -0
  183. package/lib/party/onPartyDeleted.js +53 -0
  184. package/lib/party/onPartyInvite.js +53 -0
  185. package/lib/party/onPartyJoinedGame.js +53 -0
  186. package/lib/party/onPartyLeftGame.js +53 -0
  187. package/lib/party/onPartySelfJoined.js +53 -0
  188. package/lib/party/onPartySelfLeft.js +53 -0
  189. package/lib/party/onPartyUserJoined.js +53 -0
  190. package/lib/party/onPartyUserLeft.js +53 -0
  191. package/lib/premiumfeatures/getPremium.js +51 -0
  192. package/lib/presence/getPresences.js +63 -0
  193. package/lib/privatemessages/getMessages.js +60 -0
  194. package/lib/privatemessages/message.js +80 -0
  195. package/lib/privatemessages/onMessage.js +88 -0
  196. package/lib/thumbnails/getLogo.js +60 -0
  197. package/lib/thumbnails/getPlayerThumbnail.js +121 -0
  198. package/lib/thumbnails/getThumbnails.js +93 -0
  199. package/lib/trades/acceptTrade.js +58 -0
  200. package/lib/trades/canTradeWith.js +48 -0
  201. package/lib/trades/counterTrade.js +84 -0
  202. package/lib/trades/declineTrade.js +58 -0
  203. package/lib/trades/getTradeInfo.js +52 -0
  204. package/lib/trades/getTrades.js +37 -0
  205. package/lib/trades/sendTrade.js +82 -0
  206. package/lib/users/getBlurb.js +36 -0
  207. package/lib/users/getIdFromUsername.js +53 -0
  208. package/lib/users/getPlayerInfo.js +100 -0
  209. package/lib/users/getUsernameFromId.js +44 -0
  210. package/lib/users/onBlurbChange.js +46 -0
  211. package/lib/util/clearSession.js +32 -0
  212. package/lib/util/generalRequest.js +61 -0
  213. package/lib/util/getAction.js +45 -0
  214. package/lib/util/getCurrentUser.js +44 -0
  215. package/lib/util/getGeneralToken.js +52 -0
  216. package/lib/util/getHash.js +29 -0
  217. package/lib/util/getInputs.js +37 -0
  218. package/lib/util/getPageResults.js +89 -0
  219. package/lib/util/getSenderUserId.js +30 -0
  220. package/lib/util/getSession.js +38 -0
  221. package/lib/util/getVerification.js +60 -0
  222. package/lib/util/getVerificationInputs.js +31 -0
  223. package/lib/util/http.js +110 -0
  224. package/lib/util/jar.js +24 -0
  225. package/lib/util/refreshCookie.js +52 -0
  226. package/lib/util/relog.js +81 -0
  227. package/lib/util/setOptions.js +54 -0
  228. package/lib/util/shortPoll.js +102 -0
  229. package/lib/util/threaded.js +80 -0
  230. package/package.json +91 -3
  231. package/postinstall.js +1 -0
  232. package/settings.json +107 -0
  233. package/test/accountinformation.test.js +27 -0
  234. package/test/accountsettings.test.js +27 -0
  235. package/test/asset.test.js +81 -0
  236. package/test/assets/Great-White-Shark-Fin.rbxm +0 -0
  237. package/test/assets/KeyframeSequence.rbxm +0 -0
  238. package/test/avatar.test.js +164 -0
  239. package/test/badges.test.js +96 -0
  240. package/test/chat.test.js +104 -0
  241. package/test/datastore.test.js +105 -0
  242. package/test/develop.test.js +53 -0
  243. package/test/economy.test.js +137 -0
  244. package/test/friends.test.js +128 -0
  245. package/test/games.test.js +212 -0
  246. package/test/groups.test.js +311 -0
  247. package/test/inventory.test.js +98 -0
  248. package/test/itemconfiguration.test.js +24 -0
  249. package/test/premiumfeatures.test.js +17 -0
  250. package/test/presence.test.js +25 -0
  251. package/test/privatemessages.test.js +33 -0
  252. package/test/thumbnails.test.js +53 -0
  253. package/test/users.test.js +68 -0
  254. package/tutorials/Authentication.md +75 -0
  255. package/tutorials/Event Emitters.md +26 -0
  256. package/tutorials/Promises.md +86 -0
  257. package/tutorials/VPS Authentication.md +72 -0
  258. package/typings/index.d.ts +2525 -0
  259. package/typings/jsDocs.ts +1927 -0
@@ -0,0 +1,60 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getCurrentUser = require('../util/getCurrentUser').func
4
+ const getGeneralToken = require('../util/getGeneralToken.js').func
5
+
6
+ // Args
7
+ exports.required = ['group']
8
+ exports.optional = []
9
+
10
+ // Docs
11
+ /**
12
+ * 🔐 Leave a group.
13
+ * @category Group
14
+ * @alias leaveGroup
15
+ * @param {number} group - The id of the group.
16
+ * @returns {Promise<void>}
17
+ * @example const noblox = require("noblox.js")
18
+ * // Login using your cookie
19
+ * noblox.leaveGroup(1)
20
+ **/
21
+
22
+ // Define
23
+ function leaveGroup (group, jar, xcsrf, userId) {
24
+ return new Promise((resolve, reject) => {
25
+ const httpOpt = {
26
+ url: `https://groups.roblox.com/v1/groups/${group}/users/${userId}`,
27
+ options: {
28
+ method: '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
+ exports.func = function (args) {
54
+ const jar = args.jar
55
+ return getGeneralToken({ jar: jar })
56
+ .then(async function (xcsrf) {
57
+ const currentUser = await getCurrentUser({ jar: jar })
58
+ return leaveGroup(args.group, args.jar, xcsrf, currentUser.UserID)
59
+ })
60
+ }
@@ -0,0 +1,62 @@
1
+ // Includes
2
+ const shortPoll = require('../util/shortPoll.js').func
3
+ const getAuditLog = require('./getAuditLog.js').func
4
+
5
+ // Args
6
+ exports.required = ['group']
7
+ exports.optional = ['jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 An event for when an audit log event is added.
12
+ * @category Group
13
+ * @alias onAuditLog
14
+ * @param {number} group - The id of the group.
15
+ * @returns An EventEmitter that emits when an action is added to the audit log.
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * const auditEvent = noblox.onAuditLog(1)
19
+ * auditEvent.on("data", function(data) {
20
+ * console.log("New action!", data)
21
+ * })
22
+ * auditEvent.on("error", function(err) {
23
+ * console.error("Something went wrong: ", err)
24
+ * // Handle error as needed
25
+ * })
26
+ **/
27
+
28
+ // Define
29
+ exports.func = function (args) {
30
+ let empty = false
31
+ return shortPoll({
32
+ getLatest: function (latest) {
33
+ return getAuditLog({ group: args.group, jar: args.jar, sortOrder: 'Desc' })
34
+ .then(function (audit) {
35
+ const given = []
36
+ if (audit) {
37
+ for (const key in audit.data) {
38
+ if (Object.prototype.hasOwnProperty.call(audit.data, key)) {
39
+ const date = audit.data[key].created
40
+
41
+ if (date > latest) {
42
+ latest = date
43
+ given.push(audit.data[key])
44
+ }
45
+ empty = false
46
+ } else if (!empty) {
47
+ const date = new Date()
48
+ given.push({ audit: '', author: { name: '', id: '-1' }, date: date })
49
+ latest = date
50
+ empty = true
51
+ }
52
+ }
53
+ return {
54
+ latest: latest,
55
+ data: given
56
+ }
57
+ }
58
+ })
59
+ },
60
+ delay: 'onAuditLog'
61
+ })
62
+ }
@@ -0,0 +1,63 @@
1
+ // Includes
2
+ const settings = require('../../settings.json')
3
+ const shortPoll = require('../util/shortPoll.js').func
4
+ const getJoinRequests = require('./getJoinRequests.js').func
5
+ const promiseTimeout = require('../internal/timeout')
6
+
7
+ // Args
8
+ exports.required = ['group']
9
+ exports.optional = ['jar']
10
+
11
+ // Docs
12
+ /**
13
+ * 🔐 An event for when someone makes a request to join the group.
14
+ * @category Group
15
+ * @alias onJoinRequest
16
+ * @param {number} group - The id of the group.
17
+ * @returns An EventEmitter that emits when someone tries to join.
18
+ * @example const noblox = require("noblox.js")
19
+ * // Login using your cookie
20
+ * const e = noblox.onJoinRequest()
21
+ * e.on("data", function(data) {
22
+ * console.log("New request!", data)
23
+ * })
24
+ * e.on("error", function (err) {
25
+ * ...
26
+ * })
27
+ **/
28
+
29
+ async function getRequests (jar, group, cursor) {
30
+ const requests = []
31
+ const res = await promiseTimeout(getJoinRequests({ jar, group, cursor, limit: 100 }), settings.event.timeout, 'getRequests onJoinRequests internal')
32
+ requests.push.apply(requests, res.data)
33
+ if (res.nextPageCursor) {
34
+ requests.push.apply(requests, await getRequests(jar, group, res.nextPageCursor))
35
+ }
36
+ return requests
37
+ }
38
+
39
+ // Define
40
+ exports.func = function (args) {
41
+ return shortPoll({
42
+ getLatest: function (latest) {
43
+ return getRequests(args.jar, args.group)
44
+ .then(function (requests) {
45
+ const given = []
46
+ for (const key in requests) {
47
+ if (Object.prototype.hasOwnProperty.call(requests, key)) {
48
+ const date = new Date(requests[key].created.slice(0, requests[key].created.lastIndexOf('.')))
49
+ if (date > latest) {
50
+ latest = date
51
+ given.push(requests[key])
52
+ }
53
+ }
54
+ }
55
+ return {
56
+ latest: latest,
57
+ data: given
58
+ }
59
+ })
60
+ },
61
+ delay: 'onJoinRequest'
62
+ })
63
+ }
@@ -0,0 +1,105 @@
1
+ // Includes
2
+ const settings = require('../../settings.json')
3
+ const shortPoll = require('../util/shortPoll.js').func
4
+ const getJoinRequests = require('./getJoinRequests.js').func
5
+ const handleJoinRequest = require('./handleJoinRequest.js').func
6
+ const promiseTimeout = require('../internal/timeout')
7
+
8
+ // Args
9
+ exports.required = ['group']
10
+ exports.optional = ['jar']
11
+
12
+ // Docs
13
+ /**
14
+ * 🔐 An event for when someone is added to the join requests, which allows you to handle the join request as part of a
15
+ * screening process. Emits all join requests and waits until all of them have been resolved by firing the handle event
16
+ * with the request and either true or false. You can also pass a third argument callback to handle to execute once the
17
+ * join request has been handled.
18
+ * Once all requests on a page have been resolved, the next page is collected. Make sure that all join requests are handled in some way.
19
+ * Because this function has to wait for input, it does handle timeouts but does them within the function as opposed to within shortPoll.
20
+ *
21
+ * The use of this function is generally pretty complex. If it is not as working as you expect, you may actually be wanting
22
+ * to use `onJoinRequest`.
23
+ * @category Group
24
+ * @alias onJoinRequestHandle
25
+ * @param {number} group - The id of the group.
26
+ * @returns An EventEmitter that emits when someone tries to join.
27
+ * @example const noblox = require("noblox.js")
28
+ * // Login using your cookie
29
+ *
30
+ * var blacklist = [1, 261]
31
+ * var evt = noblox.onJoinRequestHandle(18)
32
+ * evt.on('data', function (request) {
33
+ * noblox.getIdFromUsername(request.username).then(function (id) {
34
+ * for (var i = 0; i < blacklist.length; i++) {
35
+ * if (blacklist[i] === id) {
36
+ * evt.emit('handle', request, false);
37
+ * return;
38
+ * }
39
+ * }
40
+ * evt.emit('handle', request, true, function () {
41
+ * console.log(`Welcome ${id} to the group`)
42
+ * });
43
+ *});
44
+ *});
45
+ **/
46
+
47
+ async function getRequests (jar, group, cursor) {
48
+ const requests = []
49
+ const res = await promiseTimeout(getJoinRequests({ jar, group, cursor, limit: 100 }), settings.event.timeout)
50
+ requests.push.apply(requests, res.data)
51
+ if (res.nextPageCursor) {
52
+ requests.push.apply(requests, await getRequests(jar, group, res.nextPageCursor))
53
+ }
54
+ return requests
55
+ }
56
+
57
+ // Define
58
+ exports.func = function (args) {
59
+ const group = args.group
60
+ const jar = args.jar
61
+ function getLatest (latest, evt) {
62
+ return getRequests(jar, group)
63
+ .then(function (requests) {
64
+ const complete = {
65
+ data: [],
66
+ latest: -2,
67
+ repeat: requests.length >= 20
68
+ }
69
+ let handled = 0
70
+ let promise
71
+ if (requests.length > 0) {
72
+ promise = new Promise(function (resolve, reject) {
73
+ evt.on('handle', function (request, accept, callback) {
74
+ const id = request.requester.userId
75
+ handleJoinRequest({ jar: jar, group, userId: id, accept: accept })
76
+ .then(function () {
77
+ handled++
78
+ if (callback) {
79
+ callback()
80
+ }
81
+ if (handled === requests.length) {
82
+ evt.removeAllListeners('handle')
83
+ resolve(complete)
84
+ }
85
+ })
86
+ .catch(reject)
87
+ })
88
+ })
89
+ }
90
+ for (let i = 0; i < requests.length; i++) {
91
+ const request = requests[i]
92
+ evt.emit('data', request)
93
+ }
94
+ if (requests.length > 0) {
95
+ return promise
96
+ }
97
+ return complete
98
+ })
99
+ }
100
+ return shortPoll({
101
+ getLatest: getLatest,
102
+ delay: 'onJoinRequestHandle',
103
+ timeout: -1
104
+ })
105
+ }
@@ -0,0 +1,57 @@
1
+ // Includes
2
+ const shortPoll = require('../util/shortPoll.js').func
3
+ const getShout = require('./getShout.js').func
4
+
5
+ // Args
6
+ exports.required = ['group']
7
+ exports.optional = ['jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 An event for when the shout is changed.
12
+ * @category Group
13
+ * @alias onShout
14
+ * @param {number} group - The id of the group.
15
+ * @returns An EventEmitter that emits when someone shouts.
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * const shoutEvent = noblox.onShout(1)
19
+ * shoutEvent.on("data", function(data) {
20
+ * console.log("New Shout!", data)
21
+ * })
22
+ * shoutEvent.on("error", function(err) {
23
+ * console.error("Something went wrong: ", err)
24
+ * // Handle error as needed
25
+ * })
26
+ **/
27
+
28
+ // Define
29
+ exports.func = function (args) {
30
+ let empty = false
31
+ return shortPoll({
32
+ getLatest: function (latest) {
33
+ return getShout({ group: args.group, jar: args.jar })
34
+ .then(function (shout) {
35
+ const given = []
36
+ if (shout) {
37
+ const date = new Date(shout.updated.slice(0, shout.updated.lastIndexOf('.')))
38
+ if (date > latest) {
39
+ latest = date
40
+ given.push(shout)
41
+ }
42
+ empty = false
43
+ } else if (!empty) {
44
+ const date = new Date()
45
+ given.push({ message: '', author: { name: '', id: '-1' }, date: date })
46
+ latest = date
47
+ empty = true
48
+ }
49
+ return {
50
+ latest: latest,
51
+ data: given
52
+ }
53
+ })
54
+ },
55
+ delay: 'onShout'
56
+ })
57
+ }
@@ -0,0 +1,58 @@
1
+ // Includes
2
+ const shortPoll = require('../util/shortPoll.js').func
3
+ const getWall = require('./getWall.js').func
4
+
5
+ // Args
6
+ exports.required = ['group']
7
+ exports.optional = ['view', 'jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 An event for when someone posts on the group wall.
12
+ * @category Group
13
+ * @alias onWallPost
14
+ * @param {number} group - The id of the group.
15
+ * @returns An EventEmitter that emits when someone posts on the group wall.
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * const wallpostEvent = noblox.onWallPost(1)
19
+ * wallpostEvent.on("data", function(data) {
20
+ * console.log("New post!", data)
21
+ * })
22
+ * wallpostEvent.on("error", function(err) {
23
+ * console.error("Something went wrong: ", err)
24
+ * // Handle error as needed
25
+ * })
26
+ **/
27
+
28
+ // Define
29
+ exports.func = function (args) {
30
+ const group = args.group
31
+ const jar = args.jar
32
+ const view = args.view
33
+ return shortPoll({
34
+ getLatest: function (latest) {
35
+ return getWall({ group: group, jar: jar, sortOrder: 'Desc' })
36
+ .then(function (wall) {
37
+ const posts = wall.data
38
+ const given = []
39
+ for (let i = posts.length - 1; i >= 0; i--) {
40
+ const post = posts[i]
41
+ const id = post.id
42
+ if (id > latest) {
43
+ latest = id
44
+ if (view) {
45
+ post.view = wall.views[post.parent.page]
46
+ }
47
+ given.push(post)
48
+ }
49
+ }
50
+ return {
51
+ latest: latest,
52
+ data: given
53
+ }
54
+ })
55
+ },
56
+ delay: 'onWallPost'
57
+ })
58
+ }
@@ -0,0 +1,25 @@
1
+ // Includes
2
+ const changeRank = require('./changeRank.js').func
3
+
4
+ // Args
5
+ exports.required = ['group', 'target']
6
+ exports.optional = ['jar']
7
+
8
+ // Docs
9
+ /**
10
+ * 🔐 Promote a user.
11
+ * @category Group
12
+ * @alias promote
13
+ * @param {number} group - The id of the group.
14
+ * @param {number} target - The id of the user.
15
+ * @returns {Promise<ChangeRankResult>}
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * noblox.promote(1, 2)
19
+ **/
20
+
21
+ // Define
22
+ exports.func = function (args) {
23
+ args.change = 1
24
+ return changeRank(args)
25
+ }
@@ -0,0 +1,32 @@
1
+ // Includes
2
+ const getPageResults = require('../util/getPageResults.js').func
3
+
4
+ // Args
5
+ exports.required = ['keyword']
6
+ exports.optional = ['prioritizeExactMatch', 'limit']
7
+
8
+ // Docs
9
+ /**
10
+ * ✅ Searches for groups by a given search term.
11
+ * @category Group
12
+ * @alias searchGroups
13
+ * @param {string} keyword - The keyword or search term to search by.
14
+ * @param {boolean} [prioritizeExactMatch=false] - Whether or not to prioritize the exact match for the keyword
15
+ * @param {number} [limit=100] - The maximum number of groups to return. Supply 0 to apply no limit, returning all results.
16
+ * Note: This may significantly increase the time to execute and return potentially thousands of results.
17
+ * @returns {Promise<GroupSearchItem[]>}
18
+ * @example const noblox = require("noblox.js")
19
+ * const groupInfo = await noblox.searchGroups("noblox.js");
20
+ **/
21
+
22
+ // Define
23
+ exports.func = async function (args) {
24
+ const results = await getPageResults({
25
+ url: '//groups.roblox.com/v1/groups/search',
26
+ query: { keyword: args.keyword, prioritizeExactMatch: args.prioritizeExactMatch || false },
27
+ // If limit is 0, pass undefined for infinite results. Otherwise, default to 100.
28
+ limit: args.limit === 0 ? undefined : (args.limit || 100)
29
+ })
30
+ // Parse updated/created to Date objects.
31
+ return results.map((g) => ({ created: new Date(g.created), updated: new Date(g.updated), ...g }))
32
+ }
@@ -0,0 +1,65 @@
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']
7
+ exports.optional = ['description', 'jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 Update a group description
12
+ * @category Group
13
+ * @alias setGroupDescription
14
+ * @param {number} group - The id of the group.
15
+ * @param {string=} [description=""] - The new description for the group
16
+ * @returns {Promise<GroupDescriptionResult>}
17
+ * @example const noblox = require("noblox.js")
18
+ * // Login using your cookie
19
+ * noblox.setGroupDescription(1, "Group Description!")
20
+ **/
21
+
22
+ function changeGroupDesc (group, description = '', jar, xcsrf) {
23
+ return new Promise((resolve, reject) => {
24
+ const httpOpt = {
25
+ url: `https://groups.roblox.com/v1/groups/${group}/description`,
26
+ options: {
27
+ method: 'PATCH',
28
+ resolveWithFullResponse: true,
29
+ json: {
30
+ description
31
+ },
32
+ jar: jar,
33
+ headers: {
34
+ 'X-CSRF-TOKEN': xcsrf
35
+ }
36
+ }
37
+ }
38
+
39
+ return http(httpOpt)
40
+ .then(function (res) {
41
+ if (res.statusCode === 200) {
42
+ resolve(res.body)
43
+ } else {
44
+ const body = res.body || {}
45
+ if (body.errors && body.errors.length > 0) {
46
+ const errors = body.errors.map((e) => {
47
+ return e.message
48
+ })
49
+ reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
50
+ } else {
51
+ reject(new Error(`${res.statusCode} ${res.body}`))
52
+ }
53
+ }
54
+ })
55
+ })
56
+ }
57
+
58
+ // Define
59
+ exports.func = function (args) {
60
+ const jar = args.jar
61
+ return getGeneralToken({ jar: jar })
62
+ .then(function (xcsrf) {
63
+ return changeGroupDesc(args.group, args.description, args.jar, xcsrf)
64
+ })
65
+ }
@@ -0,0 +1,66 @@
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', 'name']
7
+ exports.optional = ['jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 Update a group name. This method will trigger a Robux charge to your account, and can only be performed by the group
12
+ * owner.
13
+ * @category Group
14
+ * @alias setGroupName
15
+ * @param {number} group - The id of the group.
16
+ * @param {string=} name - The new name for the group
17
+ * @returns {Promise<GroupNameResult>}
18
+ * @example const noblox = require("noblox.js")
19
+ * // Login using your cookie
20
+ * noblox.setGroupName(1, "Cool group")
21
+ **/
22
+
23
+ function changeGroupName (group, name, jar, xcsrf) {
24
+ return new Promise((resolve, reject) => {
25
+ const httpOpt = {
26
+ url: `https://groups.roblox.com/v1/groups/${group}/name`,
27
+ options: {
28
+ method: 'PATCH',
29
+ resolveWithFullResponse: true,
30
+ json: {
31
+ name
32
+ },
33
+ jar: jar,
34
+ headers: {
35
+ 'X-CSRF-TOKEN': xcsrf
36
+ }
37
+ }
38
+ }
39
+
40
+ return http(httpOpt)
41
+ .then(function (res) {
42
+ if (res.statusCode === 200) {
43
+ resolve(res.body)
44
+ } else {
45
+ const body = res.body || {}
46
+ if (body.errors && body.errors.length > 0) {
47
+ const errors = body.errors.map((e) => {
48
+ return e.message
49
+ })
50
+ reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
51
+ } else {
52
+ reject(new Error(`${res.statusCode} ${res.body}`))
53
+ }
54
+ }
55
+ })
56
+ })
57
+ }
58
+
59
+ // Define
60
+ exports.func = function (args) {
61
+ const jar = args.jar
62
+ return getGeneralToken({ jar: jar })
63
+ .then(function (xcsrf) {
64
+ return changeGroupName(args.group, args.name, args.jar, xcsrf)
65
+ })
66
+ }
@@ -0,0 +1,79 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getGeneralToken = require('../util/getGeneralToken.js').func
4
+ const getRole = require('./getRole.js').func
5
+
6
+ // Args
7
+ exports.required = ['group', 'target', 'rank']
8
+ exports.optional = ['jar']
9
+
10
+ // Docs
11
+ /**
12
+ * 🔐 Change a user's rank.
13
+ * @category Group
14
+ * @alias setRank
15
+ * @param {number} group - The id of the group.
16
+ * @param {number} target - The id of the user whose rank is being changed.
17
+ * @param {number | string | Role} rank - The rank, roleset ID, name of the role, or the actual Role itself.
18
+ * @returns {Promise<Role>}
19
+ * @example const noblox = require("noblox.js")
20
+ * // Login using your cookie
21
+ * noblox.setRank(1, 1, "Customer")
22
+ **/
23
+
24
+ // Define
25
+ function setRank (jar, xcsrf, group, target, role) {
26
+ return new Promise((resolve, reject) => {
27
+ const httpOpt = {
28
+ url: `//groups.roblox.com/v1/groups/${group}/users/${target}`,
29
+ options: {
30
+ resolveWithFullResponse: true,
31
+ method: 'PATCH',
32
+ jar: jar,
33
+ headers: {
34
+ 'Content-Type': 'application/json',
35
+ 'X-CSRF-TOKEN': xcsrf
36
+ },
37
+ body: JSON.stringify({
38
+ roleId: role.id
39
+ })
40
+ }
41
+ }
42
+ return http(httpOpt)
43
+ .then(function (res) {
44
+ if (res.statusCode === 200) {
45
+ resolve(role)
46
+ } else {
47
+ const body = JSON.parse(res.body) || {}
48
+ if (body.errors && body.errors.length > 0) {
49
+ const errors = body.errors.map((e) => {
50
+ return e.message
51
+ })
52
+ reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
53
+ }
54
+ }
55
+ }).catch(error => reject(error))
56
+ })
57
+ }
58
+
59
+ function runWithToken (args) {
60
+ const jar = args.jar
61
+ return getGeneralToken({ jar: jar })
62
+ .then(function (xcsrf) {
63
+ return setRank(jar, xcsrf, args.group, args.target, args.role)
64
+ })
65
+ }
66
+
67
+ exports.func = function (args) {
68
+ if (typeof args.rank === 'object') { // assumes they gave Role
69
+ args.role = args.rank
70
+ return runWithToken(args)
71
+ } else if (typeof args.rank === 'number' || typeof args.rank === 'string') {
72
+ return getRole({ group: args.group, roleQuery: args.rank }).then((role) => {
73
+ args.role = role
74
+ return runWithToken(args)
75
+ })
76
+ } else {
77
+ throw new Error('Please provide either a Role, rank, or role name to change the user\'s rank to')
78
+ }
79
+ }