[FEAT] Allow disabling nickname updates on linking and allow custom nickname formats

This commit is contained in:
2023-08-05 18:43:13 +02:00
parent 95e1dfac70
commit b901609957
3 changed files with 26 additions and 13 deletions

View File

@@ -131,7 +131,7 @@ public class MinecraftAccount {
try { try {
sdlinkDatabase.upsert(account); sdlinkDatabase.upsert(account);
String suffix = " [MC: " + this.username + "]"; String suffix = this.username;
int availableChars = 32 - suffix.length(); int availableChars = 32 - suffix.length();
String nickname = member.getEffectiveName(); String nickname = member.getEffectiveName();
@@ -139,21 +139,23 @@ public class MinecraftAccount {
nickname = nickname.substring(0, availableChars - 3) + "..."; nickname = nickname.substring(0, availableChars - 3) + "...";
} }
nickname += suffix; String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix);
try {
member.modifyNickname(nickname).queue();
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
try { try {
if (RoleManager.getLinkedRole() != null) { member.modifyNickname(finalnickname).queue();
guild.addRoleToMember(UserSnowflake.fromId(member.getId()), RoleManager.getLinkedRole()).queue();
try {
if (RoleManager.getLinkedRole() != null) {
guild.addRoleToMember(UserSnowflake.fromId(member.getId()), RoleManager.getLinkedRole()).queue();
}
} catch (Exception e) {
e.printStackTrace();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); if (SDLinkConfig.INSTANCE.generalConfig.debugging) {
} e.printStackTrace();
} catch (Exception e) { }
if (SDLinkConfig.INSTANCE.generalConfig.debugging) {
e.printStackTrace();
} }
} }

View File

@@ -33,6 +33,14 @@ public class LinkAndWhitelistConfigSettings {
@Path("requireLinking") @Path("requireLinking")
@SpecComment("Require users to link their Discord and Minecraft accounts before joining the server") @SpecComment("Require users to link their Discord and Minecraft accounts before joining the server")
public boolean requireLinking = false; public boolean requireLinking = false;
@Path("changeNickname")
@SpecComment("Allow nickname changes on account linking")
public boolean changeNickname = true;
@Path("nicknameFormat")
@SpecComment("The nickname format to use for linked accounts, when changeNickname is enabled. %nick% for current nickname/name and %mcname% for the minecraft name")
public String nicknameFormat = "%nick% [MC:%mcname%]";
} }
public static class Whitelisting { public static class Whitelisting {

View File

@@ -28,7 +28,6 @@ public class PermissionChecker {
// Base Permissions required by the bot to operate // Base Permissions required by the bot to operate
private static final List<Permission> BOT_PERMS = new ArrayList<>() {{ private static final List<Permission> BOT_PERMS = new ArrayList<>() {{
add(Permission.NICKNAME_CHANGE); add(Permission.NICKNAME_CHANGE);
add(Permission.NICKNAME_MANAGE);
add(Permission.MANAGE_WEBHOOKS); add(Permission.MANAGE_WEBHOOKS);
add(Permission.MESSAGE_SEND); add(Permission.MESSAGE_SEND);
add(Permission.MESSAGE_EMBED_LINKS); add(Permission.MESSAGE_EMBED_LINKS);
@@ -50,6 +49,10 @@ public class PermissionChecker {
* Run the permission checker to see if the bot has all the required permissions * Run the permission checker to see if the bot has all the required permissions
*/ */
public static void checkBotSetup() { public static void checkBotSetup() {
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
BOT_PERMS.add(Permission.NICKNAME_MANAGE);
}
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("\r\n").append("******************* Simple Discord Link Errors *******************").append("\r\n"); builder.append("\r\n").append("******************* Simple Discord Link Errors *******************").append("\r\n");
AtomicInteger errCount = new AtomicInteger(); AtomicInteger errCount = new AtomicInteger();