Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #826

Closed
wants to merge 36 commits into from
Closed

merge #826

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f23b48
Update dependencies and refactor SignalR connection
Prioq Mar 31, 2024
406c379
Refactor client connection handling in onNotification.js
Prioq Mar 31, 2024
1600040
Add onFriendshipCreated event handler
Prioq Mar 31, 2024
6df1cf8
Fix syntax errors and error handling in onNotification.js
Prioq Mar 31, 2024
d97d8cc
Update API endpoints for friend requests and followers to use roproxy
Prioq Mar 31, 2024
00ea07d
Update API endpoints to use roproxy.com
Prioq Apr 1, 2024
58bd664
feat: add onFriendShipCreation event handler
Prioq Apr 7, 2024
f43fab1
fix: joining strings on getPlaceInfo
Prioq Apr 8, 2024
a5d3152
fix: update event listener in index.d.ts to use FriendEntry instead o…
Prioq Apr 8, 2024
eaa8011
fix: typo
Prioq Apr 8, 2024
d60b20f
fix: Update event listener in index.d.ts to use NewFriendship instead…
Prioq Apr 8, 2024
c7dff7d
feat: update getPageResults function to handle non-JSON response
Prioq Apr 22, 2024
a0c903e
feat: update API endpoint for getGamePassProductInfo to use roproxy.com
Prioq Apr 22, 2024
8376e42
feat: update API endpoints to use roproxy.com
Prioq May 6, 2024
475aacc
feat: Improve error handling in getPremium function
Prioq May 6, 2024
8afa7b6
feat: update API endpoints to use roproxy.com
Prioq May 18, 2024
0e844b6
feat: update index.d.ts to include a close() method in the OnFriendSh…
Prioq May 18, 2024
6480945
feat: update SignalR URL to use roblox.com instead of roproxy.com
Prioq May 18, 2024
ccb7699
fix: Improve error handling in getFriends function
Prioq May 24, 2024
85332a1
refactor: Update getFriends API endpoint to use roblox.com instead of…
Prioq May 29, 2024
3d93eaa
chore: add try catch statments for JSON.parse
Prioq Jul 11, 2024
42dc845
fix rate limiting bug
Lonegwadiwaitor Jul 12, 2024
836d745
friend request ratelimit fix attempt # 1
Lonegwadiwaitor Jul 13, 2024
2b7120b
why is this stupid api not using my code
Lonegwadiwaitor Jul 13, 2024
ab8b68a
fix: handle JSON parsing errors in acceptFriendRequest function
Prioq Jul 22, 2024
ea21406
chore: lint
Prioq Jul 22, 2024
62cba4d
feat: add url parameter
Prioq Jul 25, 2024
df2d2cf
fix: remove console logs
Prioq Jul 25, 2024
4974069
fix: typings
Prioq Jul 25, 2024
8efda66
fix: add apiUrl to the optional parameters
Prioq Jul 28, 2024
eef426f
fix: removeFriend
Prioq Jul 28, 2024
f5d8323
fix: block and unblock
Prioq Jul 28, 2024
1567589
fix: remove protocol from default url
Prioq Jul 28, 2024
00bbfbc
fix: add apiUrl to the types for acceptFriendRequest
Prioq Jul 28, 2024
a9cf502
fix: add apiUrl to getFriends types
Prioq Jul 28, 2024
6a0ef82
Resolved merge conflicts with upstream/master
Prioq Aug 22, 2024
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
34 changes: 20 additions & 14 deletions lib/accountsettings/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getGeneralToken = require('../util/getGeneralToken.js').func

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

// Docs
/**
Expand All @@ -16,13 +16,13 @@ exports.optional = ['jar']
* @example const noblox = require("noblox.js")
* // Login using your cookie
* noblox.block(123456)
**/
**/

