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
50 changes: 50 additions & 0 deletions lib/groups/canPay.js
Original file line number Diff line number Diff line change
@@ -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<PayoutAllowedList>}
* @example const noblox = require("noblox.js")
* const groupShout = await noblox.getShout(1)
**/

// Define
function getShout (group, member, jar) {
Regalijan marked this conversation as resolved.
Show resolved Hide resolved
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)
}
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ declare module "noblox.js" {
updated: Date;
}

interface PayoutAllowedList {
usersGroupPayoutEligibility: [string, string]
}

interface GroupDescriptionResult {
newDescription: string
}
Expand Down
7 changes: 7 additions & 0 deletions typings/jsDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,13 @@ type GroupShout = {
updated: Date;
}

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

/**
* @typedef
*/
Expand Down
Loading