Skip to content

Commit

Permalink
Resolved merge conflicts with upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Prioq committed Aug 22, 2024
2 parents a9cf502 + b21307c commit 6a0ef82
Show file tree
Hide file tree
Showing 31 changed files with 3,749 additions and 734 deletions.
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .github/FUNDING.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/doc-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 20

- name: Install yarn
run: npm install -g yarn
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Test & Publish

on:
pull_request:
branches:
- master

push:
branches:
- master
Expand All @@ -15,7 +19,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 20

- name: Install yarn
run: npm install -g yarn
Expand All @@ -28,6 +32,7 @@ jobs:

publish-npm:
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout code with ADMIN_TOKEN
Expand All @@ -46,22 +51,22 @@ jobs:
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 20

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: yarn-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-deps-${{ hashFiles('yarn.lock') }}
- name: Create Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run tests

on:
workflow_dispatch


jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 20

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Lint lib/
run: yarn lint
- name: Run tests
env:
COOKIE: ${{ secrets.COOKIE }}
COOKIE_2: ${{ secrets.COOKIE_2 }}
run: yarn test

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-blue.svg?style=flat-square" alt="JavaScript Style Guide"/></a>
<a href="https://discord.gg/R5GVSyTVGv"><img src="https://img.shields.io/badge/discord-noblox.js-blue.svg?style=flat-square" alt="noblox.js Discord"/></a>
<a href="https://npmjs.org/noblox.js"><img src="https://img.shields.io/npm/v/noblox.js.svg?style=flat-square" alt="NPM package"/>
<a href="https://travis-ci.org/noblox/noblox.js"><img src="https://img.shields.io/travis/noblox/noblox.js/master.svg?style=flat-square" alt="Travis Build Status"/></a></a>
</p>

<p align="center">
Expand All @@ -30,15 +29,15 @@

`noblox.js` is an open-source Roblox API wrapper written in JavaScript (with TypeScript compatibility) as a fork from sentanos's <a href="https://github.com/sentanos/roblox-js"> roblox-js module</a>.