// Define
function block (jar, token, userId) {
function block (jar, token, userId, apiUrl) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//accountsettings.roblox.com/v1/users/${userId}/block`,
url: `//${apiUrl}/v1/users/${userId}/block`,
options: {
method: 'POST',
jar,
Expand All @@ -32,27 +32,33 @@ function block (jar, token, userId) {
resolveWithFullResponse: true
}
}
return http(httpOpt)
.then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
return http(httpOpt).then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
try {
const body = JSON.parse(res.body) || {}
if (body.errors && body.errors.length > 0) {
const errors = body.errors.map((e) => {
return e.message
})
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
}
} catch (err) {
reject(new Error(`${res.statusCode} ${res.body}`))
}
})
}
})
})
}

exports.func = function (args) {
const jar = args.jar
return getGeneralToken({ jar })
.then(function (xcsrf) {
return block(jar, xcsrf, args.userId)
})
return getGeneralToken({ jar }).then(function (xcsrf) {
let apiUrl = 'accountsettings.roblox.com'
if (args.apiUrl) {
apiUrl = args.apiUrl
}
return block(jar, xcsrf, args.userId, apiUrl)
})
}
34 changes: 20 additions & 14 deletions lib/accountsettings/unblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getGeneralToken = require('../util/getGeneralToken.js').func

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

// Docs
/**
Expand All @@ -16,13 +16,13 @@ exports.optional = ['jar']
* @example const noblox = require("noblox.js")
* // Login using your cookie
* noblox.unblock(123456)
**/
**/

// Define
function unblock (jar, token, userId) {
function unblock (jar, token, userId, apiUrl) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//accountsettings.roblox.com/v1/users/${userId}/unblock`,
url: `//${apiUrl}/v1/users/${userId}/unblock`,
options: {
method: 'POST',
jar,
Expand All @@ -32,27 +32,33 @@ function unblock (jar, token, userId) {
resolveWithFullResponse: true
}
}
return http(httpOpt)
.then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
return http(httpOpt).then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
try {
const body = JSON.parse(res.body) || {}
if (body.errors && body.errors.length > 0) {
const errors = body.errors.map((e) => {
return e.message
})
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
}
} catch (err) {
reject(new Error(`${res.statusCode} ${res.body}`))
}
})
}
})
})
}

exports.func = function (args) {
const jar = args.jar
return getGeneralToken({ jar })
.then(function (xcsrf) {
return unblock(jar, xcsrf, args.userId)
})
return getGeneralToken({ jar }).then(function (xcsrf) {
let apiUrl = 'accountsettings.roblox.com'
if (args.apiUrl) {
apiUrl = args.apiUrl
}
return unblock(jar, xcsrf, args.userId, apiUrl)
})
}
29 changes: 21 additions & 8 deletions lib/asset/getGamePassProductInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports.required = ['gamepass']
function getGamePassProductInfo (gamepass) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//apis.roblox.com/game-passes/v1/game-passes/${gamepass}/product-info`,
url: `//apis.roproxy.com/game-passes/v1/game-passes/${gamepass}/product-info`,
options: {
resolveWithFullResponse: true,
method: 'GET'
Expand All @@ -28,14 +28,27 @@ function getGamePassProductInfo (gamepass) {

return http(httpOpt)
.then(function (res) {
const data = JSON.parse(res.body)
try {
// First, check the content type
const contentType = res.headers['content-type']
if (contentType && contentType.includes('application/json')) {
const data = JSON.parse(res.body)

if (res.statusCode === 200) {
resolve(data)
} else {
const errors = data.errors.map((e) => e.message)

reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
if (res.statusCode === 200) {
resolve(data)
} else {
console.log(data)
const errors = Array.isArray(data.errors) ? data.errors.map((e) => e.message) : ['Unknown error']
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
}
} else {
// If not JSON, handle or log accordingly
console.error('Non-JSON response received:', res.body) // Log the unexpected body
reject(new Error('Expected JSON response but received content-type: ' + contentType))
}
} catch (error) {
// Handle JSON parsing errors
reject(new Error('Failed to parse JSON response: ' + error.message))
}
})
.catch(error => reject(error))
Expand Down
72 changes: 70 additions & 2 deletions 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 @@ -31,11 +35,54 @@ exports.optional = ['jar']
exports.func = function (args) {
const max = settings.event.maxRetries
const notifications = new events.EventEmitter()
function connect (retries) {

async function connect (retries) {
if (typeof args.jar === 'string') {
args.jar = { session: args.jar }
}
const session = getSession({ jar: args.jar })
<<<<<<< HEAD
const headers = {
Cookie: '.ROBLOSECURITY=' + session + ';'
// Add other headers if needed
}

let client
try {
client = new HubConnectionBuilder()
.withUrl('https://realtime-signalr.roblox.com/userhub', {
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
headers: headers
})
.build()
} catch (err) {
console.error('Error creating HubConnection:', err)
throw err
}

if (!client) {
console.error('Failed to create HubConnection')
return
}

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

notifications.on('close', async function (err) {
try {
client.stop()
console.error('Connection closed:', err)
} catch (err) {
console.error('Error while closing connection:', err)
}
})

client.serviceHandlers = client.serviceHandlers || {}
client.serviceHandlers.connectFailed = function (err) {
console.error('Connection failed:', err)
=======
let userNotificationConnection = null

userNotificationConnection = new signalR.HubConnectionBuilder()
Expand All @@ -55,32 +102,53 @@ exports.func = function (args) {
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) {
notifications.emit('close', new Error('Max retries reached'))
} else {
setTimeout(connect, 5000, retries + 1)
setTimeout(() => connect(retries + 1), 5000)
}
}
}
<<<<<<< HEAD
client.serviceHandlers.onerror = function (err) {
console.error('Connection error:', err)
=======

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

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)
return notifications
}
34 changes: 20 additions & 14 deletions lib/friends/acceptFriendRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getGeneralToken = require('../util/getGeneralToken.js').func

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

// Docs
/**
Expand All @@ -16,13 +16,13 @@ exports.optional = ['jar']
* @example const noblox = require("noblox.js")
* // Login using your cookie
* noblox.acceptFriendRequest(123456)
**/
**/

// Define
function acceptFriendRequest (jar, token, userId) {
function acceptFriendRequest (jar, token, userId, apiUrl) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//friends.roblox.com/v1/users/${userId}/accept-friend-request`,
url: `//${apiUrl}/v1/users/${userId}/accept-friend-request`,
options: {
method: 'POST',
jar,
Expand All @@ -33,27 +33,33 @@ function acceptFriendRequest (jar, token, userId) {
resolveWithFullResponse: true
}
}
return http(httpOpt)
.then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
return http(httpOpt).then(function (res) {
if (res.statusCode === 200) {
resolve()
} else {
try {
const body = JSON.parse(res.body) || {}
if (body.errors && body.errors.length > 0) {
const errors = body.errors.map((e) => {
return e.message
})
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
}
} catch (err) {
reject(new Error(`${res.statusCode} ${res.body}`))
}
})
}
})
})
}

exports.func = function (args) {
const jar = args.jar
return getGeneralToken({ jar })
.then(function (xcsrf) {
return acceptFriendRequest(jar, xcsrf, args.userId)
})
return getGeneralToken({ jar }).then(function (xcsrf) {
let apiUrl = 'friends.roblox.com'
if (args.apiUrl) {
apiUrl = args.apiUrl
}
return acceptFriendRequest(jar, xcsrf, args.userId, apiUrl)
})
}
2 changes: 1 addition & 1 deletion lib/friends/declineAllFriendRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports.optional = ['jar']
function declineAllFriendRequests (jar, token) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: '//friends.roblox.com/v1/user/friend-requests/decline-all',
url: '//friends.roproxy.com/v1/user/friend-requests/decline-all',
options: {
method: 'POST',
jar,
Expand Down
Loading
Loading