Skip to content

Commit

Permalink
Add Optional User to /codemc unklink
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 authored Nov 10, 2024
1 parent ed06cd2 commit a7e178f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/io/codemc/bot/commands/CmdCodeMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ public Unlink(CodeMCBot bot) {
this.allowedRoles = bot.getConfigHandler().getLongList("allowed_roles", "commands", "codemc");

this.options = List.of(
new OptionData(OptionType.USER, "discord", "The discord user to unlink.").setRequired(true)
new OptionData(OptionType.USER, "discord", "The discord user to unlink.").setRequired(true),
new OptionData(OptionType.STRING, "username", "The Jenkins user to unlink from. Use if the discord user is linked to multiple accounts.").setRequired(false)
);
}

Expand All @@ -415,6 +416,7 @@ public void withModalReply(SlashCommandEvent event) {}
@Override
public void withHookReply(InteractionHook hook, SlashCommandEvent event, Guild guild, Member member) {
Member target = event.getOption("discord", null, OptionMapping::getAsMember);
String userTarget = event.getOption("username", null, OptionMapping::getAsString);

if (target == null) {
CommandUtil.EmbedReply.from(hook).error("Invalid Discord User provided!").send();
Expand All @@ -424,6 +426,7 @@ public void withHookReply(InteractionHook hook, SlashCommandEvent event, Guild g
String username = DatabaseAPI.getAllUsers().stream()
.filter(user -> user.getDiscord() == target.getIdLong())
.map(User::getUsername)
.filter(user -> userTarget == null || user.equals(userTarget))
.findFirst()
.orElse(null);

Expand Down

0 comments on commit a7e178f

Please sign in to comment.