Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions lib/groups/getGroups.js

This file was deleted.

37 changes: 37 additions & 0 deletions lib/groups/getPrimaryGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Includes
const http = require('../util/http.js').func
const RobloxAPIError = require('../util/apiError.js')

// Args
exports.required = ['userId']
exports.optional = []

// Docs
/**
* ✅Gets the specified user's primary group.
* @category User
* @alias getPrimaryGroup
* @param {number} userId - The ID of the user.
* @returns {Promise<Group>}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it? Or does it return a GroupMemberInfo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary group endpoint returns whole group object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://groups.roblox.com/v1/users/66592931/groups/primary/role

{"group":{"id":3812352,"name":"Polaris Incorporated","description":"Polaris incorporated. The Polaris bot will shut down on the First of March 2022. Thank you all for coming along for the ride. We're proud of what we achieved: From a Project that didn't set out to achieve much at all, except be a hobby of mine.","owner":{"hasVerifiedBadge":false,"userId":66592931,"username":"Neztore","displayName":"Neztore"},"shout":null,"isBuildersClubOnly":false,"publicEntryAllowed":false,"hasVerifiedBadge":false,"hasSocialModules":true},"role":{"id":26008925,"name":"Dev","rank":255,"color":0}}

Isn't that a GroupMemberInfo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up making a new type using the existing Group and Role types, since the primary group returns the full group object (which is not present in the GroupMemberInfo type)

* @example const noblox = require("noblox.js")
* const primaryGroup = await noblox.getPrimaryGroup(1)
**/

// Define
exports.func = async function (args) {
const { userId } = args

const response = await http({
url: `https://groups.roblox.com/v1/users/${userId}/groups/primary/role`,
options: {
json: true,
resolveWithFullResponse: true
}
})

if (response.statusCode !== 200) {
throw new RobloxAPIError(response)
}

return response.body
}
37 changes: 37 additions & 0 deletions lib/groups/getUserGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Includes
const http = require('../util/http.js').func
const RobloxAPIError = require('../util/apiError.js')

// Args
exports.required = ['userId']
exports.optional = []

// Docs
/**
* ✅ Get the groups of a user.
* @category User
* @alias getUserGroups
* @param {number} userId - The id of the user.
* @returns {Promise<GroupMemberInfo[]>}
* @example const noblox = require("noblox.js")
* let groups = await noblox.getGroups(123456)
Comment thread
Regalijan marked this conversation as resolved.
Outdated
**/

// Define
exports.func = async function (args) {
const { userId } = args

const response = await http({
url: `https://groups.roblox.com/v2/users/${userId}/groups/roles?includeLocked=true`,
options: {
json: true,
resolveWithFullResponse: true
}
})

if (response.statusCode !== 200) {
throw new RobloxAPIError(response)
}

return response.body.data
}
44 changes: 44 additions & 0 deletions lib/groups/multigetPartialGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Includes
const http = require('../util/http.js').func
const RobloxAPIError = require('../util/apiError')

// Args
exports.required = ['groupIds']
exports.optional = []

// Docs
/**
* ✅ Gets partial info of multiple groups.
* @category Group
* @alias multigetPartialGroups
* @param {number[]} groupIds - Array of group IDs.
* @returns {Promise<GroupMultigetPartial[]>}
* @example const noblox = require("noblox.js")
* const groupsInfo = await noblox.multigetPartialGroups([1,2,3])
**/

