Skip to content

Commit

Permalink
Add canpay function
Browse files Browse the repository at this point in the history
  • Loading branch information
supercoolspy committed Sep 29, 2024
1 parent 3ea4d7a commit c87848d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
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) {
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

0 comments on commit c87848d

Please sign in to comment.