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

Commit

Permalink
fix weird merge stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
F1sxher committed Dec 2, 2021
2 parents f4c76a7 + d18e5e9 commit 08a297d
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 207 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Node.js Package
on:
workflow_dispatch:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Setup repo
- name: Checkout repository
uses: actions/checkout@v2

# Setup .npmrc file to publish to npm && Install Node 16
- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: npm

# Checks the perviously released version of dev branch
- name: Check previous released version
id: pre-release
run: |
if [[ $(npm view tyblox.js@dev version | grep -e "$(jq --raw-output '.version' package.json).*.$(git rev-parse --short HEAD | cut -b1-3)") ]]; \
then echo '::set-output name=release::false'; \
else echo '::set-output name=release::true'; fi
# Runs npm install
- name: Install
run: npm install

# Deprecate old versions
- name: Deprecate old versions
if: steps.pre-release.outputs.release == 'true'
run: npm deprecate tyblox.js@"~$(jq --raw-output '.version' package.json)" "This version of tyblox.js is no longer supported, please upgrade to a later version." || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

# Publishes Pkg to Dev Branch
- name: Publish
run: |
npm version --git-tag-version=false $(jq --raw-output '.version' package.json).$(date +%s).$(git rev-parse --short HEAD)
npm publish --tag dev || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
366 changes: 183 additions & 183 deletions LICENSE

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# tyblox
# **tyblox.js**

## **The most powerful ROBLOX API Wrapper**

---

**tyblox.js** is the most powerful [Node.js](https://nodejs.org/) package which allows you to quickly, and easily interact with the Roblox API.

- Object-Oriented
- Performant
- Typescript Capable

## Installation

**Node.js 16.6.0 or newer is required for this to work properly**

**NPM 7.0.0 or newer is required to work properly.**

```sh
$ npm install tyblox.js
```

---

## Getting started

Below is an example to login and access many features of tyblox.js

```js
require("dotenv").config();
const { Client } = require("../src/index");

const client = new Client();

client.on("ready", () => {
console.log("Ready!");

console.log("Logged in as " + client.user.username);
});

client.login(process.env.example_cookie);
```
6 changes: 4 additions & 2 deletions examples/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const { Client } = require("../src/index");
const client = new Client();

client.on("ready", () => {

});
console.log("Ready!")

console.log("Logged in as " + client.user.username)
})

client.login(process.env.example_cookie);
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"types": "./typings/index.d.ts",
"scripts": {
"postinstall": "node postInstall.js"
"postinstall": "node postInstall.js",
"examples.login": "node examples/login.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,5 +36,9 @@
"eslint-plugin-import": "^2.25.3",
"figlet": "^1.5.2",
"typescript": "^4.5.2"
},
"engines": {
"node": ">=16.6.0",
"npm": ">=7.0.0"
}
}
40 changes: 34 additions & 6 deletions src/client/Client.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
const { usingCookie } = require("../user/getUser");
const getUser = require("../user/getUser");
const EventEmitter = require("events");

/**
* The Main Client for **`tyblox.js`** used for running
* The Main Client for **`tyblox.js`** used for running any functions needed using the ROBLOX API, mostly involving the ones with cookies.
* @type {import('../../typings/index').Client}
*/
class Client extends EventEmitter {

/**
* The Clients Cookie
* @type {string | null}
*/
cookie = null;

/**
* The Client's User
* @type {import('../../typings/index').User | null}
*/
user = null;

/**
* Logs the client in, establishing a WebSocket connection to Discord.
* Logs the client in, sets the cookie, and confirms that the cookie is valid
* @param {string} [cookie=this.cookie] The Cookie of the account to log in with
* @returns {Promise<{STATUS: "OK" | "ERROR", MESSAGE?: string}>} The Cookie of the account used
* @example
* ```js
* require("dotenv").config();
* const { Client } = require("../src/index");
*
* const client = new Client();
*
* client.on("ready", () => {
* console.log("Ready!")
*
* console.log("Logged in as " + client.user.username)
* })
*
* client.login('_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_');
* ```
*/
async login(cookie = this.cookie) {
if (!cookie || typeof cookie !== "string")
throw new Error("INVALID COOKIE ");
usingCookie(cookie);
this.user = await getUser.usingCookie(cookie, false);
this.user.cookieValid();
console.log(this.user)

this.emit("ready");
}
}

Expand Down
18 changes: 11 additions & 7 deletions src/request.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
const Axios = require("axios");
const axios = Axios.default;
const { RequestOptions } = require("../typings/index.d.ts");
const axios = require('axios').default;

