Increase logging within commands & listeners
This commit is contained in:
parent
35512486ad
commit
ba34562917
|
@ -145,6 +145,7 @@ public class Kiafumi {
|
|||
.setFooter(footer)
|
||||
.setTimestamp(ZonedDateTime.now());
|
||||
JDA.getTextChannelById(config.getLogChannel()).sendMessageEmbeds(build.build()).queue();
|
||||
info("Shutting down Kiafumi.");
|
||||
if(database.saveServerInformation()) {
|
||||
info("Successfully saved server information. Shutting down peacefully.");
|
||||
} else {
|
||||
|
@ -191,9 +192,12 @@ public class Kiafumi {
|
|||
private void registerAllCommands() {
|
||||
// Registers slash commands.
|
||||
info("Registering commands for guilds.");
|
||||
int i = 0;
|
||||
for(Guild guild : JDA.getGuilds()) {
|
||||
registerForGuild(guild);
|
||||
i++;
|
||||
}
|
||||
info("Registered commands for " + i + " guilds.");
|
||||
|
||||
// Registers the event listeners for those commands.
|
||||
for(CommandClass cmd : activeCommands) {
|
||||
|
@ -208,6 +212,7 @@ public class Kiafumi {
|
|||
public void registerForGuild(Guild guild) {
|
||||
debug("Registering commands for guild [" + guild.getName() + ":" + guild.getId() + "]");
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for(CommandClass cmd : activeCommands) {
|
||||
for(CommandInfo ci : cmd.getSlashCommandInfo()) {
|
||||
var cca = guild.upsertCommand(ci.getName(), ci.getDescription());
|
||||
|
@ -238,7 +243,7 @@ public class Kiafumi {
|
|||
}
|
||||
}
|
||||
}
|
||||
info("Registered " + i + " commands for guild [" + guild.getId() + "]");
|
||||
debug("Registered " + i + " commands for guild [" + guild.getId() + "]");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -258,7 +263,7 @@ public class Kiafumi {
|
|||
* @param msg - Any message to append with this.
|
||||
*/
|
||||
public static void slashLog(SlashCommandInteractionEvent event, @Nullable String msg) {
|
||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] ran command: \"" + event.getName() + "\"." + (msg == null ? "" : msg));
|
||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] ran command: \"" + event.getName() + "\" " + (msg == null ? "" : msg));
|
||||
}
|
||||
|
||||
public static void slashLog(SlashCommandInteractionEvent event) {
|
||||
|
|
|
@ -28,12 +28,12 @@ public class AvatarCommand extends CommandClass {
|
|||
@Override
|
||||
public void newCommand(String name, SlashCommandInteractionEvent e) {
|
||||
if ("avatar".equals(name)) {
|
||||
slashLog(e);
|
||||
e.deferReply().queue();
|
||||
|
||||
final var user = e.getOptions().size() == 0
|
||||
? e.getUser()
|
||||
: e.getOption("user").getAsUser();
|
||||
slashLog(e, "for user [" + user.getName() + ":" + user.getId() + "]." );
|
||||
|
||||
var eb = new EmbedBuilder()
|
||||
.setColor(EmbedUI.INFO)
|
||||
|
|
|
@ -190,7 +190,7 @@ public class MusicCommand extends CommandClass {
|
|||
case "play":
|
||||
e.deferReply().queue();
|
||||
var input = e.getOption("url").getAsString();
|
||||
slashLog(e, " With search \"" + input + "\".");
|
||||
slashLog(e, "with search \"" + input + "\".");
|
||||
if(input.contains("https://")) {
|
||||
loadTrack(input, e.getMember(), e.getHook());
|
||||
} else {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class DuckCommand extends CommandClass {
|
|||
if ("search".equals(name)) {
|
||||
e.deferReply().queue();
|
||||
String option = e.getOption("query").getAsString();
|
||||
slashLog(e, " With search \"" + option + "\".");
|
||||
slashLog(e, "with search \"" + option + "\".");
|
||||
WebSearch ws = WebSearch.instanceOf();
|
||||
SearchResult sr;
|
||||
try {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class InfoCommand extends CommandClass {
|
|||
? e.getMember()
|
||||
: e.getOption("user").getAsMember();
|
||||
final var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
||||
slashLog(e, " For user [" + member.getUser().getName() + ":" + member.getId() + "].");
|
||||
slashLog(e, "for user [" + member.getUser().getName() + ":" + member.getId() + "].");
|
||||
// Build embed
|
||||
EmbedBuilder eb1 = new EmbedBuilder()
|
||||
.setColor(EmbedUI.INFO)
|
||||
|
@ -56,7 +56,7 @@ public class InfoCommand extends CommandClass {
|
|||
// Setup variables
|
||||
final var guild = e.getGuild();
|
||||
final var dTF2 = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
||||
slashLog(e, " For guild [" + guild.getId() + ":" + guild.getName() + "]");
|
||||
slashLog(e, "for guild [" + guild.getId() + ":" + guild.getName() + "].");
|
||||
// Build Embed
|
||||
EmbedBuilder eb2 = new EmbedBuilder()
|
||||
.setColor(EmbedUI.INFO)
|
||||
|
|
|
@ -63,7 +63,7 @@ public class SettingCommand extends CommandClass {
|
|||
case "view" -> {
|
||||
e.deferReply().queue();
|
||||
String opt = e.getOption("name").getAsString();
|
||||
slashLog(e, "With subcommand \"" + name + "\". Setting \"" + opt + "\".");
|
||||
slashLog(e, "with subcommand \"" + e.getSubcommandName().toLowerCase() + "\" for setting \"" + opt + "\".");
|
||||
EmbedBuilder eb1 = new EmbedBuilder()
|
||||
.setColor(EmbedUI.INFO)
|
||||
.setTitle(opt)
|
||||
|
@ -76,7 +76,7 @@ public class SettingCommand extends CommandClass {
|
|||
e.deferReply().queue();
|
||||
String opt1 = e.getOption("name").getAsString();
|
||||
String opt2 = e.getOption("value").getAsString();
|
||||
slashLog(e, "With subcommand \"" + name + "\". Setting \"" + opt1 + "\" to \"" + opt2 + "\".");
|
||||
slashLog(e, "with subcommand \"" + e.getSubcommandName().toLowerCase() + "\" for setting \"" + opt1 + "\" to \"" + opt2 + "\".");
|
||||
String response = server.setOptionByString(opt1, opt2);
|
||||
slashResponse(e, response);
|
||||
EmbedBuilder eb2 = new EmbedBuilder()
|
||||
|
@ -90,7 +90,7 @@ public class SettingCommand extends CommandClass {
|
|||
case "clear" -> {
|
||||
e.deferReply().queue();
|
||||
String opt3 = e.getOption("name").getAsString();
|
||||
slashLog(e, "With subcommand \"" + name + "\". Setting \"" + opt3 + "\".");
|
||||
slashLog(e, "with subcommand \"" + e.getSubcommandName().toLowerCase() + "\" for setting \"" + opt3 + "\".");
|
||||
String response1 = server.resetOptionByString(opt3);
|
||||
slashResponse(e, response1);
|
||||
EmbedBuilder eb3 = new EmbedBuilder()
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.Timer;
|
|||
import java.util.TimerTask;
|
||||
|
||||
import static moe.oko.Kiafumi.Kiafumi.info;
|
||||
import static moe.oko.Kiafumi.Kiafumi.debug;
|
||||
import static moe.oko.Kiafumi.Kiafumi.error;
|
||||
|
||||
/**
|
||||
* Main Listener
|
||||
|
@ -59,6 +61,7 @@ public class MainListener extends ListenerAdapter {
|
|||
*/
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
if(event.getMessage().getMentionedUsers().contains(Kiafumi.JDA.getSelfUser())) {
|
||||
info("Sent about message in " + event.getGuild().getId());
|
||||
var eb = new EmbedBuilder()
|
||||
.setColor(EmbedUI.INFO)
|
||||
.setTitle("Hi, i'm Kiafumi!")
|
||||
|
@ -111,13 +114,15 @@ public class MainListener extends ListenerAdapter {
|
|||
try {
|
||||
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(server.getJoinRole())).queue();
|
||||
} catch(Exception ex) {
|
||||
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", as the role does not exist.**").queue();
|
||||
error("Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", as the role does not exist.");
|
||||
}
|
||||
}
|
||||
if(server.isWelcomeEnabled()) {
|
||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] joined guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
||||
// Fetch the welcome channel from settings.
|
||||
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||
if(textChannel == null) {
|
||||
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send welcome message, as the welcome channel does not exist.**").queue();
|
||||
error("Failed to send welcome message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
||||
return;
|
||||
}
|
||||
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
||||
|
@ -128,16 +133,19 @@ public class MainListener extends ListenerAdapter {
|
|||
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Joined").setTimestamp(OffsetDateTime.now())
|
||||
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated().format(dTF));
|
||||
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
||||
debug("Guild join message successfully sent.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
|
||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] left guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
||||
// Fetch the welcome channel from settings.
|
||||
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
||||
if(server.isWelcomeEnabled()) {
|
||||
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||
if(textChannel == null) {
|
||||
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send leave message, as the welcome channel does not exist.**").queue();
|
||||
error("Failed to send leave message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
||||
return;
|
||||
}
|
||||
// Prepare embed.
|
||||
|
@ -148,6 +156,7 @@ public class MainListener extends ListenerAdapter {
|
|||
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Left").setTimestamp(OffsetDateTime.now())
|
||||
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF));
|
||||
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
||||
debug("Guild leave message successfully sent.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">%d{HH:mm} %highlight{%-5level} %cyan{%logger{7}} - %m%n</Property>
|
||||
<Property name="LOG_PATTERN">%d{HH:mm} %highlight{%-5level} %cyan{%logger{11}} - %m%n</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
|
|
Loading…
Reference in a new issue