Search in sources :

Example 1 with MemberCacheView

use of net.dv8tion.jda.core.utils.cache.MemberCacheView in project SkyBot by duncte123.

the class GuildUtils method getBotAndUserCount.

/**
 * Returns an array with the member counts of the guild
 * 0 = the total users
 * 1 = the total bots
 * 3 = the total members
 *
 * @param g The {@link Guild Guild} to count the users in
 * @return an array with the member counts of the guild
 */
public static long[] getBotAndUserCount(Guild g) {
    MemberCacheView memberCache = g.getMemberCache();
    long totalCount = memberCache.size();
    long botCount = memberCache.stream().filter(it -> it.getUser().isBot()).count();
    long userCount = totalCount - botCount;
    return new long[] { userCount, botCount, totalCount };
}
Also used : MemberCacheView(net.dv8tion.jda.core.utils.cache.MemberCacheView) Logger(org.slf4j.Logger) Member(net.dv8tion.jda.core.entities.Member) ComparatingUtils(ml.duncte123.skybot.unstable.utils.ComparatingUtils) TextChannel(net.dv8tion.jda.core.entities.TextChannel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Settings(ml.duncte123.skybot.Settings) MemberCacheView(net.dv8tion.jda.core.utils.cache.MemberCacheView) Objects(java.util.Objects) Guild(net.dv8tion.jda.core.entities.Guild) AtomicLong(java.util.concurrent.atomic.AtomicLong) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Permission(net.dv8tion.jda.core.Permission) Map(java.util.Map) JDA(net.dv8tion.jda.core.JDA)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Settings (ml.duncte123.skybot.Settings)1 ComparatingUtils (ml.duncte123.skybot.unstable.utils.ComparatingUtils)1 JDA (net.dv8tion.jda.core.JDA)1 Permission (net.dv8tion.jda.core.Permission)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Member (net.dv8tion.jda.core.entities.Member)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 MemberCacheView (net.dv8tion.jda.core.utils.cache.MemberCacheView)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1