mirror of
https://github.com/aikar/commands.git
synced 2026-06-28 01:18:26 +00:00
Improvements for JDA implementation. (#91)
* Added owneronly condition for JDA. * Fixed command registration for JDA. * Removed extraneous event handling. * Initialize bot owner on ReadyEvent.
This commit is contained in:
committed by
Daniel Ennis
parent
9aaf990ddb
commit
23e8858c67
@@ -5,7 +5,6 @@ import com.google.common.collect.Maps;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -58,8 +57,7 @@ public class JDACommandManager extends CommandManager<
|
||||
});
|
||||
}
|
||||
|
||||
private long getBotOwnerId() {
|
||||
// Lazy initialization is required because a forced RestAction on startup is bad
|
||||
void initializeBotOwner() {
|
||||
if (botOwner == 0L) {
|
||||
if (jda.getAccountType() == AccountType.BOT) {
|
||||
botOwner = jda.asBot().getApplicationInfo().complete().getOwner().getIdLong();
|
||||
@@ -67,6 +65,11 @@ public class JDACommandManager extends CommandManager<
|
||||
botOwner = jda.getSelfUser().getIdLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getBotOwnerId() {
|
||||
// Just in case initialization on ReadyEvent fails.
|
||||
initializeBotOwner();
|
||||
return botOwner;
|
||||
}
|
||||
|
||||
@@ -126,6 +129,7 @@ public class JDACommandManager extends CommandManager<
|
||||
|
||||
@Override
|
||||
public void registerCommand(BaseCommand command) {
|
||||
command.onRegister(this);
|
||||
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
|
||||
String commandName = entry.getKey().toLowerCase();
|
||||
JDARootCommand cmd = (JDARootCommand) entry.getValue();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.events.ReadyEvent;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
|
||||
public class JDAListener extends ListenerAdapter {
|
||||
@@ -14,15 +13,6 @@ public class JDAListener extends ListenerAdapter {
|
||||
|
||||
this.manager = manager;
|
||||
}
|
||||
@Override
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
|
||||
super.onGuildMessageReceived(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
|
||||
super.onPrivateMessageReceived(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
@@ -30,4 +20,9 @@ public class JDAListener extends ListenerAdapter {
|
||||
this.manager.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
manager.initializeBotOwner();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user