From c87848dd2d5c17606cbaeeb7670766f3472f8a74 Mon Sep 17 00:00:00 2001 From: Spy Date: Sat, 28 Sep 2024 22:26:36 -0700 Subject: [PATCH 01/12] Add canpay function --- lib/groups/canPay.js | 50 ++++++++++++++++++++++++++++++++++++++++++++ lib/index.js | 1 + typings/index.d.ts | 4 ++++ 3 files changed, 55 insertions(+) create mode 100644 lib/groups/canPay.js diff --git a/lib/groups/canPay.js b/lib/groups/canPay.js new file mode 100644 index 000000000..723b0542e --- /dev/null +++ b/lib/groups/canPay.js @@ -0,0 +1,50 @@ +// Includes +const http = require('../util/http.js').func + +// Args +exports.required = ['group', 'member'] +exports.optional = [] + +// Docs +/** + * 🔓 Get if a user can be paid from group funds. + * @category Group + * @alias canPay + * @param {number} group - The id of the group. + * @param {number} member - The member to check payout status for. + * @returns {Promise} + * @example const noblox = require("noblox.js") + * const groupShout = await noblox.getShout(1) + **/ + +// Define +function getShout (group, member, jar) { + return new Promise((resolve, reject) => { + const httpOpt = { + url: `https://economy.roblox.com/v1/groups/${group}/users-payout-eligibility?userIds=${member}`, + options: { + method: 'GET', + resolveWithFullResponse: true, + jar + } + } + + return http(httpOpt) + .then(function (res) { + const responseData = JSON.parse(res.body) + if (res.statusCode === 400) { + reject(new Error('The group is invalid or does not exist.')) + } + if (responseData.shout === null) { + reject(new Error('You do not have permissions to view the shout for the group.')) + } else { + resolve(responseData.shout) + } + }) + .catch(error => reject(error)) + }) +} + +exports.func = function (args) { + return getShout(args.group, args.jar) +} diff --git a/lib/index.js b/lib/index.js index bd6063b3a..a35898bbf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -116,6 +116,7 @@ noblox.getRoles = require('./groups/getRoles.js') noblox.getShout = require('./groups/getShout.js') noblox.getWall = require('./groups/getWall.js') noblox.groupPayout = require('./groups/groupPayout.js') +noblox.canPay = require('./groups/canPay.js') noblox.handleJoinRequest = require('./groups/handleJoinRequest.js') noblox.leaveGroup = require('./groups/leaveGroup.js') noblox.onAuditLog = require('./groups/onAuditLog.js') diff --git a/typings/index.d.ts b/typings/index.d.ts index 5f12970f8..68c732d79 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -866,6 +866,10 @@ declare module "noblox.js" { updated: Date; } + interface PayoutAllowedList { + usersGroupPayoutEligibility: [string, string] + } + interface GroupDescriptionResult { newDescription: string } From 2fbf8a87adf957c1f08aa0ebdb5c3b3b7bd7c1ca Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 03:02:04 -0400 Subject: [PATCH 02/12] Add PayoutAllowedList type to jsdocs --- typings/jsDocs.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/typings/jsDocs.ts b/typings/jsDocs.ts index 6a85a8a3a..9af0cab10 100644 --- a/typings/jsDocs.ts +++ b/typings/jsDocs.ts @@ -1201,6 +1201,13 @@ type GroupShout = { updated: Date; } +/** + * @typedef +*/ +type PayoutAllowedList = { + usersGroupPayoutEligibility: [string, string] +} + /** * @typedef */ From b69b985af19fdd7e400fc9bfd6598b22d290a656 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 03:07:15 -0400 Subject: [PATCH 03/12] Fix formatting --- lib/groups/canPay.js | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/groups/canPay.js b/lib/groups/canPay.js index 723b0542e..2a9bf6c2a 100644 --- a/lib/groups/canPay.js +++ b/lib/groups/canPay.js @@ -19,32 +19,32 @@ exports.optional = [] // Define function getShout (group, member, jar) { - return new Promise((resolve, reject) => { - const httpOpt = { - url: `https://economy.roblox.com/v1/groups/${group}/users-payout-eligibility?userIds=${member}`, - options: { - method: 'GET', - resolveWithFullResponse: true, - jar - } - } + return new Promise((resolve, reject) => { + const httpOpt = { + url: `https://economy.roblox.com/v1/groups/${group}/users-payout-eligibility?userIds=${member}`, + options: { + method: 'GET', + resolveWithFullResponse: true, + jar + } + } - return http(httpOpt) - .then(function (res) { - const responseData = JSON.parse(res.body) - if (res.statusCode === 400) { - reject(new Error('The group is invalid or does not exist.')) - } - if (responseData.shout === null) { - reject(new Error('You do not have permissions to view the shout for the group.')) - } else { - resolve(responseData.shout) - } - }) - .catch(error => reject(error)) - }) + return http(httpOpt) + .then(function (res) { + const responseData = JSON.parse(res.body) + if (res.statusCode === 400) { + reject(new Error('The group is invalid or does not exist.')) + } + if (responseData.shout === null) { + reject(new Error('You do not have permissions to view the shout for the group.')) + } else { + resolve(responseData.shout) + } + }) + .catch(error => reject(error)) + }) } exports.func = function (args) { - return getShout(args.group, args.jar) + return getShout(args.group, args.jar) } From b18a6cea2f95f36b2f5b78c8f6f76ceb3b69deab Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:20:58 -0400 Subject: [PATCH 04/12] canPay -> getGroupPayoutEligibility --- ...canPay.js => getGroupPayoutEligibility.js} | 19 ++++++++----------- lib/index.js | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) rename lib/groups/{canPay.js => getGroupPayoutEligibility.js} (66%) diff --git a/lib/groups/canPay.js b/lib/groups/getGroupPayoutEligibility.js similarity index 66% rename from lib/groups/canPay.js rename to lib/groups/getGroupPayoutEligibility.js index 2a9bf6c2a..cb7c971c0 100644 --- a/lib/groups/canPay.js +++ b/lib/groups/getGroupPayoutEligibility.js @@ -3,22 +3,22 @@ const http = require('../util/http.js').func // Args exports.required = ['group', 'member'] -exports.optional = [] +exports.optional = ['jar'] // Docs /** * 🔓 Get if a user can be paid from group funds. * @category Group - * @alias canPay + * @alias getGroupPayoutEligibility * @param {number} group - The id of the group. * @param {number} member - The member to check payout status for. * @returns {Promise} * @example const noblox = require("noblox.js") - * const groupShout = await noblox.getShout(1) + * const payoutStatus = await noblox.getGroupPayoutEligibility(1) **/ // Define -function getShout (group, member, jar) { +function getGroupPayoutEligibility (group, member, jar) { return new Promise((resolve, reject) => { const httpOpt = { url: `https://economy.roblox.com/v1/groups/${group}/users-payout-eligibility?userIds=${member}`, @@ -32,13 +32,10 @@ function getShout (group, member, jar) { return http(httpOpt) .then(function (res) { const responseData = JSON.parse(res.body) - if (res.statusCode === 400) { - reject(new Error('The group is invalid or does not exist.')) - } - if (responseData.shout === null) { - reject(new Error('You do not have permissions to view the shout for the group.')) + if (res.statusCode !== 200) { + reject(new Error(responseData.errors)) } else { - resolve(responseData.shout) + resolve(responseData) } }) .catch(error => reject(error)) @@ -46,5 +43,5 @@ function getShout (group, member, jar) { } exports.func = function (args) { - return getShout(args.group, args.jar) + return getGroupPayoutEligibility(args.group, args.member, args.jar) } diff --git a/lib/index.js b/lib/index.js index a35898bbf..53e3f1d44 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,6 +103,7 @@ noblox.demote = require('./groups/demote.js') noblox.exile = require('./groups/exile.js') noblox.getAuditLog = require('./groups/getAuditLog.js') noblox.getGroup = require('./groups/getGroup.js') +noblox.getGroupPayoutEligibility = require('./groups/getGroupPayoutEligibility.js') noblox.getGroupSocialLinks = require('./groups/getGroupSocialLinks.js') noblox.getGroups = require('./groups/getGroups.js') noblox.getJoinRequest = require('./groups/getJoinRequest.js') @@ -116,7 +117,6 @@ noblox.getRoles = require('./groups/getRoles.js') noblox.getShout = require('./groups/getShout.js') noblox.getWall = require('./groups/getWall.js') noblox.groupPayout = require('./groups/groupPayout.js') -noblox.canPay = require('./groups/canPay.js') noblox.handleJoinRequest = require('./groups/handleJoinRequest.js') noblox.leaveGroup = require('./groups/leaveGroup.js') noblox.onAuditLog = require('./groups/onAuditLog.js') From 3921cdc31854f50eb96617cc58f470a6f201ee85 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:26:27 -0400 Subject: [PATCH 05/12] Only log first error message from endpoint (as if Roblox ever returned more than one) --- lib/groups/getGroupPayoutEligibility.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/groups/getGroupPayoutEligibility.js b/lib/groups/getGroupPayoutEligibility.js index cb7c971c0..d7b4e97af 100644 --- a/lib/groups/getGroupPayoutEligibility.js +++ b/lib/groups/getGroupPayoutEligibility.js @@ -33,7 +33,7 @@ function getGroupPayoutEligibility (group, member, jar) { .then(function (res) { const responseData = JSON.parse(res.body) if (res.statusCode !== 200) { - reject(new Error(responseData.errors)) + reject(new Error(responseData.errors[0].message)) } else { resolve(responseData) } From af6be5efd294385aefd16fb6810353fed1b4ba47 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:38:21 -0400 Subject: [PATCH 06/12] Fix type for PayoutAllowedList --- typings/index.d.ts | 4 +++- typings/jsDocs.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 68c732d79..24cfe5992 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -867,7 +867,9 @@ declare module "noblox.js" { } interface PayoutAllowedList { - usersGroupPayoutEligibility: [string, string] + usersGroupPayoutEligibility: { + [K: string]: string; + } } interface GroupDescriptionResult { diff --git a/typings/jsDocs.ts b/typings/jsDocs.ts index 9af0cab10..0abbc1f4c 100644 --- a/typings/jsDocs.ts +++ b/typings/jsDocs.ts @@ -1205,7 +1205,9 @@ type GroupShout = { * @typedef */ type PayoutAllowedList = { - usersGroupPayoutEligibility: [string, string] + usersGroupPayoutEligibility: { + [k: string]: string; + } } /** From 5c13505acae628f9c5482881f446562e9987ac75 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:44:10 -0400 Subject: [PATCH 07/12] Add function type for getGroupPayoutEligibility --- typings/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 24cfe5992..35bacb6a1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1937,6 +1937,11 @@ declare module "noblox.js" { */ function getGroups(userId: number): Promise + /** + * 🔐 Gets the payout eligibility status of a group member. + */ + function getGroupPayoutEligibility(groupId: number, userId: number): Promise + /** * 🔐 Get the social link data associated with a group. */ From 5a99259c0ce973897b76833fb4c442280ad11596 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Tue, 29 Oct 2024 02:32:36 -0400 Subject: [PATCH 08/12] Document jar param in getGroupPayoutEligibility --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 35bacb6a1..6de8c53d2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1940,7 +1940,7 @@ declare module "noblox.js" { /** * 🔐 Gets the payout eligibility status of a group member. */ - function getGroupPayoutEligibility(groupId: number, userId: number): Promise + function getGroupPayoutEligibility(groupId: number, userId: number, jar?: CookieJar): Promise; /** * 🔐 Get the social link data associated with a group. From 45d471d6749350160414b2fd1010562d71e0cbc5 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:54:41 -0400 Subject: [PATCH 09/12] Update example --- lib/groups/getGroupPayoutEligibility.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/groups/getGroupPayoutEligibility.js b/lib/groups/getGroupPayoutEligibility.js index d7b4e97af..2f5488d85 100644 --- a/lib/groups/getGroupPayoutEligibility.js +++ b/lib/groups/getGroupPayoutEligibility.js @@ -14,7 +14,8 @@ exports.optional = ['jar'] * @param {number} member - The member to check payout status for. * @returns {Promise} * @example const noblox = require("noblox.js") - * const payoutStatus = await noblox.getGroupPayoutEligibility(1) + * // Log in with cookie + * const payoutStatus = await noblox.getGroupPayoutEligibility(1, 2) **/ // Define From 33c5ab0e7d5aaa9ce193bf386f3e914883923287 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:55:25 -0400 Subject: [PATCH 10/12] Move getGroupPayoutEligibility to economy --- lib/{groups => economy}/getGroupPayoutEligibility.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{groups => economy}/getGroupPayoutEligibility.js (100%) diff --git a/lib/groups/getGroupPayoutEligibility.js b/lib/economy/getGroupPayoutEligibility.js similarity index 100% rename from lib/groups/getGroupPayoutEligibility.js rename to lib/economy/getGroupPayoutEligibility.js From 2d3a968c5babef276d3ea9a9613938f196e3f286 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:55:57 -0400 Subject: [PATCH 11/12] Update import for getGroupPayoutEligibility --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 53e3f1d44..97cea96b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,7 +103,7 @@ noblox.demote = require('./groups/demote.js') noblox.exile = require('./groups/exile.js') noblox.getAuditLog = require('./groups/getAuditLog.js') noblox.getGroup = require('./groups/getGroup.js') -noblox.getGroupPayoutEligibility = require('./groups/getGroupPayoutEligibility.js') +noblox.getGroupPayoutEligibility = require('./economy/getGroupPayoutEligibility.js') noblox.getGroupSocialLinks = require('./groups/getGroupSocialLinks.js') noblox.getGroups = require('./groups/getGroups.js') noblox.getJoinRequest = require('./groups/getJoinRequest.js') From 9c5db3b2c72d87e6ce04459fe3362350b9edf925 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:59:25 -0400 Subject: [PATCH 12/12] Move function type to economy section --- typings/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 6de8c53d2..7eba768f4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1752,6 +1752,11 @@ declare module "noblox.js" { * 🔓 Gets the amount of Robux in a group. */ function getGroupFunds(group: number): Promise; + + /** + * 🔐 Gets the payout eligibility status of a group member. + */ + function getGroupPayoutEligibility(groupId: number, userId: number, jar?: CookieJar): Promise; /** * 🔐 Gets recent Robux revenue summary for a group; shows pending Robux. | Requires "Spend group funds" permissions. @@ -1937,11 +1942,6 @@ declare module "noblox.js" { */ function getGroups(userId: number): Promise - /** - * 🔐 Gets the payout eligibility status of a group member. - */ - function getGroupPayoutEligibility(groupId: number, userId: number, jar?: CookieJar): Promise; - /** * 🔐 Get the social link data associated with a group. */