Skip to content

Commit

Permalink
Fix CCE thrown while parsing role audit log events
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Mar 2, 2023
1 parent f785fd6 commit d2b2f8c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ record SlashCommandRegistration(Object fieldValue, RegisterSlashCommand annotati
.disableCache(CacheFlag.ONLINE_STATUS)
.disableCache(CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY)
.disableCache(CacheFlag.SCHEDULED_EVENTS)
.setEnabledIntents(INTENTS);
EventListeners.register(builder::addEventListeners);
jda = builder.build().awaitReady();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Logger getLogger() {

private static final Set<GatewayIntent> INTENTS = Set.of(
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_BANS,
GatewayIntent.GUILD_MODERATION,
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.GUILD_MEMBERS,
Expand Down Expand Up @@ -137,6 +137,7 @@ public void start() {
.disableCache(CacheFlag.ONLINE_STATUS)
.disableCache(CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY)
.disableCache(CacheFlag.SCHEDULED_EVENTS)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -83,14 +84,14 @@ private static List<Role> parseRoles(final AuditLogEntry entry, AuditLogKey logK
// https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-exceptions
// The added/removed roles are marked in the new_value property of the audit log change

final List<String> roleIds = requireNonNull(change.getNewValue());
final List<Role> roles = new ArrayList<>(roleIds.size());
final List<Map<String, String>> roleDatas = requireNonNull(change.getNewValue());
final List<Role> roles = new ArrayList<>(roleDatas.size());
final JDA jda = entry.getJDA();

for (String roleId : roleIds) {
final @Nullable Role roleById = jda.getRoleById(roleId);
for (final Map<String, String> roleData : roleDatas) {
final @Nullable Role roleById = jda.getRoleById(roleData.get("id"));
if (roleById == null) {
LOGGER.warn("Could not find role with ID {} while parsing change key {} for log entry {}", roleId, logKey, entry);
LOGGER.warn("Could not find role with ID {} while parsing change key {} for log entry {}", roleData, logKey, entry);
continue;
}
roles.add(roleById);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public void start() {
.disableCache(CacheFlag.ONLINE_STATUS)
.disableCache(CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY)
.disableCache(CacheFlag.SCHEDULED_EVENTS)
.enableCache(CacheFlag.FORUM_TAGS)
.setEnabledIntents(INTENTS);
if (oldConfig.hasActivity()) builder.setActivity(Activity.of(oldConfig.getActivityType(), oldConfig.getActivityName()));
Expand Down

0 comments on commit d2b2f8c

Please sign in to comment.