Skip to content

Commit

Permalink
Updated to the JDA version of 5.0.0-beta.18 and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Keffisor committed Nov 19, 2023
1 parent e443762 commit 805dadb
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 136 deletions.
9 changes: 7 additions & 2 deletions JDAExpansion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.4.0_352</version>
<version>5.0.0-beta.18</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import java.util.List;
import java.util.stream.Collectors;

import com.Keffisor21.JDAExpansion.JDAExpansion;
import com.Keffisor21.JDAExpansion.CommandHandler.Command;
import com.Keffisor21.JDAExpansion.CommandHandler.CommandSender;
import com.Keffisor21.JDAExpansion.CommandHandler.ConsoleCommand;
import com.Keffisor21.JDAExpansion.CommandHandler.SlashCommand;

import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
Expand Down Expand Up @@ -49,10 +48,11 @@ public void onMessageReceived(MessageReceivedEvent e) {
}

@Override
public void onSlashCommand(SlashCommandEvent e) {
public void onSlashCommandInteraction(SlashCommandInteractionEvent e) {
if(e.getUser().isBot()) return;

if(e.getName().equals(command.replaceFirst("\\"+prefix, "")) || aliases.contains(command.replaceFirst("\\"+prefix, ""))) {
String[] args = e.getCommandPath().split("/");
String[] args = e.getFullCommandName().split("/");
isExecuted(args, new SlashCommand(e, getCommand(e.getName())));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public createReact(Message me, String emote) {
@Override
public void onMessageReactionAdd(MessageReactionAddEvent e) {
if(e.getMember().getUser().isBot()) return;
if(e.getReactionEmote().getName().replace("RE:", ":").equals(emote)) {
if(e.getReaction().getEmoji().getName().replace("RE:", ":").equals(emote)) {
if(message != null && e.getMessageId().equals(message.getId())) {
addReaction(e);
return;
Expand All @@ -30,7 +30,7 @@ public void onMessageReactionAdd(MessageReactionAddEvent e) {
@Override
public void onMessageReactionRemove(MessageReactionRemoveEvent e) {
if(e.getMember().getUser().isBot()) return;
if(e.getReactionEmote().getName().replace("RE:", ":").equals(emote)) {
if(e.getReaction().getEmoji().getName().replace("RE:", ":").equals(emote)) {
if(message != null && e.getMessageId().equals(message.getId())) {
removeReaction(e);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,20 @@
package com.Keffisor21.JDAExpansion.CommandHandler;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

public class Command implements CommandSender {
public class Command extends MessageReceivedEvent implements CommandSender {
private MessageReceivedEvent e;
private String command;
private String prefix;

public Command(MessageReceivedEvent e, String command, String prefix) {
super(e.getJDA(), e.getResponseNumber(), e.getMessage());

this.e = e;
this.command = command;
this.prefix = prefix;
}

public TextChannel getTextChannel() {
return e.getTextChannel();
}

public User getAuthor() {
return e.getAuthor();
}

public MessageChannel getChannel() {
return e.getChannel();
}

public ChannelType getChannelType() {
return e.getChannelType();
}

public JDA getJDA() {
return e.getJDA();
}

public Guild getGuild() {
return e.getGuild();
}

public Member getMember() {
return e.getMember();
}

public Message getMessage() {
return e.getMessage();
}

public String getMessageId() {
return e.getMessageId();
}

public long getMessageIdLong() {
return e.getMessageIdLong();
}

public PrivateChannel getPrivateChannel() {
return e.getPrivateChannel();
}

public long getResponseNumber() {
return e.getResponseNumber();
}

public boolean isFromGuild() {
return e.isFromGuild();
}

public boolean isFromType(ChannelType type) {
return e.isFromType(type);
}

public boolean isWebhookMessage() {
return e.isWebhookMessage();
}

public void sendMessage(String message) {
e.getChannel().sendMessage(message).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;

public class SlashCommand implements CommandSender, CommandInteraction {
public class SlashCommand extends SlashCommandInteractionEvent implements CommandSender {

private SlashCommandEvent e;
private SlashCommandInteractionEvent e;
private String command;

public SlashCommand(SlashCommandEvent e, String command) {
public SlashCommand(SlashCommandInteractionEvent e, String command) {
super(e.getJDA(), e.getResponseNumber(), e.getInteraction());

this.e = e;
this.command = command;
}
Expand Down Expand Up @@ -57,7 +57,7 @@ public boolean isAcknowledged() {
return e.isAcknowledged();
}

public ReplyAction deferReply() {
public ReplyCallbackAction deferReply() {
return e.deferReply();
}

Expand All @@ -77,10 +77,6 @@ public String getSubcommandGroup() {
return e.getSubcommandGroup();
}

public MessageChannel getChannel() {
return e.getChannel();
}

public long getCommandIdLong() {
return e.getCommandIdLong();
}
Expand All @@ -104,5 +100,5 @@ public void replyMessageEmbeds(MessageEmbed embed) {
public String getCommand() {
return command;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
import com.Keffisor21.JDAExpansion.API.createCommand;
import com.Keffisor21.JDAExpansion.CommandHandler.CommandSender;
import com.Keffisor21.JDAExpansion.CommandHandler.ConsoleCommand;
import com.Keffisor21.JDAExpansion.CommandHandler.SlashCommand;
import com.Keffisor21.JDAExpansion.ConsoleHandler.ConsoleColor;
import com.Keffisor21.JDAExpansion.EventController.EventHandler;
import com.Keffisor21.JDAExpansion.Plugins.Plugin;

import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;

public class PluginsCommand extends createCommand {

public PluginsCommand() {
super(new CommandData("plugins", "See the list of plugins installed."), "!", "plugins", "pl");
public PluginsCommand() {
super(Commands.slash("plugins", "See the list of plugins installed."), "!", "plugins", "pl");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;

public class ReloadCommand extends createCommand {

public ReloadCommand() {
super(new CommandData("reload", "Reload the plugins of the bot. Requires permission."), "!", "reload", "rl");
super(Commands.slash("reload", "Reload the plugins of the bot. Requires permission."), "!", "reload", "rl");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;

public class StopCommand extends createCommand {

public StopCommand() {
super(new CommandData("stop", "Stop the bot. Requires permission."), "!", "stop", "shutdown");
super(Commands.slash("stop", "Stop the bot. Requires permission."), "!", "stop", "shutdown");
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions JDAExpansion/src/com/Keffisor21/JDAExpansion/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
import net.dv8tion.jda.api.utils.ChunkingFilter;
Expand Down Expand Up @@ -40,5 +42,6 @@ public static void main(String[] args) throws LoginException {
e.printStackTrace();
throw (Error)e;
}

}
}
37 changes: 0 additions & 37 deletions JDAExpansion/src/com/Keffisor21/JDAExpansion/NMS/JDANMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,6 @@
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ApplicationInfo;
import net.dv8tion.jda.api.entities.Category;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Icon;
import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.entities.StoreChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.Webhook;
import net.dv8tion.jda.api.hooks.IEventManager;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.managers.DirectAudioController;
import net.dv8tion.jda.api.managers.Presence;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.CommandCreateAction;
import net.dv8tion.jda.api.requests.restaction.CommandEditAction;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import net.dv8tion.jda.api.requests.restaction.GuildAction;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import net.dv8tion.jda.api.utils.cache.CacheView;
import net.dv8tion.jda.api.utils.cache.SnowflakeCacheView;
import okhttp3.OkHttpClient;

public class JDANMS {
private JDAType type;
Expand Down

0 comments on commit 805dadb

Please sign in to comment.