Fixed some command handling in main class

This commit is contained in:
unknown 2022-03-26 23:04:24 -07:00
parent 7c5840c8c1
commit 62e47ac1c4
2 changed files with 32 additions and 8 deletions

View file

@ -1,5 +1,6 @@
package moe.oko.Kiafumi; package moe.oko.Kiafumi;
import moe.oko.Kiafumi.command.CommandClass;
import moe.oko.Kiafumi.command.PingCommand; import moe.oko.Kiafumi.command.PingCommand;
import moe.oko.Kiafumi.listener.MainListener; import moe.oko.Kiafumi.listener.MainListener;
import moe.oko.Kiafumi.model.KiafumiDB; import moe.oko.Kiafumi.model.KiafumiDB;
@ -25,6 +26,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.List;
/** /**
* Kiafumi Main Class * Kiafumi Main Class
@ -43,6 +46,8 @@ public class Kiafumi {
public static JDA JDA; public static JDA JDA;
public List<CommandClass> activeCommands;
public KiafumiConfig config; public KiafumiConfig config;
public KiafumiDB database; public KiafumiDB database;
@ -67,6 +72,10 @@ public class Kiafumi {
* Ran on program start. Anything in here can determine whether the program will start. * Ran on program start. Anything in here can determine whether the program will start.
*/ */
public void start() { public void start() {
activeCommands = new ArrayList<>();
activeCommands.add(new PingCommand());
instance = this; instance = this;
logger.info("Starting Kiafumi."); logger.info("Starting Kiafumi.");
@ -148,20 +157,34 @@ public class Kiafumi {
ex.printStackTrace(); ex.printStackTrace();
return; return;
} }
PingCommand pc = new PingCommand();
JDA.addEventListener(pc); registerAllCommands();
for(Guild guild : JDA.getGuilds()) { info("Loaded " + activeCommands.size() + " commands.");
for (String name : pc.getSlashCommandInfo().keySet()) {
JDA.upsertCommand(name, pc.getSlashCommandInfo().get(name)).complete();
info("Upsert command " + name + " on guild: " + guild.getId());
}
}
EmbedBuilder eb = new EmbedBuilder().setTitle("Kiafumi Online") EmbedBuilder eb = new EmbedBuilder().setTitle("Kiafumi Online")
.setFooter("Created by Oko, Laika, and Tiddy").setColor(new Color(0x6271c1)); .setFooter("Created by Oko, Laika, and Tiddy").setColor(new Color(0x6271c1));
JDA.getTextChannelById(config.getLogChannel()).sendMessageEmbeds(eb.build()).queue(); JDA.getTextChannelById(config.getLogChannel()).sendMessageEmbeds(eb.build()).queue();
} }
private void registerAllCommands() {
for(Guild guild : JDA.getGuilds()) {
registerForGuild(guild);
}
for(CommandClass cmd : activeCommands) {
JDA.addEventListener(cmd);
}
}
public void registerForGuild(Guild guild) {
info("Registering commands for " + guild.getId());
for(CommandClass cmd : activeCommands) {
for(String name : cmd.getSlashCommandInfo().keySet()) {
guild.upsertCommand(name, cmd.getSlashCommandInfo().get(name)).queue();
}
}
}
/* /*
Static logger info reference. Static logger info reference.
*/ */

View file

@ -21,6 +21,7 @@ public class MainListener extends ListenerAdapter {
//Automatically create our default information for the server if we don't have it already. //Automatically create our default information for the server if we don't have it already.
info("Joined a new guild, NAME: " + event.getGuild().getName() + " ID: " + event.getGuild().getId()); info("Joined a new guild, NAME: " + event.getGuild().getName() + " ID: " + event.getGuild().getId());
Kiafumi.instance.getServerManager().createNewDefaultServer(event.getGuild()); Kiafumi.instance.getServerManager().createNewDefaultServer(event.getGuild());
Kiafumi.instance.registerForGuild(event.getGuild());
} }
} }