impl boost logging????
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 40s

This commit is contained in:
Lee
2024-07-04 04:28:42 +01:00
parent 040c644ab1
commit 595c61e789
6 changed files with 174 additions and 5 deletions

View File

@ -10,7 +10,8 @@ import lombok.Getter;
public enum LogCategory {
MESSAGE("Message"),
MEMBER("Member"),
CHANNEL("Channel");
CHANNEL("Channel"),
GUILD("Guild");
/**
* The name of the log category

View File

@ -30,6 +30,7 @@ public enum LogType {
MEMBER_BAN(LogCategory.MEMBER, "Member Ban"),
MEMBER_UNBAN(LogCategory.MEMBER, "Member Unban"),
MEMBER_TIMEOUT(LogCategory.MEMBER, "Member Timeout"),
MEMBER_BOOST(LogCategory.MEMBER, "Member Boost"),
/**
* Channel Events
@ -37,7 +38,12 @@ public enum LogType {
CHANNEL_CREATE(LogCategory.CHANNEL, "Channel Create"),
CHANNEL_DELETE(LogCategory.CHANNEL, "Channel Delete"),
VOICE_CHANNEL_JOIN(LogCategory.CHANNEL, "Voice Channel Join"),
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL, "Voice Channel Leave");
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL, "Voice Channel Leave"),
/**
* Guild Events
*/
INVITE_CREATE(LogCategory.GUILD, "Invite Create");
/**
* The category of the log type

View File

@ -0,0 +1,49 @@
package cc.fascinated.bat.features.logging.listeners;
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.logging.LogFeature;
import cc.fascinated.bat.features.logging.LogType;
import cc.fascinated.bat.model.BatGuild;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
@Log4j2
public class GuildListener implements EventListener {
private final LogFeature logFeature;
@Autowired
public GuildListener(@NonNull ApplicationContext context) {
this.logFeature = context.getBean(LogFeature.class);
}
@Override
public void onGuildInviteCreate(@NonNull BatGuild guild, @NonNull Invite invite, @NonNull GuildInviteCreateEvent event) {
log.info("Invite created in guild \"{}\" with code \"{}\"", guild.getGuild().getName(), invite.getCode());
guild.getDiscordGuild().retrieveInvites().queue(invites -> {
Invite newInvite = invites.stream().filter(i -> i.getCode().equals(invite.getCode())).findFirst().orElse(null);
if (newInvite == null) {
return;
}
newInvite.expand().queue(expanded -> logFeature.sendLog(guild, LogType.INVITE_CREATE, EmbedUtils.successEmbed()
.setDescription(new EmbedDescriptionBuilder("Invite Created")
.appendLine("Invite: %s".formatted(expanded.getUrl()), true)
.appendLine("Channel: %s".formatted(expanded.getChannel()), true)
.appendLine("Max Uses: %s".formatted(expanded.getMaxUses() == 0 ? "Infinite" : expanded.getMaxUses()), true)
.appendLine("Creator: %s".formatted(expanded.getInviter() == null ? "Unknown" : expanded.getInviter().getAsMention()), true)
.build())
.build()));
});
}
}

View File

@ -10,6 +10,7 @@ import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
@ -18,6 +19,7 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent;
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent;
@ -30,14 +32,14 @@ import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
/**
* @author Fascinated (fascinated7)
*/
@Component
@Component @Log4j2
public class MemberListener implements EventListener {
private static final Logger log = LoggerFactory.getLogger(MemberListener.class);
private final LogFeature logFeature;
private final GuildService guildService;
@ -226,4 +228,38 @@ public class MemberListener implements EventListener {
.build())
.build());
}
@Override
public void onGuildMemberBoostAdd(@NonNull BatGuild guild, @NonNull BatUser user, OffsetDateTime oldBoostTime,
@NonNull OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) {
if (user.getDiscordUser().isBot()) return;
log.info("User \"{}\" boosted the guild \"{}\" until \"{}\"", user.getName(), guild.getDiscordGuild().getName(), newBoostTime);
oldBoostTime = oldBoostTime == null ? OffsetDateTime.now() : oldBoostTime;
long boostAmount = ChronoUnit.MONTHS.between(oldBoostTime, newBoostTime);
long seconds = newBoostTime.toInstant().getEpochSecond();
logFeature.sendLog(guild, LogType.MEMBER_BOOST, EmbedUtils.successEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Boosted")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Boost Months: %s".formatted(boostAmount), true)
.appendLine("Boost End: <t:%s>".formatted(seconds), true)
.build())
.build());
}
@Override
public void onGuildMemberBoostRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull OffsetDateTime oldBoostTime,
OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) {
if (user.getDiscordUser().isBot()) return;
log.info("User \"{}\" boost expired in the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName());
newBoostTime = newBoostTime == null ? OffsetDateTime.now() : newBoostTime;
long boostAmount = ChronoUnit.MONTHS.between(newBoostTime, oldBoostTime);
logFeature.sendLog(guild, LogType.MEMBER_BOOST, EmbedUtils.errorEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Boost Expired")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Boosts Removed: %s".formatted(boostAmount), true)
.build())
.build());
}
}