From b4a7461f9ed95acf8a69c02eb995b659fa987083 Mon Sep 17 00:00:00 2001 From: Leastrio <60587129+Leastrio@users.noreply.github.com> Date: Tue, 7 May 2024 00:58:25 -0600 Subject: [PATCH] add top n guilds to qlc cheatsheet --- guides/cheat-sheets/qlc.cheatmd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/guides/cheat-sheets/qlc.cheatmd b/guides/cheat-sheets/qlc.cheatmd index 239332f72..1dea50643 100644 --- a/guides/cheat-sheets/qlc.cheatmd +++ b/guides/cheat-sheets/qlc.cheatmd @@ -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 }