Skip to content

Commit

Permalink
🐛 Fixed member timeout event being fired only for "single" member update
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed May 17, 2024
1 parent a3a077e commit 6eaaac5
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
import info.itsthesky.disky.api.skript.SimpleGetterExpression;
import info.itsthesky.disky.api.skript.reflects.ReflectEventExpressionFactory;
import info.itsthesky.disky.core.SkriptUtils;
import net.dv8tion.jda.api.audit.ActionType;
import net.dv8tion.jda.api.audit.AuditLogChange;
import net.dv8tion.jda.api.audit.AuditLogKey;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent;
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static info.itsthesky.disky.core.SkriptUtils.convertDateTime;

Expand All @@ -21,10 +30,7 @@ public class MemberTimeoutEvent extends DiSkyEvent<GuildMemberUpdateTimeOutEvent
register("Member Timeout Event", MemberTimeoutEvent.class, BukkitMemberTimeoutEvent.class,
"[discord] member time[ ]out[ed]");


SkriptUtils.registerBotValue(BukkitMemberTimeoutEvent.class);
SkriptUtils.registerAuthorValue(BukkitMemberTimeoutEvent.class,
e -> e.getJDAEvent().getGuild());

SkriptUtils.registerValue(BukkitMemberTimeoutEvent.class, Guild.class,
event -> event.getJDAEvent().getGuild());
Expand All @@ -43,6 +49,19 @@ public class MemberTimeoutEvent extends DiSkyEvent<GuildMemberUpdateTimeOutEvent
ReflectEventExpressionFactory.registerEventExpression(
"(future|new) date", BukkitMemberTimeoutEvent.class,
Date.class, event -> convertDateTime(event.getJDAEvent().getNewTimeOutEnd()));

SkriptUtils.registerRestValue("author", BukkitMemberTimeoutEvent.class,
event -> event.getLogEvent().getGuild().retrieveMemberById(event.getLogEvent().getEntry().getUserIdLong()));
}

@Override
public @Nullable ActionType getLogType() {
return ActionType.MEMBER_UPDATE;
}

@Override
protected Predicate<GuildAuditLogEntryCreateEvent> logChecker() {
return event -> event.getEntry().getChangeByKey(AuditLogKey.MEMBER_TIME_OUT) != null;
}

public static class BukkitMemberTimeoutEvent extends SimpleDiSkyEvent<GuildMemberUpdateTimeOutEvent> {
Expand Down

0 comments on commit 6eaaac5

Please sign in to comment.