From c87848dd2d5c17606cbaeeb7670766f3472f8a74 Mon Sep 17 00:00:00 2001 From: Spy Date: Sat, 28 Sep 2024 22:26:36 -0700 Subject: [PATCH] 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 }