Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from tyradigital/dev
Browse files Browse the repository at this point in the history
Merge to stable
  • Loading branch information
fisherjacobc authored Apr 17, 2022
2 parents f27658e + 7ced84f commit 979ff5e
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 41 deletions.
7 changes: 4 additions & 3 deletions examples/rank.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ client.on("ready", async () => {

client.defaultGroup = 13299030

const rank = await tyblox.getGroupRank(531761235, 3395411)
console.log(rank)
const getrank = await tyblox.getGroupRank(531761235, 3395411)
console.log(getrank)

await tyblox.setRank(client, 445177180, 2)
const setrank = await tyblox.setRank(client, 87516258, 2)
console.log(setrank)
})

client.login(process.env.example_cookie);
2 changes: 1 addition & 1 deletion src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Client extends EventEmitter {
if (!cookie || !this.cookie) throw new Error("NO COOKIE PROVIDED OR FOUND");

/**
* @type {import('../../typings/routes').response}
* @type {import('../../typings/response').response}
*/
let tokenReq = await request.post({
url: `${routes.v2.bases.authApi()}${routes.v2.logout()}`,
Expand Down
6 changes: 3 additions & 3 deletions src/group/getRanks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const routes = require("../routes");
/**
* Get the users group ranks
* @param {string | number} userId The user id you want to find the rank for
* @returns {import('../../typings/routes').v2_groups_ranks}
* @returns {import('../../typings/response').v2_groups_ranks}
* @example
* ```js
* const tyblox = require("tyblox.js")
Expand All @@ -19,7 +19,7 @@ const routes = require("../routes");
if (!userId) throw new Error("MISSING GROUP ID")

/**
* @type {import('../../typings/routes').v2_groups_ranks | null}
* @type {import('../../typings/response').v2_groups_ranks | null}
*/
let rolesets = await request.get({
url: `${routes.v1.bases.groupsApi()}${routes.global.getUserRanks(userId)}`
Expand Down Expand Up @@ -48,7 +48,7 @@ exports.getGroupRank = async (userId, groupId) => {
if (!groupId) throw new Error("MISSING GROUP ID")

/**
* @type {import('../../typings/routes').v2_groups_ranks | null}
* @type {import('../../typings/response').v2_groups_ranks | null}
*/
let ranks = await request.get({
url: `${routes.v1.bases.groupsApi()}${routes.global.getUserRanks(userId)}`,
Expand Down
6 changes: 3 additions & 3 deletions src/group/getRolesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const routes = require("../routes");
/**
* Get the groups roles in a list
* @param {string | number} groupId The group id for the rolesets you want to get
* @returns {import('../../typings/routes').v1_groups_rolesets}
* @returns {import('../../typings/response').v1_groups_rolesets}
* @example
* ```js
* const tyblox = require("tyblox.js")
Expand All @@ -19,11 +19,11 @@ module.exports = async (groupId) => {
if (!groupId) throw new Error("MISSING GROUP ID")

/**
* @type {import('../../typings/routes').v1_groups_rolesets | null}
* @type {import('../../typings/response').v1_groups_rolesets | null}
*/
let rolesets = await request.get({
url: `${routes.v1.bases.groupsApi()}${routes.v1.getRolesets(groupId)}`
})

return rolesets.data
return rolesets
}
11 changes: 7 additions & 4 deletions src/group/setRank.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ module.exports = async (client, userId, newRank, groupId) => {
if (newRank > 255 || newRank < 1) throw new Error("INVALID NEW RANK")
let rolesets = await getRolesets(groupId || client.defaultGroup)

let rolesetFound = rolesets.roles.find((roleset) => {
if (roleset.rank === newRank) return true;
let rolesetFound = rolesets.data.roles.find((roleset) => {
return (roleset.rank === newRank)
})
if (!rolesetFound) throw new Error("ROLE ID NOT FOUND FOR THIS GROUP")
console.log(parseInt(rolesetFound.id))

await request.patch({
const req = await request.patch({
url: `${routes.v1.bases.groupsApi()}${routes.v1.groupMember(groupId || client.defaultGroup, userId)}`,
cookie: client.cookie,
token: client.token,
silenceErr: true,
body: {
roleId: newRank
roleId: parseInt(rolesetFound.id)
}
})

return req.data
}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

// Internal
exports.internal = {
/**
* @type {import('../typings/index').request}
*/
request: require("./request")
}

Expand Down
6 changes: 2 additions & 4 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const axios = require('axios').default;
/**
* Do a `GET` request to an API, usually roblox.
* @param {import('../typings/index').RequestOptions} options The request options.
* @returns {Promise<any>}
* @example
* request.get(...options);
*/
Expand Down Expand Up @@ -42,7 +41,6 @@ exports.get = async (options) => {
/**
* Do a `POST` request to an API, usually roblox.
* @param {import('../typings/index').RequestOptions} options The request options.
* @returns {Promise<any>}
* @example
* request.get(...options);
*/
Expand Down Expand Up @@ -99,7 +97,7 @@ exports.get = async (options) => {
});

if (options.silenceErr) {
return await axios.patch(options.url, JSON.stringify(options.body) || {}, {
return await axios.patch(options.url, options.body || {}, {
method: "PATCH",
withCredentials: true,
headers: finalHeaders,
Expand All @@ -109,7 +107,7 @@ exports.get = async (options) => {
return {code: res.status, headers: res.headers, data: res.data};
});
} else {
return await axios.patch(options.url, JSON.stringify(options.body) || {}, {
return await axios.patch(options.url, options.body || {}, {
method: "PATCH",
withCredentials: true,
headers: finalHeaders,
Expand Down
8 changes: 4 additions & 4 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const routes = {
*
* @param {string} groupId
* @param {string} userId
* @returns
* @returns {`/groups/${groupId}/users/${userId}`}
*/
groupMember: (groupId, userId) => `/groups/${groupId}/users/${userId}`,

Expand All @@ -124,7 +124,7 @@ const routes = {
* @param {boolean} circular
* @param {import('../typings/index').ThumbnailAvatarSize} size
* @param {import('../typings/index').AvatarFormat} format
* @returns
* @returns {`/users/avatar?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`}
*/
userAvatarThumbnail: (userIds, circular, size = "720x720", format = "Png") => `/users/avatar?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`,

Expand All @@ -135,7 +135,7 @@ const routes = {
* @param {boolean} circular
* @param {import('../typings/index').BustAvatarSize} size
* @param {import('../typings/index').AvatarFormat} format
* @returns
* @returns {`/users/avatar-bust?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`}
*/
userAvatarBust: (userIds, circular, size = "420x420", format = "Png") => `/users/avatar-bust?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`,

Expand All @@ -146,7 +146,7 @@ const routes = {
* @param {boolean} circular
* @param {import('../typings/index').HeadshotAvatarSize} size
* @param {import('../typings/index').AvatarFormat} format
* @returns
* @returns {`/users/avatar-headshot?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`}
*/
userAvatarHeadshot: (userIds, circular, size = "720x720", format = "Png") => `/users/avatar-headshot?format=${format}&size=${size}&isCircular=${circular}&userIds=${userIds.join(",")}`,

Expand Down
4 changes: 2 additions & 2 deletions src/thumbnail/avatar/getAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const routes = require("../../routes");
* Gets the users avatar thumbnail
* @param {string[] | number[]} userIds The User Ids to get the avatar urls.
* @param {boolean} circle If the returned image should be a circle
* @returns {Promise<import('../../../typings/routes').v1_thumbnails_users_avatar[]>}
* @returns {Promise<import('../../../typings/response').v1_thumbnails_users_avatar[]>}
* @example
* ```js
* const tyblox = require("tyblox.js")
Expand All @@ -15,7 +15,7 @@ const routes = require("../../routes");
*/
module.exports = async (userIds, circular) => {
/**
* @type {import('../../../typings/routes').v1_thumbnails_user_avatars | null}
* @type {import('../../../typings/response').v1_thumbnails_user_avatars | null}
*/
let thumbnailData = await request.get({
url: `${routes.v1.bases.thumbnailsApi()}${routes.v1.userAvatarThumbnail(userIds, circular, "720x720", "Png")}`
Expand Down
4 changes: 2 additions & 2 deletions src/thumbnail/avatar/getBust.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const routes = require("../../routes");
* Gets the users avatar bust
* @param {string[] | number[]} userIds The User Ids to get the avatar urls.
* @param {boolean} circle If the returned image should be a circle
* @returns {Promise<import('../../../typings/routes').v1_thumbnails_users_avatar[]>}
* @returns {Promise<import('../../../typings/response').v1_thumbnails_users_avatar[]>}
* @example
* ```js
* const tyblox = require("tyblox.js")
Expand All @@ -15,7 +15,7 @@ const routes = require("../../routes");
*/
module.exports = async (userIds, circular) => {
/**
* @type {import('../../../typings/routes').v1_thumbnails_user_avatars | null}
* @type {import('../../../typings/response').v1_thumbnails_user_avatars | null}
*/
let thumbnailData = await request.get({
url: `${routes.v1.bases.thumbnailsApi()}${routes.v1.userAvatarBust(userIds, circular, "420x420", "Png")}`
Expand Down
4 changes: 2 additions & 2 deletions src/thumbnail/avatar/getHeadshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const routes = require("../../routes");
* Gets the users avatar headshot
* @param {string[] | number[]} userIds The User Ids to get the avatar urls.
* @param {boolean} circle If the returned image should be a circle
* @returns {Promise<import('../../../typings/routes').v1_thumbnails_users_avatar[]>}
* @returns {Promise<import('../../../typings/response').v1_thumbnails_users_avatar[]>}
* @example
* ```js
* const tyblox = require("tyblox.js")
Expand All @@ -15,7 +15,7 @@ const routes = require("../../routes");
*/
module.exports = async (userIds, circular) => {
/**
* @type {import('../../../typings/routes').v1_thumbnails_user_avatars | null}
* @type {import('../../../typings/response').v1_thumbnails_user_avatars | null}
*/
let thumbnailData = await request.get({
url: `${routes.v1.bases.thumbnailsApi()}${routes.v1.userAvatarHeadshot(userIds, circular, "720x720", "Png")}`
Expand Down
2 changes: 1 addition & 1 deletion src/user/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class User {
*/
async getPreviousNames() {
/**
* @type {import('../../typings/routes').v1_users_username_history}
* @type {import('../../typings/response').v1_users_username_history}
*/
let names = await request.get({
url: `${routes.v1.bases.usersApi()}${routes.v1.usernameHistory(this.userId)}`
Expand Down
6 changes: 3 additions & 3 deletions src/user/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const routes = require("../routes");
exports.usingId = async (userId) => {

/**
* @type {import('../../typings/routes').v1_users_get_user_info_id | null}
* @type {import('../../typings/response').v1_users_get_user_info_id | null}
*/
let dataPublic = await request.get({
url: `${routes.global.bases.api}${routes.global.getUserInfoById(userId)}`
Expand Down Expand Up @@ -52,7 +52,7 @@ exports.usingId = async (userId) => {
exports.usingCookie = async (cookie, forceLimited) => {

/**
* @type {import('../../typings/routes').v1_users_mobileapi_userinfo | null}
* @type {import('../../typings/response').v1_users_mobileapi_userinfo | null}
*/
let req1 = await request.get({
url: `${routes.global.bases.mobileApi()}${routes.global.mobileUserInfo()}`,
Expand All @@ -61,7 +61,7 @@ exports.usingCookie = async (cookie, forceLimited) => {
let partialDataLoggedIn = req1.data;

/**
* @type {import('../../typings/routes').v1_users_get_user_info_id | null}
* @type {import('../../typings/response').v1_users_get_user_info_id | null}
*/
let req2 = await request.get({
url: `${routes.global.bases.api()}${routes.global.getUserInfoById(partialDataLoggedIn.UserID)}`
Expand Down
3 changes: 3 additions & 0 deletions typings/body.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface body {
[key: string]: string;
}
47 changes: 45 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import EventEmitter = require("events");
import { body } from "./body";
import { response } from "./response";

export enum AvatarType {
avatarThumbnail = "thumbnail",
Expand Down Expand Up @@ -100,11 +102,52 @@ export interface Header {
value: string;
}

export interface RequestOptions {
export interface RequestOptions<T extends body> {
url: string;
headers?: Header[];
cookie?: string;
token?: string;
body?: any;
body?: T;
silenceErr: boolean;
}

export interface request {
/**
* Do a `GET` request to an API, usually roblox.
* @example
* request.get(...options);
*
* // or
*
* internal.reqest.get(...options);
*/
get<T extends body, U extends response>(
options: RequestOptions<T>
): Promise<U>;

/**
* Do a `POST` request to an API, usually roblox.
* @example
* request.post(...options);
*
* // or
*
* internal.request.post(...options);
*/
post<T extends body, U extends response>(
options: RequestOptions<T>
): Promise<U>;

/**
* Do a `PATCH` request to an API, usually roblox.
* @example
* request.patch(...options);
*
* // or
*
* internal.request.patch(...options);
*/
patch<T extends body, U extends response>(
options: RequestOptions<T>
): Promise<U>;
}
12 changes: 5 additions & 7 deletions typings/routes.d.ts → typings/response.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ export interface v1_groups_info extends response {
}

export interface v1_groups_roleset {
data: {
id: string;
name: string;
rank: number;
memberCount: number;
description?: string;
};
id: string;
name: string;
rank: number;
memberCount: number;
description?: string;
}

export interface v1_groups_rolesets extends response {
Expand Down

0 comments on commit 979ff5e

Please sign in to comment.