Skip to content

Commit

Permalink
Merge pull request #586 from Leastrio/patch-1
Browse files Browse the repository at this point in the history
add top n guilds to qlc cheatsheet
  • Loading branch information
jb3 authored May 7, 2024
2 parents de4f9e2 + b4a7461 commit 5f1ce30
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions guides/cheat-sheets/qlc.cheatmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ find_online_users(RequestedGuildId, PresenceCache, UserCache) ->

This depends on the guild presences intent being enabled and the bot storing received presences in the presence cache.

### Getting the largest N guilds

```erl
top_guilds(N, GuildCache) ->
Q = qlc:q([{MemberCount, Guild} || {_Id, #{member_count := MemberCount} = Guild} <- GuildCache:query_handle()]),
Q2 = qlc:keysort(1, Q, [{order, descending}]),
GuildCache:wrap_qlc(fun () ->
C = qlc:cursor(Q2),
R = qlc:next_answers(C, N),
ok = qlc:delete_cursor(C),
R
end).
```

## Debugging QLC

{: .col-2 }
Expand Down

0 comments on commit 5f1ce30

Please # to comment.