Fixed some command handling in main class
This commit is contained in:
parent
7c5840c8c1
commit
62e47ac1c4
|
@ -1,5 +1,6 @@
|
|||
package moe.oko.Kiafumi;
|
||||
|
||||
import moe.oko.Kiafumi.command.CommandClass;
|
||||
import moe.oko.Kiafumi.command.PingCommand;
|
||||
import moe.oko.Kiafumi.listener.MainListener;
|
||||
import moe.oko.Kiafumi.model.KiafumiDB;
|
||||
|
@ -25,6 +26,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Kiafumi Main Class
|
||||
|
@ -43,6 +46,8 @@ public class Kiafumi {
|
|||
|
||||
public static JDA JDA;
|
||||
|
||||
public List<CommandClass> activeCommands;
|
||||
|
||||
public KiafumiConfig config;
|
||||
|
||||
public KiafumiDB database;
|
||||
|
@ -67,6 +72,10 @@ public class Kiafumi {
|
|||
* Ran on program start. Anything in here can determine whether the program will start.
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
activeCommands = new ArrayList<>();
|
||||
activeCommands.add(new PingCommand());
|
||||
|
||||
instance = this;
|
||||
|
||||
logger.info("Starting Kiafumi.");
|
||||
|
@ -148,20 +157,34 @@ public class Kiafumi {
|
|||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
PingCommand pc = new PingCommand();
|
||||
JDA.addEventListener(pc);
|
||||
for(Guild guild : JDA.getGuilds()) {
|
||||
for (String name : pc.getSlashCommandInfo().keySet()) {
|
||||
JDA.upsertCommand(name, pc.getSlashCommandInfo().get(name)).complete();
|
||||
info("Upsert command " + name + " on guild: " + guild.getId());
|
||||
}
|
||||
}
|
||||
|
||||
registerAllCommands();
|
||||
info("Loaded " + activeCommands.size() + " commands.");
|
||||
|
||||
EmbedBuilder eb = new EmbedBuilder().setTitle("Kiafumi Online")
|
||||
.setFooter("Created by Oko, Laika, and Tiddy").setColor(new Color(0x6271c1));
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,7 @@ public class MainListener extends ListenerAdapter {
|
|||
//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());
|
||||
Kiafumi.instance.getServerManager().createNewDefaultServer(event.getGuild());
|
||||
Kiafumi.instance.registerForGuild(event.getGuild());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue