forked from Fascinated/Bat
a lil cleanup and add role perms when adding and removing a role to the log
This commit is contained in:
parent
313f43172d
commit
75da7a4b51
@ -2,6 +2,7 @@ package cc.fascinated.bat.common;
|
|||||||
|
|
||||||
import cc.fascinated.bat.model.BatGuild;
|
import cc.fascinated.bat.model.BatGuild;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
|
||||||
@ -21,4 +22,18 @@ public class RoleUtils {
|
|||||||
public static boolean hasPermissionToGiveRole(BatGuild guild, Member member, Role role) {
|
public static boolean hasPermissionToGiveRole(BatGuild guild, Member member, Role role) {
|
||||||
return member.getRoles().stream().anyMatch(r -> r.getPosition() > role.getPosition());
|
return member.getRoles().stream().anyMatch(r -> r.getPosition() > role.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the formatted permissions of a role
|
||||||
|
*
|
||||||
|
* @param role the role to get the formatted permissions of
|
||||||
|
* @return the formatted permissions
|
||||||
|
*/
|
||||||
|
public String getFormattedPermissions(Role role) {
|
||||||
|
StringBuilder formattedPermissions = new StringBuilder();
|
||||||
|
for (Permission permission : role.getPermissions()) {
|
||||||
|
formattedPermissions.append("`").append(permission.getName()).append("`, ");
|
||||||
|
}
|
||||||
|
return formattedPermissions.substring(0, formattedPermissions.length() - 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cc.fascinated.bat.features.logging.listeners;
|
|||||||
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
|
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
|
||||||
import cc.fascinated.bat.common.EmbedUtils;
|
import cc.fascinated.bat.common.EmbedUtils;
|
||||||
import cc.fascinated.bat.common.HexColorUtils;
|
import cc.fascinated.bat.common.HexColorUtils;
|
||||||
|
import cc.fascinated.bat.common.RoleUtils;
|
||||||
import cc.fascinated.bat.event.EventListener;
|
import cc.fascinated.bat.event.EventListener;
|
||||||
import cc.fascinated.bat.features.logging.LogFeature;
|
import cc.fascinated.bat.features.logging.LogFeature;
|
||||||
import cc.fascinated.bat.features.logging.LogType;
|
import cc.fascinated.bat.features.logging.LogType;
|
||||||
@ -71,26 +72,28 @@ public class RoleListener implements EventListener {
|
|||||||
public void onRoleCreate(@NonNull BatGuild guild, @NonNull RoleCreateEvent event) {
|
public void onRoleCreate(@NonNull BatGuild guild, @NonNull RoleCreateEvent event) {
|
||||||
Role role = event.getRole();
|
Role role = event.getRole();
|
||||||
log.info("Role \"{}\" was created in guild \"{}\"", role.getName(), guild.getName());
|
log.info("Role \"{}\" was created in guild \"{}\"", role.getName(), guild.getName());
|
||||||
|
|
||||||
logFeature.sendLog(guild, LogType.ROLE_CREATE, EmbedUtils.successEmbed()
|
logFeature.sendLog(guild, LogType.ROLE_CREATE, EmbedUtils.successEmbed()
|
||||||
.setDescription(new EmbedDescriptionBuilder("Role Created")
|
.setDescription(new EmbedDescriptionBuilder("Role Created")
|
||||||
.appendLine("Role: %s".formatted(role.getAsMention()), true)
|
.appendLine("Role: %s".formatted(role.getAsMention()), true)
|
||||||
.appendLine("Color: `%s`".formatted(
|
.appendLine("Color: `%s`".formatted(
|
||||||
role.getColor() == null ? "Default" : HexColorUtils.colorToHex(role.getColor())
|
role.getColor() == null ? "Default" : HexColorUtils.colorToHex(role.getColor())
|
||||||
), true)
|
), true)
|
||||||
|
.appendLine("Permissions: %s".formatted(RoleUtils.getFormattedPermissions(role)), true)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRoleDelete(@NonNull BatGuild guild, @NonNull RoleDeleteEvent event) {
|
public void onRoleDelete(@NonNull BatGuild guild, @NonNull RoleDeleteEvent event) {
|
||||||
log.info("Role \"{}\" was deleted in guild \"{}\"", event.getRole().getName(), guild.getName());
|
Role role = event.getRole();
|
||||||
|
log.info("Role \"{}\" was deleted in guild \"{}\"", role.getName(), guild.getName());
|
||||||
logFeature.sendLog(guild, LogType.ROLE_DELETE, EmbedUtils.successEmbed()
|
logFeature.sendLog(guild, LogType.ROLE_DELETE, EmbedUtils.successEmbed()
|
||||||
.setDescription(new EmbedDescriptionBuilder("Role Deleted")
|
.setDescription(new EmbedDescriptionBuilder("Role Deleted")
|
||||||
.appendLine("Role: `%s`".formatted(event.getRole().getName()), true)
|
.appendLine("Role: `%s`".formatted(role.getName()), true)
|
||||||
.appendLine("Color: `%s`".formatted(
|
.appendLine("Color: `%s`".formatted(
|
||||||
event.getRole().getColor() == null ? "Default" : HexColorUtils.colorToHex(event.getRole().getColor())
|
role.getColor() == null ? "Default" : HexColorUtils.colorToHex(role.getColor())
|
||||||
), true)
|
), true)
|
||||||
|
.appendLine("Permissions: %s".formatted(RoleUtils.getFormattedPermissions(role)), true)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user