Skip to content

Commit 8e4a6c1

Browse files
committed
Added in voicechannel and hides flags now when there are none
If the member isn't in VC, it won't show the `in voicechannel` property at all. This way it only shows info that actually matters, making it easier to read. This change has also been done to the `flags` property.
1 parent 73453e9 commit 8e4a6c1

File tree

1 file changed

+26
-8
lines changed
  • application/src/main/java/org/togetherjava/tjbot/commands/moderation

1 file changed

+26
-8
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/moderation/WhoIsCommand.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.togetherjava.tjbot.commands.moderation;
22

33
import net.dv8tion.jda.api.EmbedBuilder;
4+
import net.dv8tion.jda.api.entities.GuildVoiceState;
45
import net.dv8tion.jda.api.entities.Member;
56
import net.dv8tion.jda.api.entities.Role;
67
import net.dv8tion.jda.api.entities.User;
@@ -95,6 +96,7 @@ public void onSlashCommand(@NotNull final SlashCommandEvent event) {
9596

9697
StringBuilder descriptionBuilder =
9798
new StringBuilder().append(handleUserIdentification(user))
99+
.append(handleVoiceState(member))
98100
.append("\n**Is bot:** ")
99101
.append(user.isBot())
100102
.append(handlePossibleBooster(member))
@@ -118,6 +120,16 @@ public void onSlashCommand(@NotNull final SlashCommandEvent event) {
118120
"Click to see profile"));
119121
}
120122

123+
private static @NotNull String handleVoiceState(@NotNull final Member member) {
124+
GuildVoiceState voiceState = Objects.requireNonNull(member.getVoiceState(),
125+
"The given voiceState cannot be null");
126+
if (voiceState.inVoiceChannel()) {
127+
return "\n**In voicechannel:** " + (voiceState.getChannel().getAsMention());
128+
} else {
129+
return "";
130+
}
131+
}
132+
121133

122134
/**
123135
* Generates whois embed based on the given parameters.
@@ -141,7 +153,7 @@ public void onSlashCommand(@NotNull final SlashCommandEvent event) {
141153

142154
/**
143155
* Handles boosting properties of a {@link Member}
144-
*
156+
*
145157
* @param member the {@link Member} to take the booster properties from
146158
* @return user readable {@link String}
147159
*/
@@ -157,7 +169,7 @@ public void onSlashCommand(@NotNull final SlashCommandEvent event) {
157169

158170
/**
159171
* Handles the user's identifying properties (such as ID, tag)
160-
*
172+
*
161173
* @param user the {@link User} to take the identifiers from
162174
* @return user readable {@link StringBuilder}
163175
*/
@@ -171,7 +183,7 @@ public void onSlashCommand(@NotNull final SlashCommandEvent event) {
171183

172184
/**
173185
* Formats the roles into a user readable {@link String}
174-
*
186+
*
175187
* @param member member to take the Roles from
176188
* @return user readable {@link String} of the roles
177189
*/
@@ -181,26 +193,32 @@ private static String formatRoles(final @NotNull Member member) {
181193

182194
/**
183195
* Formats Hypesquad and the flags
184-
*
196+
*
185197
* @param flags the {@link Collection} of {@link net.dv8tion.jda.api.entities.User.UserFlag}
186198
* (recommend {@link java.util.EnumSet}
187199
* @return user readable {@link StringBuilder}
188200
*/
189201
private static @NotNull StringBuilder handleUserFlags(
190202
final @NotNull Collection<User.UserFlag> flags) {
191-
return formatHypesquad(flags).append("\n**Flags:** ").append(formatUserFlags(flags));
203+
String formattedFlags = formatUserFlags(flags);
204+
205+
if (formattedFlags.isBlank()) {
206+
return formatHypesquad(flags);
207+
} else {
208+
return formatHypesquad(flags).append("\n**Flags:** ").append(formatUserFlags(flags));
209+
}
192210
}
193211

194212
/**
195213
* Formats user readable Hypesquad item
196-
*
214+
*
197215
* @param flags the {@link Collection} of {@link net.dv8tion.jda.api.entities.User.UserFlag}
198216
* (recommend {@link java.util.EnumSet}
199217
* @return user readable {@link StringBuilder}
200218
*/
201219
private static @NotNull StringBuilder formatHypesquad(
202220
final @NotNull Collection<User.UserFlag> flags) {
203-
StringBuilder stringBuilder = new StringBuilder("**Hypesquad:** ");
221+
StringBuilder stringBuilder = new StringBuilder("**\nHypesquad:** ");
204222

205223
if (flags.contains(User.UserFlag.HYPESQUAD_BALANCE)) {
206224
stringBuilder.append(User.UserFlag.HYPESQUAD_BALANCE.getName());
@@ -217,7 +235,7 @@ private static String formatRoles(final @NotNull Member member) {
217235

218236
/**
219237
* Formats the flags into a user readable {@link String}, filters Hypesquad relating flags
220-
*
238+
*
221239
* @param flags the {@link Collection} of {@link net.dv8tion.jda.api.entities.User.UserFlag}
222240
* (recommend {@link java.util.EnumSet}
223241
* @return the user readable string

0 commit comments

Comments
 (0)