This NPM package enables operations froms the [Roblox website](https://www.roblox.com) to be executed via NodeJS; many individuals leverage `noblox.js` along side [Roblox's HTTPService](http://wiki.roblox.com/index.php?title=API:Class/HttpService) to create in-game scripts that interact with the website, i.e. promote users, shout events, and so on, or to create Discord utiltiies to manage their community.
This NPM package enables operations froms the [Roblox website](https://www.roblox.com) to be executed via NodeJS; many individuals leverage `noblox.js` along side [Roblox's HTTPService](http://wiki.roblox.com/index.php?title=API:Class/HttpService) to create in-game scripts that interact with the website, i.e. promote users, shout events, and so on, or to create Discord utilities to manage their community.

If you are looking for more information on how to create something like this, check out [our sister library, `noblox.js-server`](https://github.com/noblox/noblox.js-server) or [our YouTube series](https://www.youtube.com/playlist?list=PLEW4K4VqMUb_VMA3Yp9LI4gReRyVWGTnU). Keep in mind that these resources may not always be up to date, so it is **highly** encouraged that you learn to use the `noblox.js` library directly.

---

## Prerequisites

- [**Node.js®**](https://nodejs.org/en/download/current/)
- [**Node.js®**](https://nodejs.org/en/download/current/) v18.18 or later

---

Expand Down
34 changes: 34 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import jest from "eslint-plugin-jest";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("standard", "plugin:jest/recommended"), {
plugins: {
jest,
},

languageOptions: {
globals: {
...globals.commonjs,
...globals.node,
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},

ecmaVersion: 2018,
sourceType: "commonjs",
},

rules: {},
}];
10 changes: 8 additions & 2 deletions lib/chat/getConversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.optional = ['jar']
* @example const noblox = require("noblox.js")
* // Login using your cookie
* const conversations = await noblox.getConversations([1, 2, 3])
**/
**/

exports.func = (args) => {
const jar = args.jar
Expand All @@ -28,7 +28,13 @@ exports.func = (args) => {
}
}).then((res) => {
if (res.statusCode !== 200) {
throw new Error('You are not logged in')
const body = JSON.parse(res.body) || {}
if (body.errors && body.errors.length > 0) {
const errors = body.errors.map((e) => {
return e.message
})
throw new Error(`${res.statusCode} ${errors.join(', ')}`)
}
} else {
let response = JSON.parse(res.body)

Expand Down
44 changes: 43 additions & 1 deletion lib/client/onNotification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Dependencies
<<<<<<< HEAD
const { HubConnectionBuilder, HttpTransportType } = require('@microsoft/signalr')
=======
const signalR = require('@microsoft/signalr')
>>>>>>> upstream/master
const events = require('events')
// Includes
Expand Down Expand Up @@ -37,6 +41,7 @@ exports.func = function (args) {
args.jar = { session: args.jar }
}
const session = getSession({ jar: args.jar })
<<<<<<< HEAD
const headers = {
Cookie: '.ROBLOSECURITY=' + session + ';'
// Add other headers if needed
Expand Down Expand Up @@ -77,6 +82,27 @@ exports.func = function (args) {
client.serviceHandlers = client.serviceHandlers || {}
client.serviceHandlers.connectFailed = function (err) {
console.error('Connection failed:', err)
=======
let userNotificationConnection = null

userNotificationConnection = new signalR.HubConnectionBuilder()
.withUrl('https://realtime-signalr.roblox.com/userhub', {
transport: signalR.HttpTransportType.WebSockets,
skipNegotiation: true,
headers: {
Cookie: '.ROBLOSECURITY=' + session + ';'
}
})
.build()

userNotificationConnection.on('notification', function (name, message) {
notifications.emit('data', name, JSON.parse(message))
})

notifications.on('close', userNotificationConnection.stop)

userNotificationConnection.disconnected = function (err) {
>>>>>>> upstream/master
notifications.emit('error', new Error('Connection failed: ' + err.message))
if (retries !== -1) {
if (retries > max) {
Expand All @@ -86,25 +112,41 @@ exports.func = function (args) {
}
}
}
<<<<<<< HEAD
client.serviceHandlers.onerror = function (err) {
console.error('Connection error:', err)
=======

userNotificationConnection.error = function (err) {
>>>>>>> upstream/master
notifications.emit('error', err)
}
client.serviceHandlers.connected = function (connection) {

userNotificationConnection.connected = function (connection) {
notifications.emit('connect', connection)
}
<<<<<<< HEAD
client.serviceHandlers.reconnecting = function () {
=======

userNotificationConnection.reconnecting = function () {
setTimeout(connect, 5000, 0)
>>>>>>> upstream/master
notifications.emit('error', new Error('Lost connection, reconnecting'))
return true // Abort reconnection
}

<<<<<<< HEAD
try {
await client.start()
return client
} catch (err) {
console.error('Error while starting connection:', err)
throw err
}
=======
userNotificationConnection.start()
>>>>>>> upstream/master
}

connect(-1)
Expand Down
6 changes: 3 additions & 3 deletions lib/client/setCookie.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const options = require('../options.js')
const getCurrentUser = require('../util/getCurrentUser.js').func
const getAuthenticatedUser = require('../util/getAuthenticatedUser.js').func

exports.required = ['cookie']
exports.optional = ['validate']
Expand All @@ -11,7 +11,7 @@ exports.optional = ['validate']
* @alias setCookie
* @param {string} cookie - The cookie to sign in with.
* @param {boolean=} [validate=true] - Whether to validate the cookie or not.
* @returns {Promise<LoggedInUserData>}
* @returns {Promise<AuthenticatedUserData>}
* @example const noblox = require("noblox.js")
* noblox.setCookie("cookie").then(function() {
* //your code here
Expand All @@ -28,7 +28,7 @@ exports.func = async function (args) {
return false
}
try {
const res = await getCurrentUser({ jar: { session: args.cookie } })
const res = await getAuthenticatedUser({ jar: { session: args.cookie } })
options.jar.session = args.cookie
return res
} catch (error) {
Expand Down
44 changes: 44 additions & 0 deletions lib/economy/getUserFunds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Includes
const http = require('../util/http.js').func

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

// Docs
/**
* 🔓 Gets the amount of robux for the authenticated user.
* @category User
* @param {number} userId - Must match the userId of the authenticated user
* @alias getUserFunds
* @returns {Promise<number>}
* @example const noblox = require("noblox.js")
* // Login using your cookie
* const currentUser = await noblox.setCookie(process.env.ROBLOXCOOKIE)
* const robux = await noblox.getUserFunds(currentUser.id)
*/

// Define
function getUserFunds (userId, jar) {
return http({
url: `//economy.roblox.com/v1/users/${userId}/currency`,
options: {
jar,
resolveWithFullResponse: true
}
})
.then(({ statusCode, body }) => {
const { robux, errors } = JSON.parse(body)
if (statusCode === 200) {
return robux
} else if (statusCode === 400 || statusCode === 403) {
throw new Error(`${errors[0].message} | userId: ${userId}`)
} else {
throw new Error(`An unknown error occurred with getUserFunds() | [${statusCode}] userId: ${userId}`)
}
})
}

exports.func = function ({ userId, jar }) {
return getUserFunds(userId, jar)
}
Loading

0 comments on commit 6a0ef82

Please sign in to comment.