-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
State documentation uses outdated example for user discriminator query #552
Comments
I'm not sure what you mean by an inactive user here, but if you can clarify I can try answer. I suggest we just swap out the query for something else that demonstrates more advanced state/QLC usage for cache querying, querying by just username does not feel like a great example, let's at least look for more fields. I think we can show some more example uses, just a few off the top of my head (though I have tested them, and they do work), let me know what you think of these (they may also be a totally wrong approach to writing QLC queries, let me know if that is the case also): -module(nostrum_queries).
-export([find_role_users/4, find_large_communities/2]).
-include_lib("stdlib/include/qlc.hrl").
% Find the Nostrum.Struct.User and Member objects of all members in a specific guild role.
find_role_users(RequestedGuildId, RoleId, MemberCache, UserCache) ->
qlc:q([{User, Member} || {{GuildId, MemberId}, Member} <- MemberCache:query_handle(),
% Filter to member objects of the selected guild
GuildId =:= RequestedGuildId,
% Filter to members of the provided role
lists:member(RoleId, map_get(roles, Member)),
% Get a handle on the UserCache table
{UserId, User} <- UserCache:query_handle(),
% Find the User struct that matches the found Member
MemberId =:= UserId]).
% Find all communities in the Guild cache with the COMMUNITY guild feature
% that are over a certain threshold in user size
find_large_communities(Threshold, GuildCache) ->
qlc:q([Guild || {_, Guild} <- GuildCache:query_handle(),
% Filter for guilds that are over the provided size
map_get(member_count, Guild) > Threshold,
% Filter for guilds that have COMMUNITY in the features field
lists:member(<<"COMMUNITY">>, map_get(features, Guild))]).
(Related, QLC cheatsheet for #553?) |
I like this idea and also the idea of a QLC cheatsheet, as far as I'm aware the queries above won't work as-is since the QLC compiler expects guard tests to be passed in the list comprehension, so a |
Discussion in Discord shows that we can use |
Updates state docs with the previously agreed upon QLC examples in issue Additionally, provides an example of how to evaluate a QLC query and return the result to use within Elixir. Closes #552
Updates state docs with the previously agreed upon QLC examples in issue Additionally, provides an example of how to evaluate a QLC query and return the result to use within Elixir. Closes #552
As brought up by @jb3, the state documentation currently mentions an example of
querying users within nosedrum by matching via username and discriminator,
whilst discriminator for active user accounts are no longer in use. This might
have to be fixed in nosedrum itself, but in the meantime we could update the
documentation to use the username attribute only as it is supposed to be unique
for user accounts these days. A question for @jb3 here, could the query return
multiple users then, if you query for, for instance, an inactive user?
The text was updated successfully, but these errors were encountered: