forked from Fascinated/Bat
update member count command
This commit is contained in:
parent
4821e2a4fa
commit
df44ae90b9
@ -15,6 +15,14 @@ public class Emojis {
|
||||
public static final Emoji CROSS_MARK_EMOJI;
|
||||
public static final Emoji SAD_FACE_EMOJI;
|
||||
|
||||
/**
|
||||
* Presence Status Emojis
|
||||
*/
|
||||
public static final Emoji ONLINE_EMOJI;
|
||||
public static final Emoji IDLE_EMOJI;
|
||||
public static final Emoji DND_EMOJI;
|
||||
public static final Emoji OFFLINE_EMOJI;
|
||||
|
||||
static {
|
||||
log.info("Loading emojis...");
|
||||
JDA jda = DiscordService.JDA;
|
||||
@ -22,6 +30,10 @@ public class Emojis {
|
||||
CHECK_MARK_EMOJI = jda.getEmojiById("1256633734065557676");
|
||||
CROSS_MARK_EMOJI = jda.getEmojiById("1256634487429922897");
|
||||
SAD_FACE_EMOJI = jda.getEmojiById("1256636078258131055");
|
||||
ONLINE_EMOJI = jda.getEmojiById("1256662465668710430");
|
||||
IDLE_EMOJI = jda.getEmojiById("1256662632203685991");
|
||||
DND_EMOJI = jda.getEmojiById("1256662572933845032");
|
||||
OFFLINE_EMOJI = jda.getEmojiById("1256662679402053662");
|
||||
log.info("Loaded emojis!");
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,24 @@
|
||||
package cc.fascinated.bat.command.impl.server;
|
||||
|
||||
import cc.fascinated.bat.Emojis;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.NumberUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@ -23,7 +29,40 @@ public class MemberCountCommand extends BatCommand {
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
||||
EmbedBuilder embed = EmbedUtils.genericEmbed().setAuthor("Member Count");
|
||||
Guild discordGuild = guild.getDiscordGuild();
|
||||
embed.setDescription("**%s** has a total of %s members.".formatted(discordGuild.getName(), discordGuild.getMembers().size()));
|
||||
int totalMembers = 0, totalUsers = 0, totalBots = 0;
|
||||
Map<OnlineStatus, Integer> memberCounts = new HashMap<>();
|
||||
for (Member guildMember : discordGuild.getMembers()) {
|
||||
OnlineStatus status = guildMember.getOnlineStatus();
|
||||
memberCounts.put(status, memberCounts.getOrDefault(status, 0) + 1);
|
||||
|
||||
if (guildMember.getUser().isBot()) {
|
||||
totalBots++;
|
||||
} else {
|
||||
totalUsers++;
|
||||
}
|
||||
totalMembers++;
|
||||
}
|
||||
|
||||
embed.setDescription("""
|
||||
Total Members: `%s`
|
||||
Total Users: `%s`
|
||||
Total Bots: `%s`
|
||||
\s
|
||||
%s Online: `%s`
|
||||
%s Idle: `%s`
|
||||
%s Do Not Disturb: `%s`
|
||||
%s Offline: `%s`""".formatted(
|
||||
NumberUtils.formatNumberCommas(totalMembers),
|
||||
NumberUtils.formatNumberCommas(totalUsers),
|
||||
NumberUtils.formatNumberCommas(totalBots),
|
||||
Emojis.ONLINE_EMOJI,
|
||||
NumberUtils.formatNumberCommas(memberCounts.getOrDefault(OnlineStatus.ONLINE, 0)),
|
||||
Emojis.IDLE_EMOJI,
|
||||
NumberUtils.formatNumberCommas(memberCounts.getOrDefault(OnlineStatus.IDLE, 0)),
|
||||
Emojis.DND_EMOJI,
|
||||
NumberUtils.formatNumberCommas(memberCounts.getOrDefault(OnlineStatus.DO_NOT_DISTURB, 0)),
|
||||
Emojis.OFFLINE_EMOJI,
|
||||
NumberUtils.formatNumberCommas(memberCounts.getOrDefault(OnlineStatus.OFFLINE, 0))));
|
||||
interaction.replyEmbeds(embed.build()).queue();
|
||||
}
|
||||
}
|
@ -47,8 +47,8 @@ public class PauseSubCommand extends BatSubCommand {
|
||||
|
||||
boolean didPause = spotifyService.pausePlayback(user);
|
||||
interaction.replyEmbeds(EmbedUtils.successEmbed()
|
||||
.setDescription(didPause ? ":pause_button: Paused the current track.".formatted(Emojis.CHECK_MARK_EMOJI) :
|
||||
"%s The current track is already paused.".formatted(Emojis.CROSS_MARK_EMOJI))
|
||||
.setDescription(didPause ? ":pause_button: Paused the current track."
|
||||
: "%s The current track is already paused.".formatted(Emojis.CROSS_MARK_EMOJI))
|
||||
.build())
|
||||
.queue();
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ public class DiscordService {
|
||||
GatewayIntent.GUILD_MESSAGES,
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.GUILD_MEMBERS,
|
||||
GatewayIntent.GUILD_EMOJIS_AND_STICKERS
|
||||
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
|
||||
GatewayIntent.GUILD_PRESENCES
|
||||
))
|
||||
.disableCache(
|
||||
CacheFlag.ACTIVITY,
|
||||
CacheFlag.VOICE_STATE,
|
||||
CacheFlag.CLIENT_STATUS,
|
||||
CacheFlag.ONLINE_STATUS,
|
||||
CacheFlag.SCHEDULED_EVENTS
|
||||
).build()
|
||||
.awaitReady();
|
||||
|
Loading…
Reference in New Issue
Block a user