Add username edit logging
This commit is contained in:
parent
299622ed30
commit
ae092d3440
|
@ -1,22 +1,37 @@
|
||||||
package moe.oko.Kiafumi.listener;
|
package moe.oko.Kiafumi.listener;
|
||||||
|
|
||||||
import moe.oko.Kiafumi.Kiafumi;
|
import moe.oko.Kiafumi.Kiafumi;
|
||||||
|
import moe.oko.Kiafumi.KiafumiConfig;
|
||||||
import moe.oko.Kiafumi.util.EmbedUI;
|
import moe.oko.Kiafumi.util.EmbedUI;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
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.user.update.UserUpdateNameEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
import static moe.oko.Kiafumi.Kiafumi.error;
|
|
||||||
import static moe.oko.Kiafumi.Kiafumi.debug;
|
import static moe.oko.Kiafumi.Kiafumi.debug;
|
||||||
import static moe.oko.Kiafumi.Kiafumi.info;
|
import static moe.oko.Kiafumi.Kiafumi.info;
|
||||||
|
import static moe.oko.Kiafumi.Kiafumi.error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Skynet Listener
|
||||||
|
* Handles all event logging (Join/Leaves, Username Change, etc).
|
||||||
|
* @author oko
|
||||||
|
*/
|
||||||
public class SkynetListener extends ListenerAdapter {
|
public class SkynetListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
KiafumiConfig config;
|
||||||
|
DateTimeFormatter dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join/Leave logging
|
||||||
|
* Requires the server to configure welcomeEnabled & welcomeChannel (optionally joinRole).
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
|
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
|
||||||
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
||||||
|
@ -37,14 +52,15 @@ public class SkynetListener extends ListenerAdapter {
|
||||||
error("Failed to send join message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
error("Failed to send join message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
|
||||||
// Prepare embed.
|
// Prepare embed.
|
||||||
var embedBuilder = new EmbedBuilder()
|
var eb = new EmbedBuilder()
|
||||||
.setColor(EmbedUI.SUCCESS)
|
.setColor(EmbedUI.SUCCESS)
|
||||||
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
||||||
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Joined").setTimestamp(OffsetDateTime.now())
|
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl())
|
||||||
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated().format(dTF));
|
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated().format(dTF))
|
||||||
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
.setFooter("User Joined")
|
||||||
|
.setTimestamp(OffsetDateTime.now());
|
||||||
|
textChannel.sendMessageEmbeds(eb.build()).queue();
|
||||||
debug("Guild join message successfully sent.");
|
debug("Guild join message successfully sent.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,14 +79,36 @@ public class SkynetListener extends ListenerAdapter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Prepare embed.
|
// Prepare embed.
|
||||||
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
var eb = new EmbedBuilder()
|
||||||
var embedBuilder = new EmbedBuilder()
|
|
||||||
.setColor(EmbedUI.FAILURE)
|
.setColor(EmbedUI.FAILURE)
|
||||||
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
||||||
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Left").setTimestamp(OffsetDateTime.now())
|
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl())
|
||||||
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF));
|
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF))
|
||||||
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
.setFooter("User Left")
|
||||||
|
.setTimestamp(OffsetDateTime.now());
|
||||||
|
textChannel.sendMessageEmbeds(eb.build()).queue();
|
||||||
debug("Guild leave message successfully sent.");
|
debug("Guild leave message successfully sent.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name change logging
|
||||||
|
* Sent to the central logChannel.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onUserUpdateName(@NotNull UserUpdateNameEvent event) {
|
||||||
|
var user = event.getUser();
|
||||||
|
String name = event.getNewName(), oldName = event.getOldName();
|
||||||
|
info("User [" + name + ':' + user.getId() + "] changed name from \"" + oldName + "\".");
|
||||||
|
var logChannel = Kiafumi.JDA.getTextChannelById(config.getLogChannel());
|
||||||
|
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.setColor(EmbedUI.INFO)
|
||||||
|
.setAuthor(user.getName() + '#' + user.getDiscriminator() + " (" + user.getId() + ')', null, user.getAvatarUrl())
|
||||||
|
.setDescription('`' + oldName + "` → `" + name + '`')
|
||||||
|
.setFooter("Username Edited")
|
||||||
|
.setTimestamp(OffsetDateTime.now());
|
||||||
|
logChannel.sendMessageEmbeds(eb.build()).queue();
|
||||||
|
debug("Username edit message successfully sent.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue