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

Please add user search feature with this code #15

Open
factoryal opened this issue Oct 24, 2019 · 2 comments
Open

Please add user search feature with this code #15

factoryal opened this issue Oct 24, 2019 · 2 comments

Comments

@factoryal
Copy link

Hi.
Thanks for this npm package.
I found this on virtual market 3 and trying some examples works very well.. Great!!
VRChat_1920x1080_2019-09-21_22-42-44 425

Anyway, for my application, I need to search user by keyword.. (some part of name or etc.)
there was not in this api.

But try this!
I added some code to do that.
On node_modules/vrchat-client/dist/modules/user.js

async searchUser(keyword, n) {
    return await this.getReq(`/users?search=${encodeURI(keyword)}&n=${n.toString()}`);
}

this could work well.
keyword is search keyword.
n is number of search results from server.
the function returns user info by array.
so you can access searched users by indexing like data[0], data[1], ...

This is Typescript version but I cannot tested and I don't know syntaxes all right.

async searchUser(keyword: string, n: number): Promise<UserResponse> {
    return await this.getReq(`/users?search=${encodeURI(keyword)}&n=${n.toString()}`);  
} 

Please test this code and update to next version.
Thanks!

@neverclear86 neverclear86 added enhancement New feature or request and removed enhancement New feature or request labels Oct 28, 2019
@neverclear86
Copy link
Contributor

Hi.
Thanks for using this!

Anyway, for my application, I need to search user by keyword.. (some part of name or etc.)

Can you do that with this code?

api.user.search.all({
  search: 'keyword',
  n: 1,
  offset: 1,
})

Thanks.

@factoryal
Copy link
Author

oh, that GET request form works like that.
but anyway, like another methods, I think simplified usage form needed for code simpler.

would you add this feature for next commit?

async searchUser(keyword, n=12, offset=1) {
    return await this.getReq(`/users?search=${encodeURI(keyword)}&n=${n.toString()}`);
}

on readme.md

  • Search User
    This methods returns array of users.
    keyword: The keyword to search
    n: VRChat API will return top n results. (default: 12)
    offset: VRChat API will return next top n results. The next top means offset×n index. (default: 1)
api.user.searchUser(keyword);
api.user.searchUser(keyword, n);
api.user.searchUser(keyword, n, offset);

You can also make this request manually with this method.

api.user.search.all({
  search: 'keyword',
  n: 1,
  offset: 1,
})

This is.... just my comment.
Please review and test... and.....
Thanks for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants