forked from Fascinated/Bat
impl member ban and unban logging
This commit is contained in:
parent
38bde93d16
commit
8b7340715c
@ -10,6 +10,8 @@ import lombok.NonNull;
|
|||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
||||||
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildUnbanEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
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.GuildMemberRemoveEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
||||||
@ -170,6 +172,24 @@ public interface EventListener {
|
|||||||
default void onChannelDelete(@NonNull BatGuild guild, @NonNull ChannelDeleteEvent event) {
|
default void onChannelDelete(@NonNull BatGuild guild, @NonNull ChannelDeleteEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a user is banned from a guild
|
||||||
|
*
|
||||||
|
* @param guild the guild that the user was banned from
|
||||||
|
* @param user the user that was banned
|
||||||
|
*/
|
||||||
|
default void onGuildMemberBan(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildBanEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a user is unbanned from a guild
|
||||||
|
*
|
||||||
|
* @param guild the guild that the user was unbanned from
|
||||||
|
* @param user the user that was unbanned
|
||||||
|
*/
|
||||||
|
default void onGuildMemberUnban(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildUnbanEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when Spring is shutting down
|
* Called when Spring is shutting down
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +24,8 @@ public enum LogType {
|
|||||||
MEMBER_LEAVE(LogCategory.MEMBER, "Member Leave"),
|
MEMBER_LEAVE(LogCategory.MEMBER, "Member Leave"),
|
||||||
MEMBER_NICKNAME_UPDATE(LogCategory.MEMBER, "Member Nickname Update"),
|
MEMBER_NICKNAME_UPDATE(LogCategory.MEMBER, "Member Nickname Update"),
|
||||||
MEMBER_ROLE_UPDATE(LogCategory.MEMBER, "Member Role Update"),
|
MEMBER_ROLE_UPDATE(LogCategory.MEMBER, "Member Role Update"),
|
||||||
|
MEMBER_BAN(LogCategory.MEMBER, "Member Ban"),
|
||||||
|
MEMBER_UNBAN(LogCategory.MEMBER, "Member Unban"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Channel Events
|
* Channel Events
|
||||||
|
@ -9,6 +9,8 @@ import cc.fascinated.bat.model.BatGuild;
|
|||||||
import cc.fascinated.bat.model.BatUser;
|
import cc.fascinated.bat.model.BatUser;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildUnbanEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
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.GuildMemberRemoveEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
||||||
@ -106,4 +108,30 @@ public class MemberListener implements EventListener {
|
|||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMemberBan(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildBanEvent event) {
|
||||||
|
if (user.getDiscordUser().isBot()) return;
|
||||||
|
|
||||||
|
logFeature.sendLog(guild, LogType.MEMBER_BAN, EmbedUtils.errorEmbed()
|
||||||
|
.setDescription(new EmbedDescriptionBuilder("Member Banned")
|
||||||
|
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
|
||||||
|
.appendLine("Username: %s".formatted(user.getDiscordUser().getName()), true)
|
||||||
|
.appendLine("Snowflake: %s".formatted(user.getId()), true)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMemberUnban(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildUnbanEvent event) {
|
||||||
|
if (user.getDiscordUser().isBot()) return;
|
||||||
|
|
||||||
|
logFeature.sendLog(guild, LogType.MEMBER_UNBAN, EmbedUtils.successEmbed()
|
||||||
|
.setDescription(new EmbedDescriptionBuilder("Member Unbanned")
|
||||||
|
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
|
||||||
|
.appendLine("Username: %s".formatted(user.getDiscordUser().getName()), true)
|
||||||
|
.appendLine("Snowflake: %s".formatted(user.getId()), true)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import lombok.NonNull;
|
|||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
||||||
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildUnbanEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
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.GuildMemberRemoveEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
||||||
@ -222,4 +224,30 @@ public class EventService extends ListenerAdapter {
|
|||||||
listener.onChannelDelete(guild, event);
|
listener.onChannelDelete(guild, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildBan(@NotNull GuildBanEvent event) {
|
||||||
|
if (event.getUser().isBot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BatGuild guild = guildService.getGuild(event.getGuild().getId());
|
||||||
|
BatUser user = userService.getUser(event.getUser().getId());
|
||||||
|
|
||||||
|
for (EventListener listener : LISTENERS) {
|
||||||
|
listener.onGuildMemberBan(guild, user, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildUnban(@NotNull GuildUnbanEvent event) {
|
||||||
|
if (event.getUser().isBot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BatGuild guild = guildService.getGuild(event.getGuild().getId());
|
||||||
|
BatUser user = userService.getUser(event.getUser().getId());
|
||||||
|
|
||||||
|
for (EventListener listener : LISTENERS) {
|
||||||
|
listener.onGuildMemberUnban(guild, user, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user