From 3e22c23e05e8cc9b52b88212835c09562f8525b2 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Sun, 15 Sep 2024 07:42:53 +0000 Subject: [PATCH 1/9] Create searchUsers method --- lib/index.js | 1 + lib/users/searchUsers.js | 41 ++++++++++++++++++++++++++++++++++++++++ test/users.test.js | 20 +++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lib/users/searchUsers.js diff --git a/lib/index.js b/lib/index.js index bd6063b3a..431ce54a4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -169,6 +169,7 @@ noblox.getIdFromUsername = require('./users/getIdFromUsername.js') noblox.getPlayerInfo = require('./users/getPlayerInfo.js') noblox.getUsernameFromId = require('./users/getUsernameFromId.js') noblox.onBlurbChange = require('./users/onBlurbChange.js') +noblox.searchUsers = require('./users/searchUsers.js') noblox.clearSession = require('./util/clearSession.js') noblox.generalRequest = require('./util/generalRequest.js') noblox.getAction = require('./util/getAction.js') diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js new file mode 100644 index 000000000..d5341d6fe --- /dev/null +++ b/lib/users/searchUsers.js @@ -0,0 +1,41 @@ +// Includes +const getPageResults = require('../util/getPageResults.js').func + +// Args +exports.required = ['keyword'] +exports.optional = ['limit', 'cursor'] + +// Docs +/** + * ✅ Gets a list of users matching the keyword + * @category User + * @alias searchUsers + * @param {string} keyword - The search term to use + * @param {10 | 25 | 50 | 100} limit - The maximum number of matching users to return + * @param {string} cursor - The cursor to use when fetching the next or previous page + * @example const noblox = require("noblox.js") + * // Log in using cookie + * await noblox.searchUsers("bob", 10, "eyblahblahblahblah") +**/ + +// Define +function searchUsers(jar, keyword, limit, cursor) { + return getPageResults({ + url: '//users.roblox.com/v1/users/search', + jar, + limit, + pageCursor: cursor, + query: { + keyword + } + }) +} + +exports.func = function (args) { + return searchUsers( + args.jar, + args.keyword, + args.limit ?? 10, + args.cursor + ) +} diff --git a/test/users.test.js b/test/users.test.js index 8d9be36cc..3150a3666 100644 --- a/test/users.test.js +++ b/test/users.test.js @@ -1,5 +1,6 @@ -const { getBlurb, getIdFromUsername, getPlayerInfo, getUsernameFromId, setCookie } = require('../lib') +const { getBlurb, getIdFromUsername, getPlayerInfo, getUsernameFromId, searchUsers, setCookie } = require('../lib') +/** beforeAll(() => { return new Promise(resolve => { setCookie(process.env.COOKIE).then(() => { @@ -7,6 +8,7 @@ beforeAll(() => { }) }) }) + */ describe('Users Methods', () => { it('getBlurb() returns a user\'s blurb', () => { @@ -65,4 +67,20 @@ describe('Users Methods', () => { return expect(res).toEqual(expect.any(String)) }) }) + + it('searchUsers() returns results for the specified keyword', () => { + return searchUsers('roblox').then((res) => { + return expect(res).toMatchObject( + expect.arrayContaining([ + expect.objectContaining({ + previousUsernames: expect.any(Array), + hasVerifiedBadge: expect.any(Boolean), + id: expect.any(Number), + name: expect.any(String), + displayName: expect.any(String) + }) + ]) + ) + }) + }) }) From dd22c7b08bdf5702b37a83211b765d131e9769b0 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Sun, 15 Sep 2024 07:50:03 +0000 Subject: [PATCH 2/9] Add UserSearchResult type --- lib/users/searchUsers.js | 1 + typings/index.d.ts | 8 ++++++++ typings/jsDocs.ts | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index d5341d6fe..57ee1a571 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -13,6 +13,7 @@ exports.optional = ['limit', 'cursor'] * @param {string} keyword - The search term to use * @param {10 | 25 | 50 | 100} limit - The maximum number of matching users to return * @param {string} cursor - The cursor to use when fetching the next or previous page + * @returns {Promise} * @example const noblox = require("noblox.js") * // Log in using cookie * await noblox.searchUsers("bob", 10, "eyblahblahblahblah") diff --git a/typings/index.d.ts b/typings/index.d.ts index 5f12970f8..e62f78cea 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1162,6 +1162,14 @@ declare module "noblox.js" { guilded?: string; } + interface UserSearchResult { + previousUsernames: string[]; + hasVerifiedBadge: boolean; + id: number; + name: string; + displayName: string; + } + /// Badges interface BadgeAwarder { diff --git a/typings/jsDocs.ts b/typings/jsDocs.ts index 6a85a8a3a..25d38ec33 100644 --- a/typings/jsDocs.ts +++ b/typings/jsDocs.ts @@ -1603,6 +1603,14 @@ type PromotionChannelsResponse = { guilded?: string; } +type UserSearchResult = { + previousUsernames: string[]; + hasVerifiedBadge: boolean; + id: number; + name: string; + displayName: string; +} + /// Badges /** From ab6ba2bc4c3f0b6ae61a9069a5e3a9c16d20d225 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Sun, 15 Sep 2024 03:54:13 -0400 Subject: [PATCH 3/9] oops lol --- test/users.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/users.test.js b/test/users.test.js index 3150a3666..8f78ad0c2 100644 --- a/test/users.test.js +++ b/test/users.test.js @@ -1,6 +1,5 @@ const { getBlurb, getIdFromUsername, getPlayerInfo, getUsernameFromId, searchUsers, setCookie } = require('../lib') -/** beforeAll(() => { return new Promise(resolve => { setCookie(process.env.COOKIE).then(() => { @@ -8,7 +7,6 @@ beforeAll(() => { }) }) }) - */ describe('Users Methods', () => { it('getBlurb() returns a user\'s blurb', () => { From 6cb2dd4e5f400010bfc9a6267b264a6253781b4d Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Sun, 15 Sep 2024 08:00:40 +0000 Subject: [PATCH 4/9] lint --- lib/users/searchUsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index 57ee1a571..da1d16a23 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -20,7 +20,7 @@ exports.optional = ['limit', 'cursor'] **/ // Define -function searchUsers(jar, keyword, limit, cursor) { +function searchUsers (jar, keyword, limit, cursor) { return getPageResults({ url: '//users.roblox.com/v1/users/search', jar, From 5b1407eb5c2eb1bcaf600e97b25cd346bbf322fe Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:34:02 -0400 Subject: [PATCH 5/9] Update docs example --- lib/users/searchUsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index da1d16a23..cb20af8f9 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -16,7 +16,7 @@ exports.optional = ['limit', 'cursor'] * @returns {Promise} * @example const noblox = require("noblox.js") * // Log in using cookie - * await noblox.searchUsers("bob", 10, "eyblahblahblahblah") + * await noblox.searchUsers({ keyword: "bob", limit: 10, cursor: "eyblahblahblahblah" }) **/ // Define From c00e8475166db90c5056ab531c8fb95739401012 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:25:46 -0400 Subject: [PATCH 6/9] Add searchUsers function type --- typings/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index e62f78cea..d39a4eac7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2177,6 +2177,11 @@ declare module "noblox.js" { */ function getUsernameFromId(id: number): Promise; + /** + * ✅ Gets user search results for a keyword. + */ + function searchUsers(keyword: string, limit: number, cursor: string): Promise; + /// Utility /** From ef0a4dae190114ee73e47da2f05d5a1c181b051a Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:34:05 -0400 Subject: [PATCH 7/9] Update docs example again --- lib/users/searchUsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index cb20af8f9..38fd5b19c 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -16,7 +16,7 @@ exports.optional = ['limit', 'cursor'] * @returns {Promise} * @example const noblox = require("noblox.js") * // Log in using cookie - * await noblox.searchUsers({ keyword: "bob", limit: 10, cursor: "eyblahblahblahblah" }) + * await noblox.searchUsers("bob", 10, "cursorstring") **/ // Define From e4011bc393eecdadeef4dca04cb3d4cfb5cebf4e Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:56:52 -0400 Subject: [PATCH 8/9] Add jar param to optional params export --- lib/users/searchUsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index 38fd5b19c..dcdf6e5b1 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -3,7 +3,7 @@ const getPageResults = require('../util/getPageResults.js').func // Args exports.required = ['keyword'] -exports.optional = ['limit', 'cursor'] +exports.optional = ['limit', 'cursor', 'jar'] // Docs /** From b03ad55c501d86c897aee07820b9a9f665aaf20b Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:02:01 -0400 Subject: [PATCH 9/9] Update docs example yet again --- lib/users/searchUsers.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/users/searchUsers.js b/lib/users/searchUsers.js index dcdf6e5b1..fed4540f7 100644 --- a/lib/users/searchUsers.js +++ b/lib/users/searchUsers.js @@ -15,8 +15,7 @@ exports.optional = ['limit', 'cursor', 'jar'] * @param {string} cursor - The cursor to use when fetching the next or previous page * @returns {Promise} * @example const noblox = require("noblox.js") - * // Log in using cookie - * await noblox.searchUsers("bob", 10, "cursorstring") + * noblox.searchUsers("bob", 10, "cursorstring") **/ // Define