/**
* Do a `GET` request to an API, usually roblox.
* @param {RequestOptions} [options] The request options.
* @param {import('../typings/index').RequestOptions} [options] The request options.
* @returns {Promise}
* @example
* getUser.usingId('123456');
*/
exports.get = async (options) => {
if (!options) throw new Error("OPTIONS REQUIRED")
if (!options.baseUrl) throw new Error("BASE URL REQUIRED")

let finalUrl =
options.baseUrl +
(options.inUrlParam1 || "") +
(options.extendedUrl || "") +
(options.inUrlParam2 || "");

let finalHeaders = {};
if (options.cookie) finalHeaders.Cookie = options.cookie;
options.headers.forEach((header) => {
if (options.cookie) finalHeaders.Cookie = `.ROBLOSECURITY=${options.cookie};`;
if (options.headers) options.headers.forEach((header) => {
finalHeaders[header.key] = header.value;
});

axios.get(finalUrl, {
return await axios.get(finalUrl, {
withCredentials: true,
headers: finalHeaders,
}).then((res) => {
return res.data;
});
};
36 changes: 34 additions & 2 deletions src/user/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* The User Class for **`tyblox.js`** used for getting user details
* @type {import('../../typings/index').User}
*/
class User {
/**
Expand Down Expand Up @@ -79,12 +80,42 @@ class User {
description;

/**
* If the cookie (assuming given) for this roblox user class seems to be valid
* @type boolean
* Construct the User class
* @param {boolean} [limitedAccess] If the user has limited access to functions
* @param {import('../../typings/index').UserConstructor} [info] The Cookie of the account to log in with
*/
constructor(limitedAccess, info) {
this._initLimited = limitedAccess;

this._cookie = info._cookie;
this.userId = info.userId;
this.username = info.username;
this.displayName = info.displayName;
this.hasPremium = info.hasPremium;
this.banned = info.banned;
this.description = info.description;
}

/**
* @returns {void}
* @private
*/
_reloadAvatar() {

}

/**
* If the cookie (assuming given) for this roblox user class seems to be valid*
*
* ***Note**: This is not a guarantee that the cookie is valid, it is a basic check to see if the cookie *seems* valid
* @returns {boolean}
* @public
*/
cookieValid() {
if (!this._cookie) return false;
if (!this._cookie.toLowerCase().includes('_|WARNING:-DO-NOT-SHARE-THIS.')) {
console.error('No ROBLOX warning was found in the provided cookie. Ensure that you include the entire .ROBLOSECURITY warning!')
} else return true;
}

/**
Expand All @@ -104,6 +135,7 @@ class User {
* @public
*/
avatarUrl(avatarType) {
this._reloadAvatar();
if (this._avatar && this._avatar[avatarType]) {
return this._avatar[avatarType];
} else return false;
Expand Down
34 changes: 29 additions & 5 deletions src/user/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,44 @@ const routes = require("../routes");

/**
* Gets information for a user using its user ID - will most likely have limited access (see {@link User.limitedAccess })
* @param {string} [cookie] The Cookie of the account to log in with
* @param {string | number} [userId] The Cookie of the account to log in with
* @returns {Promise<User>}
* @example
* getUser.usingId('123456');
* ```js
* const tyblox = require("tyblox.js")
*
* tyblox.getUser.usingId('123456');
* ```
*/
exports.usingId = async () => {};

/**
* Gets information for a user using its cookie - will most likely NOT have limited access
* @param {string} [cookie] The Cookie of the account to get information on
* @param {boolean} [forceLimited] Make the account limited anyways
* @returns {Promise<User>}
* @example
* getUser.usingCookie('_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_');
* ```js
* const tyblox = require("tyblox.js")
*
* tyblox.getUser.usingCookie('_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_');
* ```
*/
exports.usingCookie = async (cookie) => {
request.get(routes.v1.users.mobileapi_userinfo);
exports.usingCookie = async (cookie, forceLimited) => {

/**
* @type {import('../../typings/routes').v1_users_mobileapi_userinfo | null}
*/
let partialDataLoggedIn = await request.get({
baseUrl: routes.v1.users.mobileapi_userinfo,
cookie: cookie
});

let newUser = new User(forceLimited, {
userId: partialDataLoggedIn.UserID,
username: partialDataLoggedIn.UserName,
hasPremium: partialDataLoggedIn.IsPremium,
});

return newUser;
};
13 changes: 13 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// import EventEmitter = require("events");

export type AvatarType = "headshot" | "avatarBust" | "avatarThumbnail";

export class Client {}

export interface UserConstructor {
_cookie?: string;
userId: number;
username: string;
displayName: string;
hasPremium: boolean;
banned: boolean;
description: string;
}

export class User {
private _cookie: string | null;
private _previousNames: string[] | null;
Expand All @@ -16,6 +28,7 @@ export class User {
public readonly hasPremium: boolean;
public readonly banned: boolean;
public readonly description: string;
public cookieValid(): boolean;
public limitedAccess(): boolean;
public avatarUrl(type: AvatarType): string;
public previousNames(): string[] | null;
Expand Down
8 changes: 8 additions & 0 deletions typings/routes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface v1_users_mobileapi_userinfo {
UserID: string;
UserName: string;
RobuxBalance: number;
ThumbnailUrl: string;
IsAnyBuildersClub: boolean;
IsPremium: boolean;
}

0 comments on commit 08a297d

Please sign in to comment.