Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Can Pay function #834

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
48 changes: 48 additions & 0 deletions lib/economy/getGroupPayoutEligibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Includes
const http = require('../util/http.js').func

// Args
exports.required = ['group', 'member']
exports.optional = ['jar']

// Docs
/**
* 🔓 Get if a user can be paid from group funds.
* @category Group
* @alias getGroupPayoutEligibility
* @param {number} group - The id of the group.
* @param {number} member - The member to check payout status for.
* @returns {Promise<PayoutAllowedList>}
* @example const noblox = require("noblox.js")
* // Log in with cookie
* const payoutStatus = await noblox.getGroupPayoutEligibility(1, 2)
**/

// Define
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}`,
options: {
method: 'GET',
resolveWithFullResponse: true,
jar
}
}

return http(httpOpt)
.then(function (res) {
const responseData = JSON.parse(res.body)
if (res.statusCode !== 200) {
reject(new Error(responseData.errors[0].message))
} else {
resolve(responseData)
}
})
.catch(error => reject(error))
})
}

exports.func = function (args) {
return getGroupPayoutEligibility(args.group, args.member, args.jar)
}
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('./economy/getGroupPayoutEligibility.js')
noblox.getGroupSocialLinks = require('./groups/getGroupSocialLinks.js')
noblox.getGroups = require('./groups/getGroups.js')
noblox.getJoinRequest = require('./groups/getJoinRequest.js')
Expand Down
11 changes: 11 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,12 @@ declare module "noblox.js" {
updated: Date;
}

interface PayoutAllowedList {
usersGroupPayoutEligibility: {
[K: string]: string;
}
}

interface GroupDescriptionResult {
newDescription: string
}
Expand Down Expand Up @@ -1746,6 +1752,11 @@ declare module "noblox.js" {
* 🔓 Gets the amount of Robux in a group.
*/
function getGroupFunds(group: number): Promise<number>;

/**
* 🔐 Gets the payout eligibility status of a group member.
*/
function getGroupPayoutEligibility(groupId: number, userId: number, jar?: CookieJar): Promise<PayoutAllowedList>;

/**
* 🔐 Gets recent Robux revenue summary for a group; shows pending Robux. | Requires "Spend group funds" permissions.
Expand Down
9 changes: 9 additions & 0 deletions typings/jsDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,15 @@ type GroupShout = {
updated: Date;
}

/**
* @typedef
*/
type PayoutAllowedList = {
usersGroupPayoutEligibility: {
[k: string]: string;
}
}

/**
* @typedef
*/
Expand Down
Loading