exports.func = async function (args) {
const { groupIds } = args

if (!Array.isArray(groupIds)) throw TypeError('Group IDs must be an array')

const response = await http({
url: `https://groups.roblox.com/v2/groups?groupIds=${groupIds.join(',')}`,
options: {
json: true,
resolveWithFullResponse: true
}
})

if (response.statusCode !== 200) {
throw new RobloxAPIError(response)
}

const { data } = response.body

for (let i = 0, len = data.length; i < len; i++) {
data[i].created = new Date(data[i].created)
}

return data
}
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,22 @@ 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')
noblox.getJoinRequests = require('./groups/getJoinRequests.js')
noblox.getPlayers = require('./groups/getPlayers.js')
noblox.getPrimaryGroup = require('./groups/getPrimaryGroup.js')
noblox.getRankInGroup = require('./groups/getRankInGroup.js')
noblox.getRankNameInGroup = require('./groups/getRankNameInGroup.js')
noblox.getRole = require('./groups/getRole.js')
noblox.getRolePermissions = require('./groups/getRolePermissions.js')
noblox.getRoles = require('./groups/getRoles.js')
noblox.getShout = require('./groups/getShout.js')
noblox.getUserGroups = require('./groups/getUserGroups.js')
noblox.getWall = require('./groups/getWall.js')
noblox.groupPayout = require('./groups/groupPayout.js')
noblox.handleJoinRequest = require('./groups/handleJoinRequest.js')
noblox.leaveGroup = require('./groups/leaveGroup.js')
noblox.multigetPartialGroups = require('./groups/multigetPartialGroups.js')
noblox.onAuditLog = require('./groups/onAuditLog.js')
noblox.onJoinRequest = require('./groups/onJoinRequest.js')
noblox.onJoinRequestHandle = require('./groups/onJoinRequestHandle.js')
Expand Down
117 changes: 61 additions & 56 deletions lib/thumbnails/getLogo.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
// Includes
const http = require('../util/http.js').func
const RobloxAPIError = require('../util/apiError.js')

// Args
exports.required = ['group']
exports.optional = ['size', 'circular', 'format']

// Docs
/**
* ✅ Get the group's logo.
* @category Group
* @alias getLogo
* @param {number} group - The id of the group.
* @param {GroupIconSize=} [size=150x150] - The size of the logo.
* @param {boolean=} [circular=false] - Get the circular version of the logo.
* @param {GroupIconFormat=} [format=Png] - The file format of the logo.
* @returns {Promise<string>}
* @example const noblox = require("noblox.js")
* const logo = await noblox.getLogo(1)
**/

// Define
function getLogo (group, size, circular, format) {
const httpOpt = {
url: '//thumbnails.roblox.com/v1/groups/icons',
options: {
qs: {
groupIds: group,
size: size || '150x150',
format: format || 'Png',
isCircular: circular
},
json: true,
resolveWithFullResponse: true
}
}
return http(httpOpt)
.then(function (res) {
if (res.statusCode !== 200) {
throw new RobloxAPIError(res)
}

const thumbnailData = res.body.data[0]

if (thumbnailData.state !== 'Completed') {
throw new Error('The requested image has not been approved. Status: ' + thumbnailData.state)
}

return thumbnailData.imageUrl
})
}

exports.func = function (args) {
return getLogo(args.group)
}
// Includes
const http = require('../util/http.js').func
const RobloxAPIError = require('../util/apiError.js')

// Args
exports.required = ['group']
exports.optional = ['size', 'circular', 'format']

// Docs
/**
* ✅ Get the group's logo.
* @category Group
* @alias getLogo
* @param {number || number[]} group - The id(s) of the group.
* @param {GroupIconSize=} [size=150x150] - The size of the logo.
* @param {boolean=} [circular=false] - Get the circular version of the logo.
* @param {GroupIconFormat=} [format=Png] - The file format of the logo.
* @returns {Promise<string> || Promise<string[]>}
* @example const noblox = require("noblox.js")
* const logo = await noblox.getLogo(1)
**/

// Define
function getLogo (group, size, circular, format) {
const groupIds = Array.isArray(group) ? group.join(',') : group
const httpOpt = {
url: '//thumbnails.roblox.com/v1/groups/icons',
options: {
qs: {
groupIds,
size: size || '150x150',
format: format || 'Png',
isCircular: circular
},
json: true,
resolveWithFullResponse: true
}
}
return http(httpOpt)
.then(function (res) {
if (res.statusCode !== 200) {
throw new RobloxAPIError(res)
}

const urls = []

for (const thumb of res.body.data) {
if (thumb.state !== 'Completed') {
throw new Error(`The requested image for group ${thumb.targetId} has not been approved. State: ${thumb.state}`)
}

urls.push(thumb.imageUrl)
}

return urls.length > 1 ? urls : urls.at(0)
})
}

exports.func = function (args) {
return getLogo(args.group)
}
Loading